Skip to content

Commit

Permalink
Issue #41: updated pmd validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Nov 15, 2017
1 parent 5fa95f4 commit 7f91b3d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
20 changes: 20 additions & 0 deletions config/pmd-main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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 Regression Tool main code
</description>
<exclude-pattern>.*/src/test/.*</exclude-pattern>
<rule ref="config/pmd.xml"/>

<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException">
<properties>
<!-- it is ok to throw exception in top level class -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main'] and //MethodDeclaration[@Name='main']"/>
</properties>
</rule>

</ruleset>
58 changes: 58 additions & 0 deletions config/pmd-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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 Regression Tool test code
</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"/>
<!--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="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>
</ruleset>
12 changes: 3 additions & 9 deletions config/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
PMD ruleset for Checkstyle Regression Tool
PMD common ruleset for Checkstyle Regression Tool
</description>
<rule ref="rulesets/java/basic.xml"/>
<rule ref="rulesets/java/braces.xml"/>
Expand All @@ -28,6 +28,7 @@
<rule ref="rulesets/java/codesize.xml/TooManyMethods" />
<rule ref="rulesets/java/codesize.xml/ExcessiveClassLength" />
<rule ref="rulesets/java/codesize.xml/ExcessiveMethodLength" />
<rule ref="rulesets/java/codesize.xml/ExcessiveParameterList" />

<rule ref="rulesets/java/comments.xml">
<!-- <exclude name="CommentRequired"/> -->
Expand Down Expand Up @@ -99,7 +100,6 @@
<rule ref="rulesets/java/design.xml/AccessorClassGeneration" />
<rule ref="rulesets/java/design.xml/PreserveStackTrace" />
<rule ref="rulesets/java/design.xml/EmptyMethodInAbstractClassShouldBeAbstract" />
<rule ref="rulesets/java/design.xml/AbstractClassWithoutAnyMethod" />

<rule ref="rulesets/java/design.xml/AvoidDeeplyNestedIfStmts">
<properties>
Expand All @@ -108,6 +108,7 @@
</properties>
</rule>

<rule ref="rulesets/java/design.xml/AvoidSynchronizedAtMethodLevel" />
<rule ref="rulesets/java/empty.xml"/>
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
<properties>
Expand All @@ -121,7 +122,6 @@
<!-- too many false-positives -->
<exclude name="BeanMembersShouldSerialize"/>
</rule>
<rule ref="rulesets/java/junit.xml"/>
<rule ref="rulesets/java/logging-jakarta-commons.xml"/>

<rule ref="rulesets/java/logging-java.xml"/>
Expand Down Expand Up @@ -195,12 +195,6 @@
</rule>
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingGenericException" />
<rule ref="rulesets/java/strictexception.xml/AvoidThrowingRawExceptionTypes" />
<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException">
<properties>
<!-- it is ok to throw exception in top level class -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main'] and //MethodDeclaration[@Name='main']"/>
</properties>
</rule>

<rule ref="rulesets/java/strings.xml"/>
<rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals">
Expand Down
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@
<skipEmptyReport>false</skipEmptyReport>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<!--<includeTests>true</includeTests> -->
<includeTests>true</includeTests>
<rulesets>
<ruleset>config/pmd.xml</ruleset>
<ruleset>config/pmd-main.xml</ruleset>
<ruleset>config/pmd-test.xml</ruleset>
</rulesets>
<excludeRoots>
<excludeRoot>src/test/resources</excludeRoot>
<excludeRoot>target/generated-sources/annotations</excludeRoot>
</excludeRoots>
</configuration>
</plugin>

Expand Down

0 comments on commit 7f91b3d

Please sign in to comment.