Files
maven-plugins/pmd/rulesets/design.xml
T

177 lines
3.8 KiB
XML

<?xml version="1.0"?>
<ruleset name="Design Rules">
<description>
The Design Ruleset contains a collection of rules that find questionable designs.
</description>
<rule name="UseSingletonRule"
message="All methods are static. Consider using Singleton instead."
class="net.sourceforge.pmd.rules.design.UseSingletonRule">
<description>
If you have a class that has nothing but static methods, consider making it a Singleton
</description>
<example>
<![CDATA[
public class MaybeASingleton {
public static void foo() {
// etc
}
public static void bar() {
// etc
}
}
]]>
</example>
</rule>
<rule name="LooseCouplingRule"
message="Avoid using implementation types like ''{0}''; use the interface instead"
class="net.sourceforge.pmd.rules.design.LooseCouplingRule">
<description>
Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead
</description>
<example>
<![CDATA[
import java.util.*;
public class Bar {
// should be "private List list"
private ArrayList list = new ArrayList();
// should be "public Set getFoo()"
public HashSet getFoo() {
return new HashSet();
}
}
]]>
</example>
</rule>
<rule name="SimplifyBooleanReturnsRule"
message="Avoid unnecessary if..then..else statements when returning a boolean"
class="net.sourceforge.pmd.rules.SimplifyBooleanReturnsRule">
<description>
Avoid unnecessary if..then..else statements when returning a boolean
</description>
<example>
<![CDATA[
public class Foo {
private int bar =2;
public boolean isBarEqualsTo(int x) {
// this bit of code
if (bar == x) {
return true;
} else {
return false;
}
// can be replaced with a simple
// return bar == x;
}
}
]]>
</example>
</rule>
<rule name="SwitchStmtsShouldHaveDefault"
message="Switch statements should have a default label"
class="net.sourceforge.pmd.rules.SwitchStmtsShouldHaveDefaultRule">
<description>
Switch statements should have a default label.
</description>
<example>
<![CDATA[
public class Foo {
public void bar() {
int x = 2;
switch (x) {
case 2: int j = 8;
}
}
}
]]>
</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>
<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"
message="Deeply nested if..then statements are hard to read"
class="net.sourceforge.pmd.rules.AvoidDeeplyNestedIfStmtsRule">
<description>
Deeply nested if..then statements are hard to read.
</description>
<properties>
<property name="problemDepth" value="3"/>
</properties>
<example>
<![CDATA[
public class Foo {
public void bar() {
int x=2;
int y=3;
int z=4;
if (x>y) {
if (y>z) {
if (z==x) {
// this is officially out of control now
}
}
}
}
}
]]>
</example>
</rule>
<rule name="AvoidReassigningParametersRule"
message="Avoid reassigning parameters such as ''{0}''"
class="net.sourceforge.pmd.rules.AvoidReassigningParametersRule">
<description>
Reassigning values to parameters is a questionable practice. Use a temporary local variable instead.
</description>
<example>
<![CDATA[
public class Foo {
private void foo(String bar) {
bar = "something else";
}
}
]]>
</example>
</rule>
</ruleset>