Skip to content

Commit

Permalink
supplemental: suppress PMD violations
Browse files Browse the repository at this point in the history
  • Loading branch information
mahfouz72 authored and romani committed May 12, 2024
1 parent 3f35a6f commit 4a1e34e
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 5 deletions.
31 changes: 29 additions & 2 deletions config/pmd-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,20 @@
assertion calls are not required as they are called by the library.
In MainTest PMD does not find asserts in lambdas called in the method
invokeAndWait. -->
<!-- For AllCheckTest.testAllModulesAreReferencedInConfigFile,
testAllCheckTokensAreReferencedInCheckstyleConfigFile,
testAllCheckTokensAreReferencedInGoogleConfigFile,
testAllCheckstyleModulesHaveXdocDocumentation
until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='AllChecksTest'
or @SimpleName='AstRegressionTest'
or @SimpleName='ImportControlCheckTest']//PrimaryPrefix/Name[@Name='verify']
| //ClassDeclaration[@SimpleName='AllChecksTest']
//MethodDeclaration[@Name='testAllModulesAreReferencedInConfigFile'
or @Name='testAllCheckTokensAreReferencedInCheckstyleConfigFile'
or @Name='testAllCheckTokensAreReferencedInGoogleConfigFile'
or @Name='testAllCheckstyleModulesHaveXdocDocumentation']
| //ClassDeclaration[@SimpleName='MainTest']
//PrimaryPrefix//Name[starts-with(@SimpleName, 'assert')]
| //ClassDeclaration[@SimpleName='XdocsPagesTest']
Expand Down Expand Up @@ -137,6 +147,8 @@
as they check each token and each rule explicitly.
JavadocTokenTypes.testTokenValues contains several asserts as it checks each
token explicitly. -->
<!-- For ClassImportRuleTest and all the below suppressions
until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='JavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenValues']
Expand All @@ -145,7 +157,15 @@
| //ClassDeclaration[@SimpleName='GeneratedJavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbers']
| //ClassDeclaration[@SimpleName='ParseTreeTablePresentationTest']
//MethodDeclaration[@Name='testGetValueAtDetailNode']"/>
//MethodDeclaration[@Name='testGetValueAtDetailNode']
| //ClassDeclaration[@SimpleName='ClassImportRuleTest']
| //ClassDeclaration[@SimpleName='PkgImportRuleTest']
| //ClassDeclaration[@SimpleName='PkgImportControlTest']
//MethodDeclaration[ends-with(@Name, 'CheckAccess')]
| //ClassDeclaration[@SimpleName='JavadocTagInfoTest']
//MethodDeclaration[@Name='testCoverage']
| //ClassDeclaration[@SimpleName='AstRegressionTest']
//MethodDeclaration[@Name='testCustomAstTree']"/>
</properties>
</rule>

Expand Down Expand Up @@ -198,9 +218,16 @@
<rule ref="category/java/multithreading.xml/DoNotUseThreads">
<properties>
<!-- We use thread to limit the stack size for a test method. -->
<!-- For SuppressionFilterTest.isConnectionAvailableAndStable and
SuppressionsLoaderTest.loadFilterSet
https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='TestUtil']
//MethodDeclaration[@Name='getResultWithLimitedResources']"/>
//MethodDeclaration[@Name='getResultWithLimitedResources']
| //ClassDeclaration[@SimpleName='SuppressionFilterTest']
//MethodDeclaration[@Name='isConnectionAvailableAndStable']
| //ClassDeclaration[@SimpleName='SuppressionsLoaderTest']
//MethodDeclaration[@Name='loadFilterSet']"/>
</properties>
</rule>
</ruleset>
125 changes: 123 additions & 2 deletions config/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
<!-- too much false-positives from 6.18.0 -->
<exclude name="UnusedPrivateMethod"/>
</rule>
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='FilterUtil']
//MethodDeclaration[@Name='isFileExists']
| //ClassDeclaration[@SimpleName='TreeWalkerTest']
//MethodDeclaration[@Name='testNoAuditEventsWithoutFilters']
| //ClassDeclaration[@SimpleName='OrderedPropertiesCheckTest']
//MethodDeclaration[@Name='getFileNotFoundDetail']
| //ClassDeclaration[@SimpleName='UniquePropertiesCheckTest']
//MethodDeclaration[@Name='getFileNotFoundDetail']
| //ClassDeclaration[@SimpleName='HeaderCheckTest']
//MethodDeclaration[@Name='testIoExceptionWhenLoadingHeader']
| //ClassDeclaration[@SimpleName='CustomImportOrderCheckTest']
//MethodDeclaration[@Name='testGetFullImportIdent']
| //ClassDeclaration[@SimpleName='MainFrameTest']
//MethodDeclaration[@Name='testOpenFileButton']
| //ClassDeclaration[@SimpleName='ConfigurationLoaderTest']
//MethodDeclaration[@Name='testConfigWithIgnoreExceptionalAttributes']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace">
<properties>
<!-- It is ok to use print stack trace in CLI class. -->
Expand All @@ -39,6 +61,42 @@
or @SimpleName='JavadocPropertiesGenerator']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/LiteralsFirstInComparisons">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath" value="//ClassDeclaration[
@SimpleName='XdocsUrlTest']//MethodDeclaration[@Name='characters' or @Name='endElement']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/LooseCoupling">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='CodeSelectorPresentationTest']
//FieldDeclaration//VariableDeclarator[@Name='linesToPosition']
| //ClassDeclaration[@SimpleName='FileText']
//ConstructorDeclaration
| //ClassDeclaration[@SimpleName='ArchUnitSuperClassTest']
//MethodDeclaration[@Name=
'testChecksShouldHaveAllowedAbstractClassAsSuperclass']
| //ClassDeclaration[@SimpleName='ArchUnitTest']
//MethodDeclaration[@Name='nonProtectedCheckMethodsTest'
or @Name='testClassesInApiDoNotDependOnClassesInUtil']
| //ClassDeclaration[@SimpleName='ImmutabilityTest']
//FieldDeclaration//VariableDeclarator[@Name='CHECKSTYLE_CHECKS']
| //ClassDeclaration[@SimpleName='ImmutabilityTest']
//MethodDeclaration[@Name='testUtilClassesImmutability']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/UnnecessaryVarargsArrayCreation">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='CustomImportOrderCheckTest']
//MethodDeclaration[@Name='testGetFullImportIdent']"/>
</properties>
</rule>


