- Notifications
You must be signed in to change notification settings - Fork7
Suppression Filter for Checkstyle that is based on patch file
License
checkstyle/patch-filters
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
special project to host Patch Suppressions
or atrepo.
Filter SuppressionPatchFilter(Checker level) only accepts audit events for Check violations whose line numberbelong to added/changed lines in patch file and will suppress all Checks’ violation messageswhich are not from added/changed lines. If there is no configured patch fileor the optional is set to true and patch file was not found the Filter suppresses all audit events.
name | description | type | default value |
---|---|---|---|
file | Specify the location of the patch file. | String | null |
optional | Control what to do when the file is not existing. Ifoptional is set tofalse the file must exist, or else it ends with error. On the other hand if optional istrue and file is not found, the filter suppresses all audit events. | boolean | false |
strategy | Control suppression scope that you need. Ifstartegy is set tonewline , it only accepts audit events for Check violations whose line number belong to added lines in patch file.patchedline will accept added/changed lines. | String | newline |
neverSuppressedChecks | String has user defined Checks to never suppress if files are touched, split by comma. This property is useful for Checks that place violation on whole file or on not all (first/last) occurrence of cause/violated code. | String | null |
For example, the following configuration fragment directs the Checker to use a SuppressionPatchFilter with patch file config/file.patch:
<modulename="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter"> <propertyname="file"value="config/file.patch" /> <propertyname="strategy"value="newline" /></module>
the following configuration fragment direts the Checker to use a SuppressionPatchFilterwith patch file config/file.patch, whose strategy ispatchedline
,and never suppresschecksTranslation
andUniqueProperties
:
<modulename="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter"> <propertyname="file"value="config/file.patch" /> <propertyname="strategy"value="patchedline" /> <propertyname="neverSuppressedChecks"value="Translation,UniqueProperties" /></module>
Filter SuppressionJavaPatchFilter(TreeWalker level) has three different strategies that control suppressionscope. if propertystrategy
is set tonewline
, then it only accepts TreeWalker audit events for TreeWalkerCheck violations whose line number belong to added lines in patch file and will suppress all TreeWalker Checks’violation messages which are not from added lines. if propertystrategy
is set topatchedline
, it will acceptall violations whose line number belong to added/changed lines in patch file. if propertystrategy
is set tocontext
,for checks listed insupportContextStrategyChecks
, it will not only accept violations whose line number belong to added/changed/deleted lines,but also consider a wider context that new code introduces violations outside of added/changed lines, but its child nodes in added/changed lines,for checks not listed insupportContextStrategyChecks
, it will accept violations whose line number belong to added/changed/deleted lines in patch file.If there is no configured patch file or the optional is set to true and patch file was not found the Filter suppresses all audit events.
Note that it's ok to use all four properties (supportContextStrategyChecks
,checkNameForContextStrategyByTokenOrParentSet
,checkNameForContextStrategyByTokenOrAncestorSet
,neverSuppressedChecks
), and the context scope of the three is also growing, for TreeWalker checks only in one of the property, its context scope is the same as that property,if in two or all properties, then the The context scope is the maximum scope.
Attention:supportContextStrategyChecks
andcheckNameForContextStrategyByTokenOrParentSet
,checkNameForContextStrategyByTokenOrAncestorSet
only have effect when thestrategy
property is set tocontext
,neverSuppressedChecks
is no such requirement.
name | description | type | default value |
---|---|---|---|
file | Specify the location of the patch file. | String | null |
optional | Control what to do when the file is not existing. Ifoptional is set tofalse the file must exist, or else it ends with error. On the other hand if optional istrue and file is not found, the filter suppresses all audit events. | boolean | false |
strategy | Control suppression scope that you need. Ifstartegy is set tonewline , it only accepts TreeWalker audit events for TreeWalker Check violations whose line number belong to added lines in patch file.patchedline will accept added/changed lines. ifstrategy is set tocontext , for checks listed insupportContextStrategyChecks , it will accept violations whose line number belong to added/changed/deleted lines and new code introduces violations outside of added/changed lines, but its child nodes in added/changed lines, for checks not listed insupportContextStrategyChecks , it will accept violations whose line number belong to added/changed/deleted lines in patch file. | String | newline |
supportContextStrategyChecks | String has user defined Checks that support context strategy | String | null |
checkNamesForContextStrategyByTokenOrParentSet | String has user defined TreeWalker Checks that need modify violation nodes to their parent node to expand the context scope, split by comma | String | null |
checkNamesForContextStrategyByTokenOrAncestorSet | String has user defined TreeWalker Checks that need modify violation nodes to their ancestor node to expand the context scope, split by comma | String | null |
neverSuppressedChecks | String has user defined TreeWalker Checks to never suppress if files are touched, split by comma. This property is useful for Checks that place violation on whole file or on not all (first/last) occurrence of cause/violated code. | String | null |
Currently, the following checks supportcheckNamesForContextStrategyByTokenOrAncestorSet
property,other checks using this property will get the same effect likecheckNamesForContextStrategyByTokenOrParentSet
:
- ArrayTrailingComma
- AvoidNestedBlocks
- CommentsIndentation
- DefaultComesLast
- DeclarationOrder
- EqualsHashCode
- FinalLocalVariable
- FallThrough
- RightCurly
Currently, the following checks will suppress some violations that should not be suppressed when usingsupportContextStrategyChecks
.And you can usecheckNamesForContextStrategyByTokenOrParentSet
,checkNamesForContextStrategyByTokenOrAncestorSet
orneverSuppressedChecks
to get the larger context scope to solve this problem:
- ParameterNumberCheck
- SuperClone
- SuperFinalize
- BooleanExpressionComplexity
- OverloadMethodsDeclarationOrder
- UnnecessarySemicolonInEnumeration
Also, the following checks will suppress some violations that should not be suppressed when usingsupportContextStrategyChecks
orcheckNamesForContextStrategyByTokenOrParentSet
.So you need usecheckNamesForContextStrategyByTokenOrAncestorSet
orneverSuppressedChecks
to solve this problem:
- ArrayTrailingComma
- AvoidNestedBlocks
- CommentsIndentation
- DefaultComesLast
- DeclarationOrder
- EqualsHashCode
- FinalLocalVariable
- FallThrough
- RightCurly
- VariableDeclarationUsageDistance
Then the following checks will suppress some violations that should not be suppressed unless you useneverSuppressedChecks
:
- CovariantEquals
- EmptyLineSeparator
- CustomImportOrder
- ImportOrder
- RedundantImport
- UnusedImports
- PackageDeclaration
- MissingJavadocPackage
- MissingJavadocType
- OuterTypeNumberCheck
- OuterTypeFilename
- NoCodeInFileCheck
- Regexp
- AtclauseOrder
- JavadocMethod
- JavadocParagraph
- SummaryJavadoc
For example, the following configuration fragment directs the Checker to use a SuppressionJavaPatchFilterwith patch file config/file.patch and strategy isnewline
:
<modulename="com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter"> <propertyname="file"value="config/file.patch" /> <propertyname="strategy"value="newline" /></module>
the following configuration fragment directs the Checker to use a SuppressionJavaPatchFilterwith patch file config/file.patch and strategy ispatchedline
:
<modulename="com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter"> <propertyname="file"value="config/file.patch" /> <propertyname="strategy"value="patchedline" /></module>
the following configuration fragment direts the Checker to use a SuppressionJavaPatchFilterwith patch file config/file.patch, whose strategy iscontext
,support context strategy checkMethodLength
and never suppress checksEmptyBlock
andHiddenField
:
<modulename="com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter"> <propertyname="file"value="config/file.patch" /> <propertyname="strategy"value="context" /> <propertyname="supportContextStrategyChecks"value="MethodLength," /> <propertyname="neverSuppressedChecks"value="EmptyBlock,HiddenField" /></module>
the following configuration fragment direts the Checker to use a SuppressionJavaPatchFilterwith patch file config/file.patch, whose strategy iscontext
,expandSuperFinalize
's context scope to parents' nodeand expandEqualsHashCode
,FinalLocalVariable
's context scope to ancestors' node :
<modulename="com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter"> <propertyname="file"value="config/file.patch" /> <propertyname="strategy"value="context" /> <propertyname="checkNamesForContextStrategyByTokenOrParentSet"value="SuperFinalize," /> <propertyname="checkNamesForContextStrategyByTokenOrAncestorSet"value="EqualsHashCode,FinalLocalVariable" /></module>
- Checkstyle repository need to be cloned.
- Contribution repository need to be cloned.
Just clone this repository to your local.
$ git clone git@github.com:checkstyle/patch-filters.git
Because patch-filter has not been merged by Checkstyle, so you should local install this repository——patch-filters
$cd /path/to/patch-filters$ mvn clean install
then checkout topatch-filter-jar
in contribution repo
$cd /path/to/checkstyle-contribution$ git checkout patch-filter-jar
Firstly, you need to do is to modify projects-to-test-on.properties and test project that you want.For example, if I want to testguava
, then I will only remove # beforeguava
(anything that starts with #is considered a comment and is ignored.) and remove the specific version to changeguava|git|https://github.com/google/guava|v28.2||
toguava|git|https://github.com/google/guava||
, which aims to avoid auto checkout to the specific version indiff.groovy
.
Secondly, you need to set baseConfig.xml and patchConfig.xml by yourself.
Attention:
baseConfig does not need any checks in it and setseverity
toignore
,like<property name="severity" value="ignore"/>
;
patchConfig need Checks and patch-filter, added checks canrefer tohere,you can skip Translation Check and checks that reuqires extra config file (Header and RegExpHeader), patchfilter setting is like:
<modulename="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter"> <propertyname="file"value="${checkstyle.patchfilter.patch}"/></module>
You can findGeneratePatchFileLauncher
in/path/to/patch-filters/src/main/java/com/github/checkstyle/generatepatchfile/
,then add seven follow program arguments in Run/Debug Configurations:
# RepoPath of repository that will be checked by checkstyle, here example is guavapath/to/guava/# Path of checkstylepath/to/checkstyle/# Path of checkstyle-testerpatch/to/checkstyle-contribution/checkstyle-tester/# Patch-branch name of checkstyle, which can be any branch except master, because checkstyle-tester's diff mode# not allow the baseBranch and patchBranch have the same name, you can create a new branch based on master which# does not need any changes, here is branch name for example patch-filterpatch-filter# path to the base checkstyle configuration file. It will be applied to base branchpath/to/baseConfig.xml# path to the patch checkstyle config file. It will be applied to patch-filter branchpath/to/patchConfig.xml# commit parameter will be used to create patch-filter report# if commit parameter is number then the Generator will work in sequence mode,# for example if commit parameter is 4, then 3 reports that represent# the first three commits in HEAD branch will be created.4# sequence mode# Attention: num should be greater than 1, because if num is 1, no report will be created.# if commit parameter is a comma separated list of commit hashes then the Generator will work in set mode,# for example if commit parameter is 86bf3a482c68a3a466b278ae4c7bba4bd7be1d9c,aafac1c6d794750aeba9213e9b15a0b8f0e54f81# then 2 report that represent the two commit will be created if they belong to the HEAD branch.86bf3a482c68a3a466b278ae4c7bba4bd7be1d9c,aafac1c6d794750aeba9213e9b15a0b8f0e54f81# set mode
then, add Environment variables:
checkstyle.patchfilter.patch=/path/to/patch-filters/DiffReport/patch.txt
after above, if everything is ok, run it and then reports will be created in/path/to/patch-filters/DiffReport/
.for example, whenrepoPath
is guava andrunPatchNum
is 4, then result will look like:
- DiffReport
- guava-a1b3c06
- guava-bfc1cce
- guava-fb6ef19
- index.html
by default,guava
inguava-a1b3c06
meansrepo
's name,a1b3c06
inguava-a1b3c06
meansthe patch-filter diff report which use patch file between the commita1b3c06
and the commit beforea1b3c06
,so it represents the commita1b3c06
.
About
Suppression Filter for Checkstyle that is based on patch file
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.