I've got a custom ruleset file that has the following as part of it:
<rule ref="rulesets/java/basic.xml/CollapsibleIfStatements" message="foobarbaz" >
<priority>5</priority>
</rule>
When I run pmd via the 3.0.1 version of the maven-pmd-plugin, violations of this rule occur twice; once with the original priority, once with the new one. (If I add a message to the rule reference, the second violation with the new priority will also show up.)
Is this user error, expected behavior, or an actual bug? Is there some other way to CHANGE priority, rather than add a new rule with a new priority? I used the directions at http://pmd.sourceforge.net/pmd-5.0.3/howtomakearuleset.html.
Sample output in pmd.xml is below:
<violation beginline="551" endline="558" begincolumn="17" endcolumn="17" rule="CollapsibleIfStatements" ruleset="Basic" package="com.pmdtest" class="IfsTest" method="hasManyIfs" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.3/rules/java/basic.html#CollapsibleIfStatements" priority="3">
These nested if statements could be combined
</violation>
<violation beginline="551" endline="558" begincolumn="17" endcolumn="17" rule="CollapsibleIfStatements" ruleset="Basic" package="com.pmdtest" class="IfsTest" method="hasManyIfs" externalInfoUrl="http://pmd.sourceforge.net/pmd-5.0.3/rules/java/basic.html#CollapsibleIfStatements" priority="5">
foobarbaz
</violation>
Hi,
I assume, that you import in your custom ruleset the basic ruleset and then (re)define the priority of the CollapsibleIfStatements rule.
If this is the case, you can for now workaround this issue by excluding the rules you redefine:
However, I agree, that the default behaviour should be to overwrite/redefine existing rule definitions, rather than adding duplicates. This would make this feature easier to use.
Thanks,
Andreas
Andreas,
Yes, this is precisely the issue. I'm importing all of basic, and then trying to redefine just this priority. The workaround you propose works perfectly for me.
Thanks!
Michael