config/pmd-test.xml (99 lines of code) (raw):

<?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="AbstractNaming"/> <!--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 keep it all in one place--> <exclude name="NcssTypeCount"/> <!--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="rulesets/java/codesize.xml/NcssMethodCount"> <properties> <!-- 'testTokenNumbering' method is simple but long as it recheck each token one by one --> <!-- 'testNospaceWithComplexInput' it is intended to keep all in one method. --> <!--Method `testTokenValues` in JavadocTokenTypes contains several asserts as it checks each token explicitly--> <!-- XdocsPagesTest is a complicated list of different checks --> <property name="violationSuppressXPath" value=" //ClassOrInterfaceDeclaration[@Image='GeneratedJavaTokenTypesTest']//MethodDeclarator[@Image='testTokenNumbering'] | //ClassOrInterfaceDeclaration[@Image='ParenPadCheckTest']//MethodDeclarator[@Image='testNospaceWithComplexInput'] | //MethodDeclaration[@Name='testTokenValues' and ../../..[@Image='JavadocTokenTypesTest']] | //MethodDeclaration[@Name='getModulePropertyExpectedValue' and ../../..[@Image='XdocsPagesTest']]"/> </properties> </rule> <rule ref="rulesets/java/codesize.xml/ExcessiveMethodLength"> <properties> <!-- 'testTokenNumbering' method is simple but long as it recheck each token one by one --> <!-- 'testNospaceWithComplexInput' it is intended to keep all in one method. --> <!--Method `testTokenValues` in JavadocTokenTypes contains several asserts as it checks each token explicitly--> <!-- XdocsPagesTest is a complicated list of different checks --> <property name="violationSuppressXPath" value=" //ClassOrInterfaceDeclaration[@Image='GeneratedJavaTokenTypesTest']//MethodDeclarator[@Image='testTokenNumbering'] | //ClassOrInterfaceDeclaration[@Image='ParenPadCheckTest']//MethodDeclarator[@Image='testNospaceWithComplexInput'] | //ClassOrInterfaceDeclaration[@Image='ParenPadTest']//MethodDeclarator[@Image='testMethodParen'] | //MethodDeclaration[@Name='testTokenValues' and ../../..[@Image='JavadocTokenTypesTest']] | //MethodDeclaration[@Name='getModulePropertyExpectedTypeName' and ../../..[@Image='XdocsPagesTest']]"/> </properties> </rule> <rule ref="rulesets/java/junit.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 SuppressionCommentFilterTest, SuppressWithNearbyCommentFilterTest, SuppressionFilterTest, SuppressionXpathFilterTest, XpathFilterTest pmd does not accept nl.jqno.equalsverifier.EqualsVerifier#.verify() as correctness check method --> <!-- in AbstractJavadocCheckTest pmd does not find asserts in another class methods called from the test method --> <!-- in ImportControlCheckTest, DetailASTTest pmd does not find asserts in private methods of the test class called from the test method --> <!-- in AstRegressionTest pmd does not find asserts in inner classes methods called from the test method --> <!-- in AllChecksTest pmd does not find asserts in lambdas --> <!-- in DetailASTTest pmd does not find asserts in lambdas --> <property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='SuppressionFilterTest']//MethodDeclarator[@Image='testEqualsAndHashCode'] | //ClassOrInterfaceDeclaration[@Image='SuppressionCommentFilterTest']//MethodDeclarator[@Image='testEqualsAndHashCodeOfTagClass'] | //ClassOrInterfaceDeclaration[@Image='SuppressWithNearbyCommentFilterTest']//MethodDeclarator[@Image='testEqualsAndHashCodeOfTagClass'] | //ClassOrInterfaceDeclaration[@Image='SuppressionXpathFilterTest']//MethodDeclarator[@Image='testEqualsAndHashCode'] | //ClassOrInterfaceDeclaration[@Image='XpathFilterTest']//MethodDeclarator[@Image='testEqualsAndHashCode'] | //ClassOrInterfaceDeclaration[@Image='AbstractJavadocCheckTest']//MethodDeclarator[@Image='testBlockCommentPositionHasPrivateConstr'] | //ClassOrInterfaceDeclaration[@Image='ImportControlCheckTest']//MethodDeclarator[@Image='testPkgRegExpInChild'] | //ClassOrInterfaceDeclaration[@Image='ImportControlCheckTest']//MethodDeclarator[@Image='testPkgRegExpInParent'] | //ClassOrInterfaceDeclaration[@Image='ImportControlCheckTest']//MethodDeclarator[@Image='testPkgRegExpInBoth'] | //ClassOrInterfaceDeclaration[@Image='AstRegressionTest']//MethodDeclarator[@Image='testImpossibleValid'] | //ClassOrInterfaceDeclaration[@Image='AllChecksTest']//MethodDeclarator[@Image='testAllModulesAreReferencedInConfigFile'] | //ClassOrInterfaceDeclaration[@Image='DetailASTTest']//MethodDeclarator[@Image='testTreeStructure'] | //ClassOrInterfaceDeclaration[@Image='SuppressWithPlainTextCommentFilterTest']//MethodDeclarator[@Image='testEqualsAndHashCodeOfTagClass'] "/> </properties> </rule> <rule ref="config/pmd.xml/ConfusingTernary"> <properties> <!-- false positive: commit validation is a sequence of checks, if we shuffle them it would be broken --> <property name="violationSuppressXPath" value="//MethodDeclaration[@Name='validateCommitMessage' and ../../..[@Image='CommitValidationTest']]"/> </properties> </rule> <rule ref="rulesets/java/migrating.xml/JUnit4TestShouldUseBeforeAnnotation"> <properties> <!-- false positive --> <property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='CommitValidationTest']"/> </properties> </rule> <rule ref="rulesets/java/junit.xml/JUnitTestContainsTooManyAsserts"> <properties> <property name="maximumAsserts" value="11"/> <!--Methods `testTokenNumbers` and `testRuleNumbers` in GeneratedJavadocTokenTypesTest contain several asserts as they check each token and each rule explicitly--> <!--Method `testTokenValues` in JavadocTokenTypes contains several asserts as it checks each token explicitly--> <property name="violationSuppressXPath" value=" //ClassOrInterfaceDeclaration[@Image='GeneratedJavadocTokenTypesTest'] | //MethodDeclaration[@Name='testTokenValues' and ../../..[@Image='JavadocTokenTypesTest']]"/> </properties> </rule> <rule ref="rulesets/java/naming.xml/ShortMethodName"> <properties> <!-- this inherited from GeneratedJavaLexer --> <property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='AstRegressionTest'] | //ClassOrInterfaceDeclaration[@Image='AssertGeneratedJavaLexer']//MethodDeclarator[@Image='LA']"/> </properties> </rule> <rule ref="rulesets/java/unusedcode.xml/UnusedPrivateMethod"> <properties> <!-- generates false-positives on private methods called within a file --> <property name="violationSuppressXPath" value=" //ClassOrInterfaceDeclaration[@Image='IndentationCheckTest']//MethodDeclarator[@Image='verifyWarns'] | //ClassOrInterfaceDeclaration[@Image='SuppressWarningsFilterTest']//MethodDeclarator[@Image='verifySuppressed'] | //ClassOrInterfaceDeclaration[@Image='SuppressWithNearbyCommentFilterTest']//MethodDeclarator[@Image='verifySuppressed'] | //ClassOrInterfaceDeclaration[@Image='SuppressionCommentFilterTest']//MethodDeclarator[@Image='verifySuppressed']"/> </properties> </rule> </ruleset>