Moved some rules into the 'controversial' ruleset
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1416 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -10,6 +10,7 @@ Fixed bug 683465 - JavaCC parser no longer has ability to throw java.lang.Error;
|
||||
Fixed bug in OverrideBothEqualsAndHashcodeRule - it no longer bails out with a NullPtrException on interfaces that declare a method signature "equals(Object)". Thx to Don Leckie for catching that.
|
||||
Added an optional Ant task formatter attribute 'isReportFilePathAbsolute'. Thx to Andriy Rozeluk for the feedback.
|
||||
Added an optional Ant task attribute 'failOnRuleViolation'. This stops the build if any rule violations are found.
|
||||
Moved several rules into a new "controversial" ruleset.
|
||||
|
||||
January 22, 2003 - 1.02:
|
||||
Added new rules: ImportFromSamePackageRule, SwitchDensityRule, NullAssignmentRule, UnusedModifierRule, ForLoopShouldBeWhileLoopRule
|
||||
|
@ -212,22 +212,6 @@ public class JumbledIncrementerRule1 {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnusedModifier"
|
||||
message="Unused modifiers are, well, unused"
|
||||
class="net.sourceforge.pmd.rules.UnusedModifierRule">
|
||||
<description>
|
||||
Unused modifiers are, well, unused.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public interface Foo {
|
||||
public abstract void bar(); // abstract compiles, but is useless
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ForLoopShouldBeWhileLoop"
|
||||
message="This for loop could be simplified to a while loop"
|
||||
class="net.sourceforge.pmd.rules.ForLoopShouldBeWhileLoopRule">
|
||||
|
99
pmd/rulesets/controversial.xml
Normal file
99
pmd/rulesets/controversial.xml
Normal file
@ -0,0 +1,99 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Controversial Rules">
|
||||
<description>
|
||||
The Controversial Ruleset contains rules that, for whatever reason, are considered controversial. They
|
||||
are separated out here to allow people to include as they see fit via custom rulesets. This ruleset was
|
||||
initially created in response to discussions over UnnecessaryConstructorRule which Tom likes but
|
||||
most people really dislike :-)
|
||||
</description>
|
||||
|
||||
<rule name="UnnecessaryConstructorRule"
|
||||
message="Avoid unnecessary constructors - the compiler will generate these for you"
|
||||
class="net.sourceforge.pmd.rules.UnnecessaryConstructorRule">
|
||||
<description>
|
||||
Unnecessary constructor detects when a constructor is not necessary; i.e., when there's only one constructor,
|
||||
it's public, has an empty body, and takes no arguments.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public Foo() {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
<rule name="NullAssignment"
|
||||
message="Assigning an Object to null is a code smell. Consider refactoring."
|
||||
class="net.sourceforge.pmd.rules.design.NullAssignmentRule">
|
||||
<description>
|
||||
Assigning a "null" to a variable (outside of its declaration) is usually in
|
||||
bad form. Some times, the assignment is an indication that the programmer doesn't
|
||||
completely understand what is going on in the code. NOTE: This sort of assignment
|
||||
may in rare cases be useful to encourage garbage collection. If that's what you're using
|
||||
it for, by all means, disregard this rule :-)
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
Object x = null; // This is OK.
|
||||
x = new Object();
|
||||
// Big, complex piece of code here.
|
||||
x = null; // This is BAD.
|
||||
// Big, complex piece of code here.
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
|
||||
</rule>
|
||||
<rule name="OnlyOneReturn"
|
||||
message="A method should have only one exit point, and that should be the last statement in the method"
|
||||
class="net.sourceforge.pmd.rules.design.OnlyOneReturnRule">
|
||||
<description>
|
||||
A method should have only one exit point, and that should be the last statement in the method.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class OneReturnOnly1 {
|
||||
public void foo(int x) {
|
||||
if (x > 0) {
|
||||
return "hey"; // oops, multiple exit points!
|
||||
}
|
||||
return "hi";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnusedModifier"
|
||||
message="Unused modifiers are, well, unused"
|
||||
class="net.sourceforge.pmd.rules.UnusedModifierRule">
|
||||
<description>
|
||||
Unused modifiers are, well, unused.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public interface Foo {
|
||||
public abstract void bar(); // abstract compiles, but is useless
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
@ -105,27 +105,6 @@ public class Foo {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="OnlyOneReturn"
|
||||
message="A method should have only one exit point, and that should be the last statement in the method"
|
||||
class="net.sourceforge.pmd.rules.design.OnlyOneReturnRule">
|
||||
<description>
|
||||
A method should have only one exit point, and that should be the last statement in the method.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class OneReturnOnly1 {
|
||||
public void foo(int x) {
|
||||
if (x > 0) {
|
||||
return "hey"; // oops, multiple exit points!
|
||||
}
|
||||
return "hi";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="AvoidDeeplyNestedIfStmts"
|
||||
@ -213,33 +192,6 @@ public class Foo {
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="NullAssignment"
|
||||
message="Assigning an Object to null is a code smell. Consider refactoring."
|
||||
class="net.sourceforge.pmd.rules.design.NullAssignmentRule">
|
||||
<description>
|
||||
Assigning a "null" to a variable (outside of its declaration) is usually in
|
||||
bad form. Some times, the assignment is an indication that the programmer doesn't
|
||||
completely understand what is going on in the code. NOTE: This sort of assignment
|
||||
may in rare cases be useful to encourage garbage collection. If that's what you're using
|
||||
it for, by all means, disregard this rule :-)
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
Object x = null; // This is OK.
|
||||
x = new Object();
|
||||
// Big, complex piece of code here.
|
||||
x = null; // This is BAD.
|
||||
// Big, complex piece of code here.
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
@ -1 +1 @@
|
||||
rulesets.filenames=rulesets/strings.xml,rulesets/junit.xml,rulesets/braces.xml,rulesets/basic.xml,rulesets/unusedcode.xml,rulesets/design.xml,rulesets/naming.xml,rulesets/imports.xml,rulesets/codesize.xml
|
||||
rulesets.filenames=rulesets/strings.xml,rulesets/junit.xml,rulesets/braces.xml,rulesets/basic.xml,rulesets/unusedcode.xml,rulesets/design.xml,rulesets/naming.xml,rulesets/imports.xml,rulesets/codesize.xml,rulesets/controversial.xml
|
@ -86,22 +86,6 @@ public class Foo {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnnecessaryConstructorRule"
|
||||
message="Avoid unnecessary constructors - the compiler will generate these for you"
|
||||
class="net.sourceforge.pmd.rules.UnnecessaryConstructorRule">
|
||||
<description>
|
||||
Unnecessary constructor detects when a constructor is not necessary; i.e., when there's only one constructor,
|
||||
it's public, has an empty body, and takes no arguments.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public Foo() {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
Reference in New Issue
Block a user