Made the plugin work with Maven b9
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
91b265cc3a
commit
8786cd4a91
@ -3,3 +3,4 @@ maven.log
|
||||
.project
|
||||
build.properties
|
||||
velocity.log
|
||||
target
|
||||
@ -1,45 +1,78 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<project
|
||||
xmlns:j="jelly:core"
|
||||
xmlns:doc="doc">
|
||||
<!--
|
||||
=============================================================================
|
||||
PMD Plugin. Generate PMD reports using the PMD framework.
|
||||
=============================================================================
|
||||
-->
|
||||
<project xmlns:j="jelly:core" xmlns:doc="doc">
|
||||
|
||||
<!--
|
||||
========================================================================
|
||||
Register a PMD report.
|
||||
========================================================================
|
||||
-->
|
||||
<goal name="maven-pmd-plugin:register">
|
||||
<j:if test="${sourcesPresent}">
|
||||
<doc:registerReport
|
||||
name="PMD"
|
||||
link="pmd-report"
|
||||
description="PMD Report."/>
|
||||
name="PMD Report"
|
||||
pluginName="pmd"
|
||||
description="Verification of coding rules."
|
||||
link="pmd-report"/>
|
||||
</j:if>
|
||||
</goal>
|
||||
|
||||
<!-- ================================================================== -->
|
||||
<!-- P M D T A R G E T -->
|
||||
<!-- ================================================================== -->
|
||||
<!--
|
||||
========================================================================
|
||||
Deregister a PMD report.
|
||||
========================================================================
|
||||
-->
|
||||
<goal name="maven-pmd-plugin:deregister">
|
||||
<j:if test="${sourcesPresent}">
|
||||
<doc:deregisterReport name="PMD Report"/>
|
||||
</j:if>
|
||||
</goal>
|
||||
|
||||
<!--
|
||||
========================================================================
|
||||
Main PMD plugin goal.
|
||||
========================================================================
|
||||
-->
|
||||
<goal name="pmd" description="Static Code Analyzer">
|
||||
|
||||
<!-- Only run PMD if it is enabled -->
|
||||
<j:set var="enable" value="${maven.pmd.enable}"/>
|
||||
|
||||
<!-- Either am bloody dumb or this is the only way to make it work ?! -->
|
||||
<j:if test="${enable.toString().equalsIgnoreCase('true')}">
|
||||
<attainGoal name="maven-pmd-plugin:report"/>
|
||||
<attainGoal name="pmd:report"/>
|
||||
</j:if>
|
||||
|
||||
</goal>
|
||||
|
||||
<goal name="maven-pmd-plugin:report"
|
||||
<!--
|
||||
========================================================================
|
||||
Generate the PMD report.
|
||||
========================================================================
|
||||
-->
|
||||
<goal name="pmd:report"
|
||||
description="Generate source code report with PMD">
|
||||
|
||||
<!-- Create the dirs if we start from a previously cleaned project -->
|
||||
|
||||
<mkdir dir="${maven.build.dir}"/>
|
||||
<mkdir dir="${maven.docs.dest}"/>
|
||||
|
||||
<!-- Define a PMD task with the rulesets and all jars in the classpath -->
|
||||
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
||||
<!-- Define a PMD task with the rulesets and all jars in the
|
||||
classpath -->
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
|
||||
<classpath>
|
||||
<pathelement location="${plugin.getDependencyPath('pmd:pmd')}"/>
|
||||
<pathelement location="${plugin.getDependencyPath('jaxen:jaxen')}"/>
|
||||
<pathelement location="${plugin.getDependencyPath('saxpath:saxpath')}"/>
|
||||
</classpath>
|
||||
</taskdef>
|
||||
|
||||
<!-- Run the PMD task - need a way to define the rulesets dynamically -->
|
||||
|
||||
<echo>Running the PMD task with ${maven.pmd.rulesetfiles} ...</echo>
|
||||
|
||||
<pmd rulesetfiles="${maven.pmd.rulesetfiles}">
|
||||
@ -51,12 +84,12 @@
|
||||
|
||||
<!-- Run DVSL to transform the report into XDOC -->
|
||||
|
||||
<echo>Converting the PMD report to XDOC ...</echo>
|
||||
<echo>Converting the PMD report to xdoc ...</echo>
|
||||
|
||||
<doc:jsl
|
||||
input="${maven.build.dir}/pmd-raw-report.xml"
|
||||
output="pmd-report.xml"
|
||||
stylesheet="${plugin.dir}/pmd.jsl"
|
||||
stylesheet="${plugin.resources}/pmd.jsl"
|
||||
omitXmlDeclaration="true"
|
||||
outputMode="xml"
|
||||
prettyPrint="true"
|
||||
|
||||
@ -11,4 +11,4 @@ maven.pmd.enable = true
|
||||
# comma seperated list of rules to use
|
||||
# rulesets/experimental.xml is, well, experimental ... use at your own risk
|
||||
|
||||
maven.pmd.rulesetfiles=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
|
||||
maven.pmd.rulesetfiles=${plugin.resources}/rulesets/strings.xml,${plugin.resources}/rulesets/junit.xml,${plugin.resources}/rulesets/braces.xml,${plugin.resources}/rulesets/basic.xml,${plugin.resources}/rulesets/unusedcode.xml,${plugin.resources}/rulesets/design.xml,${plugin.resources}/rulesets/naming.xml,${plugin.resources}/rulesets/imports.xml,${plugin.resources}/rulesets/codesize.xml
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project>
|
||||
<extend>${basedir}/../project.xml</extend>
|
||||
@ -64,27 +64,18 @@
|
||||
<artifactId>pmd</artifactId>
|
||||
<version>1.04</version>
|
||||
<url>http://pmd.sourceforge.net</url>
|
||||
<properties>
|
||||
<classloader>root</classloader>
|
||||
</properties>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
<version>1.0-FCS-full</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>saxpath</groupId>
|
||||
<artifactId>saxpath</artifactId>
|
||||
<version>1.0-FCS</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}</directory>
|
||||
<includes>
|
||||
<include>plugin.jelly</include>
|
||||
<include>plugin.properties</include>
|
||||
<include>project.properties</include>
|
||||
<include>project.xml</include>
|
||||
<include>pmd.jsl</include>
|
||||
<include>rulesets/**</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
|
||||
@ -1,209 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Basic Rules">
|
||||
<description>
|
||||
The Basic Ruleset contains a collection of good practice rules
|
||||
which everyone should follow.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="EmptyCatchBlock"
|
||||
message="Avoid empty catch blocks"
|
||||
class="net.sourceforge.pmd.rules.EmptyCatchBlockRule">
|
||||
<description>
|
||||
Empty Catch Block finds instances where an exception is caught,
|
||||
but nothing is done. In most circumstances, this swallows an exception
|
||||
which should either be acted on or reported.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void doSomething() {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream("/tmp/bugger");
|
||||
} catch (IOException ioe) {
|
||||
// not good
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyIfStmt"
|
||||
message="Avoid empty 'if' statements"
|
||||
class="net.sourceforge.pmd.rules.EmptyIfStmtRule">
|
||||
<description>
|
||||
Empty If Statement finds instances where a condition is checked but nothing is done about it.
|
||||
</description>
|
||||
<example>
|
||||
<![CDATA[
|
||||
if (absValue < 1) {
|
||||
// not good
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyWhileStmt"
|
||||
message="Avoid empty 'while' statements"
|
||||
class="net.sourceforge.pmd.rules.EmptyWhileStmtRule">
|
||||
<description>
|
||||
Empty While Statement finds all instances where a while statement
|
||||
does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if
|
||||
it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
while (a == b) {
|
||||
// not good
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UnnecessaryConversionTemporaryRule"
|
||||
message="Avoid unnecessary temporaries when converting primitives to Strings"
|
||||
class="net.sourceforge.pmd.rules.UnnecessaryConversionTemporaryRule">
|
||||
<description>
|
||||
Avoid unnecessary temporaries when converting primitives to Strings
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public String convert(int x) {
|
||||
// this wastes an object
|
||||
String foo = new Integer(x).toString();
|
||||
// this is better
|
||||
return Integer.toString(x);
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
<rule name="EmptyTryBlock"
|
||||
message="Avoid empty try blocks"
|
||||
class="net.sourceforge.pmd.rules.EmptyTryBlockRule">
|
||||
<description>
|
||||
Avoid empty try blocks - what's the point?
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public void bar() {
|
||||
try {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyFinallyBlock"
|
||||
message="Avoid empty finally blocks"
|
||||
class="net.sourceforge.pmd.rules.EmptyFinallyBlockRule">
|
||||
<description>
|
||||
Avoid empty finally blocks - these can be deleted.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public void bar() {
|
||||
try {
|
||||
int x=2;
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptySwitchStatements"
|
||||
message="Avoid empty switch statements"
|
||||
class="net.sourceforge.pmd.rules.EmptySwitchStmtRule">
|
||||
<description>
|
||||
Avoid empty switch statements.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 2;
|
||||
switch (x) {
|
||||
// once there was code here
|
||||
// but it's been commented out or something
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="OverrideBothEqualsAndHashcodeRule"
|
||||
message="Ensure you override both equals() and hashCode()"
|
||||
class="net.sourceforge.pmd.rules.OverrideBothEqualsAndHashcodeRule">
|
||||
<description>
|
||||
Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public class Bar {
|
||||
public boolean equals(Object o) {
|
||||
// do some comparison
|
||||
}
|
||||
}
|
||||
|
||||
// and so is this
|
||||
public class Baz {
|
||||
public int hashCode() {
|
||||
// return some hash value
|
||||
}
|
||||
}
|
||||
|
||||
// this is OK
|
||||
public class Foo {
|
||||
public boolean equals(Object other) {
|
||||
// do some comparison
|
||||
}
|
||||
public int hashCode() {
|
||||
// return some hash value
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="JumbledIncrementer"
|
||||
message="Avoid using an outer loop incrementer in an inner loop for update expression"
|
||||
class="net.sourceforge.pmd.rules.JumbledIncrementerRule">
|
||||
<description>
|
||||
Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class JumbledIncrementerRule1 {
|
||||
public void foo() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int k = 0; k < 20; i++) {
|
||||
System.out.println("Hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
}}]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@ -1,92 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Braces Rules">
|
||||
<description>
|
||||
The Braces Ruleset contains a collection of braces rules.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="IfElseStmtsMustUseBracesRule"
|
||||
message="Avoid using 'if...else' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.IfElseStmtsMustUseBracesRule">
|
||||
<description>
|
||||
Avoid using if..else statements without using curly braces
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
||||
public void doSomething() {
|
||||
// this is OK
|
||||
if (foo) x++;
|
||||
|
||||
// but this is not
|
||||
if (foo)
|
||||
x=x+1;
|
||||
else
|
||||
x=x-1;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="WhileLoopsMustUseBracesRule"
|
||||
message="Avoid using 'while' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.WhileLoopsMustUseBracesRule">
|
||||
<description>
|
||||
Avoid using 'while' statements without using curly braces
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void doSomething() {
|
||||
while (true)
|
||||
x++;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ForLoopsMustUseBracesRule"
|
||||
message="Avoid using 'for' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.ForLoopsMustUseBracesRule">
|
||||
<description>
|
||||
Avoid using 'for' statements without using curly braces
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void foo() {
|
||||
for (int i=0; i<42;i++)
|
||||
foo();
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="IfStmtsMustUseBraces"
|
||||
message="Avoid using if statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.IfStmtsMustUseBracesRule">
|
||||
<description>
|
||||
Avoid using if statements without using curly braces
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 0;
|
||||
if (foo) x++;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@ -1,176 +0,0 @@
|
||||
<?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>
|
||||
|
||||
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Tom's Favorites">
|
||||
<description>
|
||||
The Favorites ruleset contains links to rules that I like to use. Usually I
|
||||
combine this ruleset with the unusedcode.xml, basic.xml, and import.xml rulesets for my projects.
|
||||
This ruleset also serves as an example of how to reference one ruleset from another.
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/braces.xml/WhileLoopsMustUseBracesRule"/>
|
||||
<rule ref="rulesets/braces.xml/ForLoopsMustUseBracesRule"/>
|
||||
<rule ref="rulesets/design.xml/UseSingletonRule"/>
|
||||
<rule ref="rulesets/design.xml/LooseCouplingRule"/>
|
||||
<rule ref="rulesets/design.xml/SimplifyBooleanReturnsRule"/>
|
||||
<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>
|
||||
<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>
|
||||
<rule ref="rulesets/strings.xml/StringToString"/>
|
||||
<rule ref="rulesets/strings.xml/StringInstantiation"/>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="JUnit Rules">
|
||||
<description>
|
||||
These rules deal with different problems that can occur with JUnit tests.
|
||||
</description>
|
||||
|
||||
<rule name="JUnitSpelling"
|
||||
message="You may have misspelled the JUnit framework ''{0}'' method as ''{1}''"
|
||||
class="net.sourceforge.pmd.rules.JUnitSpellingRule">
|
||||
<description>
|
||||
Some JUnit framework methods are easy to misspell.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import junit.framework.*;
|
||||
public class Foo extends TestCase {
|
||||
public void setup() {} // oops, should be setUp
|
||||
public void TearDown() {} // oops, should be tearDown
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="JUnitStaticSuite"
|
||||
message="You have a suite() method that is not both public and static, so JUnit won't call it to get your TestSuite. Is that what you wanted to do?"
|
||||
class="net.sourceforge.pmd.rules.JUnitStaticSuiteRule">
|
||||
<description>
|
||||
The suite() method in a JUnit test needs to be both public and static.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import junit.framework.*;
|
||||
public class Foo extends TestCase {
|
||||
public void suite() {} // oops, should be static
|
||||
private static void suite() {} // oops, should be public
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="newrules">
|
||||
<description>
|
||||
These are new rules for the next release
|
||||
</description>
|
||||
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
@ -1 +0,0 @@
|
||||
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
|
||||
357
pmd/src/plugin-resources/rulesets/basic.xml
Normal file
357
pmd/src/plugin-resources/rulesets/basic.xml
Normal file
@ -0,0 +1,357 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Basic Rules">
|
||||
<description>
|
||||
The Basic Ruleset contains a collection of good practices which everyone should follow.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="EmptyCatchBlock"
|
||||
message="Avoid empty catch blocks"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Empty Catch Block finds instances where an exception is caught,
|
||||
but nothing is done. In most circumstances, this swallows an exception
|
||||
which should either be acted on or reported.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TryStatement[@Catch='true']/Block[position() > 1]
|
||||
[count(*) = 0]
|
||||
[../@Finally='false' or following-sibling::Block]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void doSomething() {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream("/tmp/bugger");
|
||||
} catch (IOException ioe) {
|
||||
// not good
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyIfStmt"
|
||||
message="Avoid empty 'if' statements"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Empty If Statement finds instances where a condition is checked but nothing is done about it.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement/Statement/Block[count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
if (absValue < 1) {
|
||||
// not good
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="EmptyWhileStmt"
|
||||
message="Avoid empty 'while' statements"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Empty While Statement finds all instances where a while statement
|
||||
does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if
|
||||
it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//WhileStatement/Statement/Block[count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
while (a == b) {
|
||||
// not good
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="EmptyTryBlock"
|
||||
message="Avoid empty try blocks"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid empty try blocks - what's the point?
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TryStatement/Block[1][count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public void bar() {
|
||||
try {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyFinallyBlock"
|
||||
message="Avoid empty finally blocks"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid empty finally blocks - these can be deleted.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TryStatement[@Finally='true']/Block[position() = last()][count(*) = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public void bar() {
|
||||
try {
|
||||
int x=2;
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="EmptySwitchStatements"
|
||||
message="Avoid empty switch statements"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid empty switch statements.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//SwitchStatement[count(*) = 1]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 2;
|
||||
switch (x) {
|
||||
// once there was code here
|
||||
// but it's been commented out or something
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="JumbledIncrementer"
|
||||
message="Avoid using an outer loop incrementer in an inner loop for update expression"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForStatement[ForUpdate//Name/@Image = ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class JumbledIncrementerRule1 {
|
||||
public void foo() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int k = 0; k < 20; i++) {
|
||||
System.out.println("Hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
}}]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="ForLoopShouldBeWhileLoop"
|
||||
message="This for loop could be simplified to a while loop"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Some for loops can be simplified to while loops - this makes them more concise.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForStatement[count(*) > 1][not(ForInit)][not(ForUpdate)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
for (;true;) true; // No Init or Update part, may as well be: while (true)
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="UnnecessaryConversionTemporaryRule"
|
||||
message="Avoid unnecessary temporaries when converting primitives to Strings"
|
||||
class="net.sourceforge.pmd.rules.UnnecessaryConversionTemporaryRule">
|
||||
<description>
|
||||
Avoid unnecessary temporaries when converting primitives to Strings
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public String convert(int x) {
|
||||
// this wastes an object
|
||||
String foo = new Integer(x).toString();
|
||||
// this is better
|
||||
return Integer.toString(x);
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="OverrideBothEqualsAndHashcodeRule"
|
||||
message="Ensure you override both equals() and hashCode()"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassDeclaration//MethodDeclarator
|
||||
[
|
||||
(@Image = 'equals'
|
||||
and count(FormalParameters/*) = 1
|
||||
and not(//MethodDeclarator[count(FormalParameters/*) = 0][@Image = 'hashCode'])
|
||||
or
|
||||
(@Image='hashCode'
|
||||
and count(FormalParameters/*) = 0
|
||||
and not(//MethodDeclarator[count(FormalParameters//Type/Name[@Image = 'Object']) = 1][@Image = 'equals']))
|
||||
)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is bad
|
||||
public class Bar {
|
||||
public boolean equals(Object o) {
|
||||
// do some comparison
|
||||
}
|
||||
}
|
||||
|
||||
// and so is this
|
||||
public class Baz {
|
||||
public int hashCode() {
|
||||
// return some hash value
|
||||
}
|
||||
}
|
||||
|
||||
// this is OK
|
||||
public class Foo {
|
||||
public boolean equals(Object other) {
|
||||
// do some comparison
|
||||
}
|
||||
public int hashCode() {
|
||||
// return some hash value
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="DoubleCheckedLockingRule"
|
||||
message="Double checked locking is not thread safe in Java."
|
||||
class="net.sourceforge.pmd.rules.DoubleCheckedLockingRule">
|
||||
<description>
|
||||
Partially created objects can be returned by the Double Checked Locking pattern when used in Java.
|
||||
An optimizing JRE may assign a reference to the baz variable before it creates the object the
|
||||
reference is intended to point to. For more details see http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html.
|
||||
</description>
|
||||
<priority>1</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
Object baz;
|
||||
Object bar() {
|
||||
if(baz == null) { //baz may be non-null yet not fully created
|
||||
synchronized(this){
|
||||
if(baz == null){
|
||||
baz = new Object();
|
||||
}
|
||||
}
|
||||
}
|
||||
return baz;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
128
pmd/src/plugin-resources/rulesets/braces.xml
Normal file
128
pmd/src/plugin-resources/rulesets/braces.xml
Normal file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Braces Rules">
|
||||
<description>
|
||||
The Braces Ruleset contains a collection of braces rules.
|
||||
</description>
|
||||
|
||||
<rule name="IfStmtsMustUseBraces"
|
||||
message="Avoid using if statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using if statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[count(*) < 3][not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 0;
|
||||
if (foo) x++;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="WhileLoopsMustUseBracesRule"
|
||||
message="Avoid using 'while' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using 'while' statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//WhileStatement[not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void doSomething() {
|
||||
while (true)
|
||||
x++;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="IfElseStmtsMustUseBracesRule"
|
||||
message="Avoid using 'if...else' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using if..else statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[count(*) > 2][not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
||||
public void doSomething() {
|
||||
// this is OK
|
||||
if (foo) x++;
|
||||
|
||||
// but this is not
|
||||
if (foo)
|
||||
x=x+1;
|
||||
else
|
||||
x=x-1;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ForLoopsMustUseBracesRule"
|
||||
message="Avoid using 'for' statements without curly braces"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid using 'for' statements without using curly braces
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForStatement[not(Statement/Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public void foo() {
|
||||
for (int i=0; i<42;i++)
|
||||
foo();
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ topscore - The Maximum Number of reports to generate.
|
||||
At this time, only one can be used at a time.
|
||||
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="100"/>
|
||||
</properties>
|
||||
@ -64,6 +65,7 @@ topscore - The Maximum Number of reports to generate.
|
||||
At this time, only one can be used at a time.
|
||||
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="10"/>
|
||||
</properties>
|
||||
@ -99,6 +101,7 @@ topscore - The Maximum Number of reports to generate.
|
||||
At this time, only one can be used at a time.
|
||||
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="1000"/>
|
||||
</properties>
|
||||
@ -118,6 +121,116 @@ public class Foo {
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="CyclomaticComplexityRule"
|
||||
message = "The {0} ''{1}'' has a Cyclomatic Complexity of {2}."
|
||||
class="net.sourceforge.pmd.rules.CyclomaticComplexityRule">
|
||||
<description>
|
||||
Complexity is determined by the number of decision points in a method plus one for the
|
||||
method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Scale:
|
||||
1-4 (low complexity) 5-7 (moderate complexity) 8-10 (high complexity) 10+ (very high complexity)
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="reportLevel" value="10"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Cyclomatic Complexity = 12
|
||||
|
||||
public class Foo
|
||||
{
|
||||
1 public void example()
|
||||
{
|
||||
2 if (a == b)
|
||||
{
|
||||
3 if (a1 == b1)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
4 else if a2 == b2)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
else
|
||||
{
|
||||
do something;
|
||||
}
|
||||
}
|
||||
5 else if (c == d)
|
||||
{
|
||||
6 while (c == d)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
}
|
||||
7 else if (e == f)
|
||||
{
|
||||
8 for (int n = 0; n < h; n++)
|
||||
{
|
||||
do something;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (z)
|
||||
{
|
||||
9 case 1:
|
||||
do something;
|
||||
break;
|
||||
|
||||
10 case 2:
|
||||
do something;
|
||||
break;
|
||||
|
||||
11 case 3:
|
||||
do something;
|
||||
break;
|
||||
|
||||
12 default:
|
||||
do something;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ExcessivePublicCountRule"
|
||||
message="A high number of public methods and attributes in an object can indicate the class may need to be broken up for exhaustive testing may prove difficult."
|
||||
class="net.sourceforge.pmd.rules.ExcessivePublicCountRule">
|
||||
<description>
|
||||
A large amount of public methods and attributes declared in an object can indicate the class may need
|
||||
to be broken up as increased effort will be required to thoroughly test such a class.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="45"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
||||
public class Foo {
|
||||
public String value;
|
||||
public Bar something;
|
||||
public Variable var;
|
||||
//more public attributes
|
||||
public void doWork() {}
|
||||
public void doMoreWork() {}
|
||||
public void doWorkAgain() {}
|
||||
public void doWorking() {}
|
||||
public void doWorkIt() {}
|
||||
public void doWorkingAgain() {}
|
||||
public void doWorkAgainAgain() {}
|
||||
public void doWorked() {}
|
||||
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
169
pmd/src/plugin-resources/rulesets/controversial.xml
Normal file
169
pmd/src/plugin-resources/rulesets/controversial.xml
Normal file
@ -0,0 +1,169 @@
|
||||
<?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.XPathRule">
|
||||
<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>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ConstructorDeclaration[1][position() = last()][@Public='true'][not(FormalParameters/*)][not(BlockStatement)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<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.XPathRule">
|
||||
<description>
|
||||
Unused modifiers are, well, unused.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//InterfaceDeclaration//MethodDeclaration[@Public='true' or @Abstract = 'true']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public interface Foo {
|
||||
public abstract void bar(); // both abstract and public are ignored by the compiler
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AssignmentInOperandRule"
|
||||
message="Avoid assigments in operands"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid assigments in operands; this can make code more complicated and harder to read.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//*[name()='WhileStatement' or name()='IfStatement'][Expression//AssignmentOperator]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 2;
|
||||
if ((x = getX()) == 3) {
|
||||
System.out.println("3!");
|
||||
}
|
||||
}
|
||||
private int getX() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AtLeastOneConstructor"
|
||||
message="Each class should declare at least one constructor"
|
||||
class="net.sourceforge.pmd.rules.AtLeastOneConstructorRule">
|
||||
<description>
|
||||
Each class should declare at least one constructor. Note that this rule is the
|
||||
opposite of UnnecessaryConstructorRule, so running them at the same time will
|
||||
result on a rule violation on every class.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
// no constructor! not good!
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
71
pmd/src/plugin-resources/rulesets/coupling.xml
Normal file
71
pmd/src/plugin-resources/rulesets/coupling.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="coupling">
|
||||
<description>
|
||||
These are new rules for coupling
|
||||
</description>
|
||||
|
||||
<rule name="CouplingBetweenObjectsRule"
|
||||
message="High amount of different objects as memebers donotes a high coupling"
|
||||
class="net.sourceforge.pmd.rules.CouplingBetweenObjectsRule">
|
||||
<description>
|
||||
Rule counts unique attributes, local variables and return types within an object. An amount
|
||||
higher than specified threshold can indicate a high degree of couping with in an object
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="threshold" value="20"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
import com.Blah;
|
||||
import org.Bar;
|
||||
import org.Bardo;
|
||||
//
|
||||
public class Foo {
|
||||
private Blah var1;
|
||||
private Bar var2;
|
||||
//followed by many imports of unique objects
|
||||
|
||||
void ObjectC doWork() {
|
||||
Bardo var55;
|
||||
ObjectA var44;
|
||||
ObjectZ var93;
|
||||
return something;
|
||||
}
|
||||
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ExcessiveImportsRule"
|
||||
message="A high number of imports can indicate a high degree of coupling within an object."
|
||||
class="net.sourceforge.pmd.rules.ExcessiveImportsRule">
|
||||
<description>
|
||||
A high number of imports can indicate a high degree of coupling within
|
||||
an object. Rule counts the number of unique imports and reports a violation
|
||||
if the count is above the user defined threshold.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="30"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
import blah.blah.Bardo;
|
||||
import blah.blah.Hardo;
|
||||
import blah.blah.Bar;
|
||||
import blah.net.ObjectA;
|
||||
//imports over some threshold
|
||||
public class Foo {
|
||||
public void doWork() {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
303
pmd/src/plugin-resources/rulesets/design.xml
Normal file
303
pmd/src/plugin-resources/rulesets/design.xml
Normal file
@ -0,0 +1,303 @@
|
||||
<?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>
|
||||
<priority>3</priority>
|
||||
|
||||
<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>
|
||||
<priority>3</priority>
|
||||
|
||||
<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>
|
||||
<priority>3</priority>
|
||||
<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.XPathRule">
|
||||
<description>
|
||||
Switch statements should have a default label.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//SwitchStatement[not(SwitchLabel[count(*) = 0])]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
int x = 2;
|
||||
switch (x) {
|
||||
case 2: int j = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</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>
|
||||
<priority>3</priority>
|
||||
<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>
|
||||
<priority>2</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private void foo(String bar) {
|
||||
bar = "something else";
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="SwitchDensity"
|
||||
message="A high ratio of statements to labels in a switch statement. Consider refactoring."
|
||||
class="net.sourceforge.pmd.rules.design.SwitchDensityRule">
|
||||
<description>
|
||||
A high ratio of statements to labels in a switch statement implies that the switch
|
||||
statement is doing too much work. Consider moving the statements either into new
|
||||
methods, or creating subclasses based on the switch variable.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimum" value="10"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
private int x;
|
||||
public void bar() {
|
||||
switch (x) {
|
||||
case 1: {
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
System.out.println("I am a fish.");
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
System.out.println("I am a cow.");
|
||||
System.out.println("I am a cow.");
|
||||
System.out.println("I am a cow.");
|
||||
System.out.println("I am a cow.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ConstructorCallsOverridableMethodRule"
|
||||
message="Avoid calls to overridable methods during construction"
|
||||
class="net.sourceforge.pmd.rules.ConstructorCallsOverridableMethodRule">
|
||||
<description>
|
||||
Calling overridable methods during construction poses a risk of invoking methods on an
|
||||
incompletely constructed object. This situation can be difficult to discern.
|
||||
It may leave the sub-class unable to construct its superclass or forced to
|
||||
replicate the construction process completely within itself, losing the ability to call
|
||||
super(). If the default constructor contains a call to an overridable method,
|
||||
the subclass may be completely uninstantiable.
|
||||
</description>
|
||||
<priority>1</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class SeniorClass {
|
||||
public SeniorClass(){
|
||||
toString(); //may throw NullPointerException if overridden
|
||||
}
|
||||
public String toString(){
|
||||
return "IAmSeniorClass";
|
||||
}
|
||||
}
|
||||
public class JuniorClass extends SeniorClass {
|
||||
private String name;
|
||||
public JuniorClass(){
|
||||
super(); //Automatic call leads to NullPointerException
|
||||
name = "JuniorClass";
|
||||
}
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="AccessorClassGenerationRule"
|
||||
message="Avoid instantiation through private constructors from outside of the constructor's class."
|
||||
class="net.sourceforge.pmd.rules.AccessorClassGenerationRule">
|
||||
<description>
|
||||
Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor.
|
||||
A factory method, or non-privitization of the constructor can eliminate this situation.
|
||||
The generated class file is actually an interface. It gives the accessing class the ability to invoke a new hidden package
|
||||
scope constructor that takes the interface as a supplementary parameter. This turns a private constructor effectively into
|
||||
one with package scope, though not visible to the naked eye.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class OuterClass {
|
||||
void method(){
|
||||
InnerClass ic = new InnerClass();//Causes generation of accessor
|
||||
}
|
||||
public class InnerClass {
|
||||
private InnerClass(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OuterClass {
|
||||
void method(){
|
||||
InnerClass ic = new InnerClass();//OK, due to public constructor
|
||||
}
|
||||
public class InnerClass {
|
||||
public InnerClass(){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OuterClass {
|
||||
void method(){
|
||||
InnerClass ic = InnerClass.getInnerClass();//OK
|
||||
}
|
||||
public static class InnerClass {
|
||||
private InnerClass(){
|
||||
}
|
||||
private static InnerClass getInnerClass(){
|
||||
return new InnerClass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OuterClass {
|
||||
private OuterClass(){
|
||||
}
|
||||
public class InnerClass {
|
||||
void method(){
|
||||
OuterClass oc = new OuterClass();//Causes generation of accessor
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
24
pmd/src/plugin-resources/rulesets/favorites.xml
Normal file
24
pmd/src/plugin-resources/rulesets/favorites.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Favorites">
|
||||
<description>
|
||||
The Favorites ruleset contains links to rules that I like to use. Usually I
|
||||
combine this ruleset with the unusedcode.xml, basic.xml, and import.xml rulesets for my projects.
|
||||
This ruleset also serves as an example of do a custom ruleset.
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/braces.xml/WhileLoopsMustUseBracesRule"/>
|
||||
<rule ref="rulesets/braces.xml/ForLoopsMustUseBracesRule"/>
|
||||
<rule ref="rulesets/design.xml/LooseCouplingRule"/>
|
||||
<rule ref="rulesets/design.xml/SimplifyBooleanReturnsRule"/>
|
||||
<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>
|
||||
<rule ref="rulesets/strings.xml/StringToString"/>
|
||||
<rule ref="rulesets/strings.xml/StringInstantiation"/>
|
||||
<rule ref="rulesets/controversial.xml/UnnecessaryConstructorRule"/>
|
||||
<rule ref="rulesets/controversial.xml/NullAssignment"/>
|
||||
<rule ref="rulesets/controversial.xml/UnusedModifier"/>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ These rules deal with different problems that can occur with a class' import sta
|
||||
<description>
|
||||
Avoid duplicate import statements.
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -32,10 +33,23 @@ public class Foo {}
|
||||
|
||||
<rule name="DontImportJavaLang"
|
||||
message="Avoid importing anything from the package 'java.lang'"
|
||||
class="net.sourceforge.pmd.rules.DontImportJavaLangRule">
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ImportDeclaration
|
||||
[starts-with(Name/@Image, 'java.lang')]
|
||||
[not(starts-with(Name/@Image, 'java.lang.ref'))]
|
||||
[not(starts-with(Name/@Image, 'java.lang.reflect'))]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>4</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -59,6 +73,7 @@ public class Foo {}
|
||||
<description>
|
||||
Avoid unused import statements.
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -69,6 +84,22 @@ public class Foo {}
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ImportFromSamePackage"
|
||||
message="No need to import a type that's in the same package"
|
||||
class="net.sourceforge.pmd.rules.ImportFromSamePackageRule">
|
||||
<description>
|
||||
No need to import a type that's in the same package.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
package foo;
|
||||
import foo.Buz; // no need for this
|
||||
public class Bar{}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
92
pmd/src/plugin-resources/rulesets/junit.xml
Normal file
92
pmd/src/plugin-resources/rulesets/junit.xml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="JUnit Rules">
|
||||
<description>
|
||||
These rules deal with different problems that can occur with JUnit tests.
|
||||
</description>
|
||||
|
||||
<rule name="JUnitStaticSuite"
|
||||
message="You have a suite() method that is not both public and static, so JUnit won't call it to get your TestSuite. Is that what you wanted to do?"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
The suite() method in a JUnit test needs to be both public and static.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclaration[not(@Static='true') or not(@Public='true')][MethodDeclarator/@Image='suite']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import junit.framework.*;
|
||||
public class Foo extends TestCase {
|
||||
public void suite() {} // oops, should be static
|
||||
private static void suite() {} // oops, should be public
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="JUnitSpelling"
|
||||
message="You may have misspelled a JUnit framework method (setUp or tearDown)"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Some JUnit framework methods are easy to misspell.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclarator[(not(@Image = 'setUp') and translate(@Image, 'SETuP', 'setUp') = 'setUp') or (not(@Image = 'tearDown') and translate(@Image, 'TEARdOWN', 'tearDown') = 'tearDown')][FormalParameters[count(*) = 0]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import junit.framework.*;
|
||||
public class Foo extends TestCase {
|
||||
public void setup() {} // oops, should be setUp
|
||||
public void TearDown() {} // oops, should be tearDown
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="JUnitAssertionsShouldIncludeMessageRule"
|
||||
message="JUnit assertions should include a message"
|
||||
class="net.sourceforge.pmd.rules.junit.JUnitAssertionsShouldIncludeMessageRule">
|
||||
<description>
|
||||
JUnit assertions should include a message - i.e., use the three argument version of
|
||||
assertEquals(), not the two argument version.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo extends TestCase {
|
||||
public void testSomething() {
|
||||
assertEquals("foo", "bar");
|
||||
// not good! use the form:
|
||||
// assertEquals("Foo does not equals bar", "foo", "bar");
|
||||
// instead
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
||||
@ -7,14 +7,21 @@ The Naming Ruleset contains a collection of rules about names - too long, too sh
|
||||
|
||||
|
||||
<rule name="ShortVariable"
|
||||
message="Avoid variables with short names such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.ShortVariableRule">
|
||||
message="Avoid variables with short names"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Detects when a field, local or parameter has a short name.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="minimumLength" value="3"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//VariableDeclaratorId[string-length(@Image) < 3][not(ancestor::ForInit)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
@ -33,13 +40,20 @@ public class Something {
|
||||
</rule>
|
||||
|
||||
<rule name="LongVariable"
|
||||
message="Avoid excessively long variable names such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.LongVariableRule">
|
||||
message="Avoid excessively long variable names"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Detects when a field, formal or local variable is declared with a big name.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimumLength" value="12"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//VariableDeclaratorId[string-length(@Image) > 12]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -61,13 +75,20 @@ public class Something {
|
||||
</rule>
|
||||
|
||||
<rule name="ShortMethodNameRule"
|
||||
message="Avoid using short method names such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.ShortMethodNameRule">
|
||||
message="Avoid using short method names"
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Detects when very short method names are used.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="minimumLength" value="3"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclarator[string-length(@Image) < 3]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
31
pmd/src/plugin-resources/rulesets/newrules.xml
Normal file
31
pmd/src/plugin-resources/rulesets/newrules.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="newrules">
|
||||
<description>
|
||||
These are new rules for the next release
|
||||
</description>
|
||||
|
||||
|
||||
|
||||
<rule name="SymbolTableTestRule"
|
||||
message="test"
|
||||
class="net.sourceforge.pmd.rules.SymbolTableTestRule">
|
||||
<description>
|
||||
asdsad
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
// asdadas
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
||||
@ -8,10 +8,20 @@ These rules deal with different problems that can occur with String manipulation
|
||||
|
||||
<rule name="StringInstantiation"
|
||||
message="Avoid instantiating String objects; this is usually unnecessary."
|
||||
class="net.sourceforge.pmd.rules.StringInstantiationRule">
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
Avoid instantiating String objects; this is usually unnecessary.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//AllocationExpression[Name/@Image='String'][count(.//Expression) < 2][not(ArrayDimsAndInits)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>2</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -28,6 +38,7 @@ public class Foo {
|
||||
<description>
|
||||
Code containing duplicate String literals can usually be improved by declaring the String as a constant field.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="threshold" value="4"/>
|
||||
</properties>
|
||||
@ -52,6 +63,7 @@ public class Foo {
|
||||
<description>
|
||||
Avoid calling toString() on String objects; this is unnecessary
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -5,7 +5,6 @@
|
||||
The Unused Code Ruleset contains a collection of rules that find unused code.
|
||||
</description>
|
||||
|
||||
|
||||
<rule name="UnusedPrivateField"
|
||||
message="Avoid unused private fields such as ''{0}''"
|
||||
class="net.sourceforge.pmd.rules.UnusedPrivateFieldRule">
|
||||
@ -13,6 +12,7 @@ The Unused Code Ruleset contains a collection of rules that find unused code.
|
||||
Unused Private Field detects when a private field is declared
|
||||
that is not used by the class.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
@ -35,6 +35,7 @@ public class Something {
|
||||
Unused Local Variables detects when a variable is declared, but not
|
||||
used (except for possibly initial assignment)
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -56,6 +57,7 @@ public int doSomething() {
|
||||
<description>
|
||||
Unused Private Method detects when a private method is declared but is unused.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
@ -72,6 +74,7 @@ public class Something {
|
||||
<description>
|
||||
Avoid passing parameters to methods and then not using those parameters.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
@ -83,21 +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>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Foo {
|
||||
public Foo() {}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
@ -9,6 +9,12 @@
|
||||
<releases>
|
||||
|
||||
<release version="0.6" date="in CVS">
|
||||
<action dev="vmassol" type="update">
|
||||
Make the plugin work with Maven b9.
|
||||
</action>
|
||||
<action dev="vmassol" type="add">
|
||||
Added support for PMD 1.04.
|
||||
</action>
|
||||
<action dev="vmassol" type="update">
|
||||
Moved the PMD plugin from the
|
||||
<link href="http://sourceforge.net/projects/maven-plugins">Maven-Plugins SF project</link>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user