1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
<?xml version="1.0"?>
<ruleset name="PMD ruleset for Checkstyle"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
PMD ruleset for Checkstyle tests
</description>
<exclude-pattern>.*/src/main/.*</exclude-pattern>
<rule ref="config/pmd.xml">
<!-- We do throws Exception, as any exception that in not caught in test should fail
a test that is expected behavior and we like it as it follow fail-fast and helps
to avoid extra catch blocks -->
<exclude name="SignatureDeclareThrowsException"/>
<!-- it madness to move all string values to common variables,
it will be hard to read test code -->
<exclude name="AvoidDuplicateLiterals"/>
<!-- we do not need javadoc on test code -->
<exclude name="CommentRequired"/>
<!-- we like static imports in UTs as them minimize the code and we know that most of
such methods are from UT+moks frameworks -->
<exclude name="TooManyStaticImports"/>
<!-- we try to keep all testing for class in one place/class/file to ease navigation
between target class and it's test -->
<exclude name="TooManyMethods"/>
<!-- we have too much UTs for each main class, it is better to keep all tests in one
file to ease navigation and search for tes -->
<exclude name="CouplingBetweenObjects"/>
<!-- we have too much UTs for each main class, it is better to keep all tests in one
file to ease navigation and search for test -->
<exclude name="ExcessiveImports"/>
<!-- test should be named as their main class -->
<exclude name="ClassNamingConventions"/>
<!-- checkstyle do not use IP in configuration, so all values in tests are ok to use,
they just another test string data -->
<exclude name="AvoidUsingHardCodedIP"/>
<!-- UTests are required to be public by design -->
<exclude name="ExcessivePublicCount"/>
<!-- we have too much UTs for each main class, it is better to keep all tests in one
file to ease navigation and search for test -->
<exclude name="ExcessiveClassLength"/>
<!-- we want to avoid wide throws signature, it is just test -->
<exclude name="AvoidCatchingGenericException"/>
<!-- we do not want invest extra time to make logic ideal
in test method, may be later... -->
<exclude name="NPathComplexity"/>
<!-- conflicts with checkstyle rule -->
<exclude name="JUnitUseExpected"/>
<!-- will be addressed in https://github.com/checkstyle/checkstyle/projects/5 -->
<exclude name="NonThreadSafeSingleton"/>
</rule>
<rule ref="category/java/design.xml/NcssCount">
<properties>
<!-- We want to keep it all in one place. -->
<property name="classReportLevel" value="1000"/>
<!-- A big enough value to satisfy the most cases. -->
<property name="methodReportLevel" value="100"/>
<!-- GeneratedJavaTokenTypesTest.testTokenNumbering' is simple but long as it recheck
each token one by one. Same goes for
GeneratedJavadocTokenTypesTest#testTokenNumbers.
JavadocTokenTypesTest.TokenValues contains several asserts as it checks each
token explicitly.
XdocsPagesTest.getModulePropertyExpectedTypeName is a complicated list of
different checks.
IndentationCheckTest has a lot of cases. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='JavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenValues']
| //ClassOrInterfaceDeclaration[@SimpleName='GeneratedJavaTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbering']
| //ClassOrInterfaceDeclaration[@SimpleName='XdocsPagesTest']
//MethodDeclaration[@Name='getModulePropertyExpectedTypeName']
| //ClassOrInterfaceDeclaration[@SimpleName='GeneratedJavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbers']
| //ClassOrInterfaceDeclaration[@SimpleName='IndentationCheckTest']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveMethodLength">
<properties>
<!-- GeneratedJavaTokenTypesTest.testTokenNumbering' is simple but long as it recheck
each token one by one. Same goes for GeneratedJavadocTokenTypesTest#testTokenNumbers.
ParenPadCheckTest.testNospaceWithComplexInput is intended to keep all in one method.
JavadocTokenTypesTest.TokenValues contains several asserts as it checks each
token explicitly.
XdocsPagesTest.getModulePropertyExpectedTypeName is a complicated list of
different checks. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='GeneratedJavaTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbering']
| //ClassOrInterfaceDeclaration[@SimpleName='ParenPadCheckTest']
//MethodDeclaration[@Name='testNospaceWithComplexInput']
| //ClassOrInterfaceDeclaration[@SimpleName='ParenPadTest']
//MethodDeclaration[@Name='testMethodParen']
| //ClassOrInterfaceDeclaration[@SimpleName='JavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenValues']
| //ClassOrInterfaceDeclaration[@SimpleName='XdocsPagesTest']
//MethodDeclaration[@Name='getModulePropertyExpectedTypeName']
| //ClassOrInterfaceDeclaration[@SimpleName='GeneratedJavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbers']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/JUnitTestsShouldIncludeAssert">
<!-- PMD cannot find assert if it is located in private method of this class called from
the test method or method of another class. -->
<properties>
<!-- In AllChecksTest, AstRegressionTest and ImportControlCheckTest
PMD does not find asserts in private methods of the test class called from the
test method.
In MainTest PMD does not find asserts in lambdas called in the method
exit.checkAssertionAfterwards.
In AstRegressionTest PMD does not find asserts in inner classes methods called
from the test method.
In XdocsPagesTest PMD does not find asserts in lambdas.
All test classes which starts with XpathRegression have asserts inside parent's method.
In ArchUnitTest assertion calls are not required as they are called by the library -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='AllChecksTest'
or @SimpleName='AstRegressionTest'
or @SimpleName='ImportControlCheckTest']//PrimaryPrefix/Name[@Image='verify']
| //ClassOrInterfaceDeclaration[@SimpleName='MainTest']
//PrimaryPrefix//Name[starts-with(@SimpleName, 'assert')]
| //ClassOrInterfaceDeclaration[@SimpleName='XdocsPagesTest']
//MethodDeclaration[@Name='testAllChecksPresentOnAvailableChecksPage']
| //ClassOrInterfaceDeclaration[@SimpleName='XdocsJavaDocsTest']
//MethodDeclaration[@Name='testAllCheckSectionJavaDocs']
| //ClassOrInterfaceDeclaration[starts-with(@SimpleName,'XpathRegression')]
//MethodDeclaration
| //ClassOrInterfaceDeclaration[@SimpleName='ArchUnitTest']
//MethodDeclaration"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/JUnit4TestShouldUseBeforeAnnotation">
<properties>
<!-- A false positive. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='CommitValidationTest']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/JUnitTestContainsTooManyAsserts">
<properties>
<property name="maximumAsserts" value="11"/>
<!-- GeneratedJavadocTokenTypesTest.testTokenNumbers and
GeneratedJavadocTokenTypesTest.testRuleNumbers contains several asserts
as they check each token and each rule explicitly.
JavadocTokenTypes.testTokenValues contains several asserts as it checks each
token explicitly. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='JavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenValues']
| //ClassOrInterfaceDeclaration[@SimpleName='GeneratedJavaTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbering']
| //ClassOrInterfaceDeclaration[@SimpleName='GeneratedJavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbers']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ConfusingTernary">
<properties>
<!-- A false positive: commit validation is a sequence of checks, if we shuffle them
it would be broken. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='CommitValidationTest']
//MethodDeclaration[@Name='validateCommitMessage']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ShortMethodName">
<properties>
<!-- This inherited from GeneratedJavaLexer. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='AssertGeneratedJavaLexer']
//MethodDeclaration[@Name='LA']
| //ClassOrInterfaceDeclaration[@SimpleName='AssertGenTextBlockLexer']
//MethodDeclaration[@Name='LA']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/UseObjectForClearerAPI">
<properties>
<!-- This is checking for amount of String arguments more than 3 (hardcoded).
Extra abstraction(object) for single method does not make code more readable or
easy to maintain. The rule should also only check public methods but has a bug.
Suppress the false-positives. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='SuppressionXpathSingleFilterTest']
//MethodDeclaration[@Name='createSuppressionXpathSingleFilter']
| //ClassOrInterfaceDeclaration[ @SimpleName='XdocsPagesTest']
//MethodDeclaration[@Name='validateRuleNameOrder']"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/CloseResource">
<properties>
<!-- we do close streams in special methods -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='XdocsPagesTest']
//MethodDeclaration[@Name='getModulePropertyExpectedValue']
| //ClassOrInterfaceDeclaration[@SimpleName='DefaultLoggerPowerTest']
//MethodDeclaration[@Name='testNewCtor']
| //ClassOrInterfaceDeclaration[@SimpleName='ImportControlLoaderPowerTest']
//MethodDeclaration[@Name='testInputStreamThatFailsOnClose']
| //ClassOrInterfaceDeclaration[@SimpleName='ImportControlLoaderPowerTest']
//MethodDeclaration[@Name='testInputStreamFailsOnRead']
| //ClassOrInterfaceDeclaration[@SimpleName='XpathFileGeneratorAuditListenerTest']
//MethodDeclaration[@Name='verifyOutput']
| //ClassOrInterfaceDeclaration[@SimpleName='CommonUtilTest']
//MethodDeclaration[@Name='testClose']"/>
</properties>
</rule>
</ruleset>
|