Skip to content

Commit

Permalink
supplemental: suppress PMD violations
Browse files Browse the repository at this point in the history
  • Loading branch information
mahfouz72 committed May 9, 2024
1 parent 2132b0d commit 8da7fc0
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 6 deletions.
21 changes: 19 additions & 2 deletions config/pmd-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
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 @@ -145,7 +150,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 @@ -200,7 +213,11 @@
<!-- We use thread to limit the stack size for a test method. -->
<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>
104 changes: 102 additions & 2 deletions config/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@
<!-- too much false-positives from 6.18.0 -->
<exclude name="UnusedPrivateMethod"/>
</rule>
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable">
<properties>
<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 +60,39 @@
or @SimpleName='JavadocPropertiesGenerator']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/LiteralsFirstInComparisons">
<properties>
<property name="violationSuppressXPath" value="//ClassDeclaration[
@SimpleName='XdocsUrlTest']//MethodDeclaration[@Name='characters' or @Name='endElement']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/LooseCoupling">
<properties>
<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>
<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 +207,13 @@
<property name="checkTopLevelTypes" value="false" />
</properties>
</rule>
<rule ref="category/java/codestyle.xml/UnnecessaryBoxing">
<properties>
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='IntMatchFilterElement']
//MethodDeclaration[@Name='hashCode']"/>
</properties>
</rule>

<rule ref="category/java/errorprone.xml">
<!-- That rule is not practical, no options to allow some magic numbers,
Expand Down Expand Up @@ -193,7 +254,16 @@
<!-- There is no alternative to using System.exit in the CLI class
to report the return code. -->
<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>
<property name="violationSuppressXPath"
value="//ClassDeclaration[@SimpleName='MainFrame']
//ConstructorDeclaration"/>
</properties>
</rule>

Expand Down Expand Up @@ -254,7 +324,9 @@
SiteUtil is a utility class providing different functionality. -->
<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 +444,12 @@
//MethodDeclaration[@Name='getDescriptionFromJavadoc']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal">
<properties>
<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 +473,28 @@
<exclude name="UseStringBufferForStringAppends"/>
</rule>

<rule ref="category/java/performance.xml/ConsecutiveAppendsShouldReuse">
<properties>
<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>
<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
2 changes: 1 addition & 1 deletion src/main/java/com/puppycrawl/tools/checkstyle/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private static OutputStreamOptions getOutputStreamOptions(Path outputPath) {
* @noinspection PackageVisibleInnerClass
* @noinspectionreason PackageVisibleInnerClass - we keep this enum package visible for tests
*/
enum OutputFormat {
/* package */ enum OutputFormat {
/** XML output format. */
XML,
/** SARIF output format. */
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 8da7fc0

Please sign in to comment.