<rule ref="category/java/documentation.xml">
<!-- We use class comments as source for xdoc files,
Expand Down Expand Up @@ -153,6 +211,22 @@
<property name="checkTopLevelTypes" value="false" />
</properties>
</rule>
<rule ref="category/java/codestyle.xml/UnnecessaryBoxing">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='IntMatchFilterElement']
//MethodDeclaration[@Name='hashCode']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/CommentDefaultAccessModifier">
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<properties>
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='Main']
//EnumDeclaration[@SimpleName='OutputFormat']"/>
</properties>
</rule>

<rule ref="category/java/errorprone.xml">
<!-- That rule is not practical, no options to allow some magic numbers,
Expand Down Expand Up @@ -192,8 +266,20 @@
<properties>
<!-- There is no alternative to using System.exit in the CLI class
to report the return code. -->
<!-- For MainTest.assertMainReturnCode
until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='ExitHelper']"/>
value="//ClassDeclaration[@SimpleName='ExitHelper']
| //ClassDeclaration[@SimpleName='MainTest']
//MethodDeclaration[@Name='assertMainReturnCode'] "/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/ConstructorCallsOverridableMethod">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='MainFrame']
//ConstructorDeclaration"/>
</properties>
</rule>

Expand Down Expand Up @@ -252,9 +338,13 @@
<properties>
<!-- I do not see any problem, looks like a false positive.
SiteUtil is a utility class providing different functionality. -->
<!-- For all Except SiteUtil and HandlerFactory
until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='HandlerFactory'
or @SimpleName='SiteUtil']"/>
or @SimpleName='SiteUtil' or @SimpleName='Checker' or @SimpleName='JavaAstVisitor'
or @SimpleName='Main' or @SimpleName='TreeWalker' or @SimpleName='CheckstyleAntTask'
or @SimpleName='TranslationCheck' or @SimpleName='JavadocMethodCheck']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/NcssCount">
Expand Down Expand Up @@ -372,6 +462,13 @@
//MethodDeclaration[@Name='getDescriptionFromJavadoc']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='AbstractInvalidClass']"/>
</properties>
</rule>

<rule ref="category/java/multithreading.xml">
<!-- Checkstyle is not thread safe till https://github.com/checkstyle/checkstyle/projects/5. -->
Expand All @@ -395,6 +492,30 @@
<exclude name="UseStringBufferForStringAppends"/>
</rule>

<rule ref="category/java/performance.xml/ConsecutiveAppendsShouldReuse">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='XMLLogger']
//MethodDeclaration[@Name='encode']
| //ClassDeclaration[@SimpleName='InlineTagUtil']
//MethodDeclaration[@Name='convertLinesToString']
| //ClassDeclaration[@SimpleName='XdocsPagesTest']
//MethodDeclaration[@Name='validateViolationSection']
| //ClassDeclaration[@SimpleName='XdocsJavaDocsTest']
//MethodDeclaration[@Name='createPropertiesText'
or @Name='appendNodeText' or @Name='getAttributeText']"/>
</properties>
</rule>
<rule ref="category/java/performance.xml/UseArraysAsList">
<properties>
<!-- until https://github.com/checkstyle/checkstyle/issues/14870 -->
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='DescriptionExtractor']
//MethodDeclaration[@Name='getDescriptionNodes']"/>
</properties>
</rule>

<rule ref="category/java/design.xml/ExcessivePublicCount">
<properties>
<property name="violationSuppressXPath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ public void testClearState() throws Exception {
assertWithMessage("State is not cleared on beginTree")
.that(TestUtil.isStatefulFieldClearedDuringBeginTree(check,
staticImport.orElseThrow(), "lastImportStatic",
lastImportStatic -> !((boolean) lastImportStatic)))
lastImportStatic -> !(boolean) lastImportStatic))
.isTrue();

}
Expand Down

0 comments on commit 4a1e34e

Please sign in to comment.