PMD-ATPCO-RuleSet_V7.xml 3

前端之家收集整理的这篇文章主要介绍了PMD-ATPCO-RuleSet_V7.xml 3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<rule class="net.sourceforge.pmd.rules.sunsecure.ArrayIsStoredDirectly" message="The user-supplied array ''{0}'' is stored directly" name="ArrayIsStoredDirectly">
<description>
Constructors and methods receiving arrays should clone objects and store the copy.
This prevents that future changes from the user affect the internal functionality.
</description>
<example><![CDATA[

public class Foo {
private String [] x;
public void foo (String [] param) {
// Don't do this,make a copy of the array at least
this.x=param;
}
}

]]></example>
<priority>3</priority> <!-- Priority 1 to 3. Changed by ATP3RXS -->
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.VariableNamingConventions" message="{0} variable {1} should begin with {2}" name="VariableNamingConventions">
<description>
A variable naming conventions rule - customize this to your liking. Currently,it
checks that final variables should be all caps and non-final variables
should not include underscores.
</description>
<example><![CDATA[

public class Foo {
public static final int MY_NUM = 0;
public String myTest = "";
DataModule dmTest = new DataModule();
}

]]></example>
<priority>1</priority>
<properties>
<property name="staticPrefix" value=""/>
<property name="staticSuffix" value=""/>
<property name="memberPrefix" value=""/>
<property name="memberSuffix" value=""/>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.MethodNamingConventions" message="Method name does not begin with a lower case character." name="MethodNamingConventions">
<description>
Method names should always begin with a lower case character,and should not contain underscores.
</description>
<example><![CDATA[

public class Foo {
public void fooStuff() {
}
}

]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.ClassNamingConventions" message="Class names should begin with an uppercase character" name="ClassNamingConventions">
<description>
Class names should always begin with an upper case character.
</description>
<example><![CDATA[

public class Foo {}

]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid using dollar signs in variable/method/class/interface names" name="AvoidDollarSigns">
<description>
Avoid using dollar signs in variable/method/class/interface names.
</description>
<example><![CDATA[

public class Fo$o { // yikes!
}

]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//ClassOrInterfaceDeclaration[contains(@Image,'$')]
|
//VariableDeclaratorId[contains(@Image,'$')]
|
//MethodDeclarator[contains(@Image,'$')]

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="The field name indicates a constant but its modifiers do not" name="SuspicIoUsConstantFieldName">
<description>&#xd;
A field name is all in uppercase characters,which in Sun's Java naming&#xd;
conventions indicate a constant. However,the field is not final.&#xd;
</description>
<example><![CDATA[

public class Foo {
// this is bad,since someone could accidentally
// do PI = 2.71828; which is actualy e
// final double PI = 3.16; is ok
double PI = 3.16;
}

]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//ClassOrInterfaceDeclaration[@Interface='false']
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
[@Final='false']
[VariableDeclarator/VariableDeclaratorId[upper-case(@Image)=@Image]]

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="The method name and parameter number are suspicIoUsly close to equals(Object)" name="SuspicIoUsEqualsMethodName">
<description>
The method name and parameter number are suspicIoUsly close to
equals(Object),which may mean you are intending to override the equals(Object)
method.
</description>
<example><![CDATA[

public class Foo {
public int equals(Object o) {
// oops,this probably was supposed to be boolean equals
}
public boolean equals(String s) {
// oops,this probably was supposed to be equals(Object)
}
}

]]></example>
<priority>2</priority> <!-- Priority 1 to 2. Changed by ATP3RXS -->
<properties>
<property name="xpath">
<value><![CDATA[

//MethodDeclarator [
(
@Image = 'equals'
and count(FormalParameters/*) = 1
and not (FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
[@Image = 'Object' or @Image = 'java.lang.Object'])
)
or
@Image='equal'
and count(FormalParameters/*) = 1
and (FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
[@Image = 'Object' or @Image = 'java.lang.Object'])

]

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.AvoidFieldNameMatchingTypeName" message="It is somewhat confusing to have a field name matching the declaring class name" name="AvoidFieldNameMatchingTypeName">
<description>
It is somewhat confusing to have a field name matching the declaring class name.
This proabably means that type and or field names could be more precise.
</description>
<example><![CDATA[

public class Foo extends Bar {
// There's probably a better name for foo
int foo;
}

]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.AvoidFieldNameMatchingMethodName" message="It is somewhat confusing to have a field name with the same name as a method" name="AvoidFieldNameMatchingMethodName">
<description>
It is somewhat confusing to have a field name with the same name as a method.
While this is totally legal,having information (field) and actions (method) is
not clear naming.
</description>
<example><![CDATA[

public class Foo {
Object bar;
// bar is data or an action or both?
void bar() {
}
}

]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.AvoidNonConstructorMethodsWithClassName" message="Method {0} is not a constructor but it can be confused with one" name="AvoidNonConstructorMethodsWithClassName">
<description>
It is very easy to confuse methods with classname with constructors. It is preferrable
to name these non-constructor methods in a different way.
</description>
<example><![CDATA[

public class Foo {
public void Foo() {
// not a constructor,just a poorly named method
}
}

]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Package name contains upper case characters" name="PackageCase">
<description>&#xd;
Detects when a package definition contains upper case characters.&#xd;
</description>
<example><![CDATA[

package com.MyCompany; // <- should be lower case name
public class SomeClass {
}

]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//PackageDeclaration/Name[lower-case(@Image)!=@Image]

]]></value>
</property>
<property name="pluginname" value="true"/>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.optimization.LocalVariableCouldBeFinal" message="Local variable could be declared final" name="LocalVariableCouldBeFinal">
<description>
A local variable assigned only once can be declared final.
</description>
<example><![CDATA[

public class Bar {
public void foo () {
String a = "a"; //if a will not be assigned again it is better to do this:
final String b = "b";
}
}

]]></example>
<priority>3</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.optimization.MethodArgumentCouldBeFinal" message="Parameter ''{0}'' is not assigned and could be declared final" name="MethodArgumentCouldBeFinal">
<description>
A method argument that is never assigned can be declared final.
</description>
<example><![CDATA[

public void foo (String param) {
// do stuff with param never assigning it
// better: public void foo (final String param) {
}

]]></example>
<priority>3</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.optimization.AvoidInstantiatingObjectsInLoops" message="Avoid instantiating new objects inside loops" name="AvoidInstantiatingObjectsInLoops">
<description>
Detects when a new object is created inside a loop
</description>
<example><![CDATA[

public class Something {
public static void main( String as[] ) {
for (int i = 0; i < 10; i++) {
Foo f = new Foo(); //Avoid this whenever you can it's really expensive
}
}
}

]]></example>
<priority>2</priority> <!-- Priority 4 to 2. Changed by ATP3RXS -->
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Use ArrayList instead of Vector" name="UseArrayListInsteadOfVector">
<description>
ArrayList is a much better Collection implementation than Vector.
</description>
<example><![CDATA[

public class SimpleTest extends TestCase {
public void testX() {
Collection c = new Vector();
// This achieves the same with much better performance
// Collection c = new ArrayList();
}
}

]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//AllocationExpression
/ClassOrInterfaceType[@Image='Vector' or @Image='java.util.Vector']

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.ExcessiveImports" message="A high number of imports can indicate a high degree of coupling within an object." name="ExcessiveImports">
<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>
<example><![CDATA[

import blah.blah.Baz;
import blah.blah.Bif;
// 18 others from the same package elided
public class Foo {
public void doWork() {}
}

]]></example>
<priority>5</priority> <!-- Priority 4 to 5. Changed by ATP3RXS -->
<properties>
<property name="minimum" value="30"/>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.design.LooseCoupling" message="Avoid using implementation types like ''{0}''; use the interface instead" name="LooseCoupling">
<description>
Avoid using implementation types (i.e.,HashSet); use the interface (i.e,Set) instead
</description>
<example><![CDATA[

import java.util.*;
public class Bar {
// Use List instead
private ArrayList list = new ArrayList();
// Use Set instead
public HashSet getFoo() {
return new HashSet();
}
}

]]></example>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty catch blocks" name="EmptyCatchBlock">
<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>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//CatchStatement
[count(Block/BlockStatement) = 0 and ($allowCommentedBlocks != 'true' or Block/@containsComment = 'false')]
[FormalParameter/Type/ReferenceType
/ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException']
]

]]></value>
</property>
<property name="allowCommentedBlocks" value="false"/>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid empty 'if' statements" name="EmptyIfStmt">
<description>
Empty If Statement finds instances where a condition is checked but nothing is done about it.
</description>
<example><![CDATA[

public class Foo {
void bar(int x) {
if (x == 0) {
// empty!
}
}
}

]]></example>
<priority>2</priority> <!-- Priority 1 to 2. Changed by ATP3RXS -->
<properties>
<property name="xpath">
<value><![CDATA[

//IfStatement/Statement
[EmptyStatement or Block[count(*) = 0]]

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.UnnecessaryConversionTemporary" message="Avoid unnecessary temporaries when converting primitives to Strings" name="UnnecessaryConversionTemporary">
<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>
<priority>1</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Ensure you override both equals() and hashCode()" name="OverrideBothEqualsAndHashcode">
<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>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//ClassOrInterfaceDeclaration
[@Interface='false']
[not (ImplementsList/ClassOrInterfaceType[@Image='Comparable'])]
//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/ReferenceType/ClassOrInterfaceType
[@Image = 'Object' or @Image = 'java.lang.Object']) = 1]
[@Image = 'equals']))]

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid returning from a finally block" name="ReturnFromFinallyBlock">
<description>
Avoid returning from a finally block - this can discard exceptions.
</description>
<example><![CDATA[

public class Bar {
public String foo() {
try {
throw new Exception( "My Exception" );
} catch (Exception e) {
throw e;
} finally {
return "A. O. K."; // Very bad.
}
}
}

]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//FinallyStatement//ReturnStatement

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Unnecessary final modifier in final class" name="UnnecessaryFinalModifier">
<description>
When a class has the final modifier,all the methods are automatically final.
</description>
<example><![CDATA[

public final class Foo {
// This final modifier is not necessary,since the class is final
// and thus,all methods are final
private final void foo() {
}
}


]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//ClassOrInterfaceDeclaration[@Final='true' and @Interface='false']
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/MethodDeclaration[@Final='true']

]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="These nested if statements could be combined" name="CollapsibleIfStatements">
<description>
Sometimes two 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
</description>
<example><![CDATA[

public class Foo {
void bar() {
if (x) {
if (y) {
// do stuff
}
}
}
}

]]></example>
<priority>4</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//IfStatement[@Else='false']/Statement
/IfStatement[@Else='false']
|
//IfStatement[@Else='false']/Statement
/Block[count(BlockStatement)=1]/BlockStatement
/Statement/IfStatement[@Else='false']
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.UnusedModifier" message="Avoid modifiers which are implied by the context" name="UnusedModifier">
<description>
Fields in interfaces are automatically public static final,and
methods are public abstract.
Classes or interfaces nested in an interface are automatically public
and static (all nested interfaces are automatically static).
For historical reasons,modifiers which are implied by the context
are accepted by the compiler,but are superfluous.
</description>
<example><![CDATA[

public interface Foo {
public abstract void bar(); // both abstract and public are ignored by the compiler
public static final int X = 0; // public,static,and final all ignored
public static class Bar {} // public,static ignored
public static interface Baz {} // ditto
}
public class Bar {
public static interface Baz {} // static ignored
}

]]></example>
<priority>8</priority>
<properties/>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Avoid importing anything from the 'sun.*' packages" name="DontImportSun">
<description>
Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
</description>
<example><![CDATA[

import sun.misc.foo;
public class Foo {}

]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//ImportDeclaration
[starts-with(Name/@Image,'sun.')]
[not(starts-with(Name/@Image,'sun.misc.Signal'))]


]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="This statement may have some unnecessary parentheses" name="UnnecessaryParentheses">
<description>&#xd;
Sometimes expressions are wrapped in unnecessary parentheses,&#xd;
making them look like a function call.&#xd;
</description>
<example><![CDATA[
public class Foo {
boolean bar() {
return (true);
}
}
]]></example>
<priority>5</priority>
<properties>
<property name="xpath">
<value><![CDATA[

//ReturnStatement
/Expression
/PrimaryExpression
/PrimaryPrefix
/Expression[count(*)=1]
/PrimaryExpression
/PrimaryPrefix
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="Use explicit scoping instead of the default package private level" name="DefaultPackage">
<description>
Use explicit scoping instead of the default package private level
</description>
<example><![CDATA[]]></example>
<priority>1</priority> <!-- Priority 4 to 1. Changed by ATP1AXR -->
<properties>
<property name="xpath">
<value><![CDATA[
//ClassOrInterfaceDeclaration[@Interface='false']
/ClassOrInterfaceBody
/ClassOrInterfaceBodyDeclaration
/FieldDeclaration[@PackagePrivate='true']
| /MethodDeclaration[@PackagePrivate='true']
]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="enter 'trace' log message after method starts and befor ends" name="TraceLogWithinMethod">
<description>The entry “trace” log message will be as close to the first line in the method as possible (only variable declarations used in the log call are allowed before)&#xd;
&#xd;
The exit “trace” log message will be as close to the end of the method as possible. The last line in functions that return void or immediately preceding the return statement for methods returning a value.&#xd;
</description>
<example><![CDATA[public void method_m(){

log.info("method starts here");
//do somthing
log.info("method ends");
}]]></example>
<priority>3</priority> <!-- Priority 3 to 1. Changed by ATP1AXR -->
<properties>
<property name="xpath">
<value><![CDATA[//PrimaryExpression[PrimaryPrefix/Name[ends-with(@Image,'.debug')]or PrimaryPrefix/Name[ends-with(@Image,'.info')]or PrimaryPrefix/Name[ends-with(@Image,'.warn')]or PrimaryPrefix/Name[ends-with(@Image,'.error')]or PrimaryPrefix/Name[ends-with(@Image,'.fatal')]]]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="all the letters of the constant are not capital" name="ConstantNaming">
<description>Constant name (variables declared as final) should be in all capital letters.</description>
<example><![CDATA[public static final String CONSTANT_NAME = null;]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[//ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration[@Final='true'][@Static='true'][VariableDeclarator/VariableDeclaratorId[upper-case(@Image)!=@Image][@Image!="serialVersionUID"]] ]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="there is no scope is defined for the variale" name="VariableDefinition">
<description>Variables are defined in the proper scope (as restrictive as possible)</description>
<example><![CDATA[private int i=0;
public String name=null;
protected String str_name ="";]]></example>
<priority>1</priority>
<properties>
<property name="xpath">
<value><![CDATA[//FieldDeclaration[@Private ="false" and @Public ="false" and @Protected="false"]]]></value>
</property>
</properties>
</rule>
<rule class="net.sourceforge.pmd.rules.XPathRule" message="variable has not been initialized" name="VariableInitialization">
<description>Variables should be initialized when they are declared unless the initial value is dependent on a computation occurring first</description>
<example><![CDATA[public class foo{

public int i=0;

public void method_name(){

String str_name = null;

}}}]]></example> <priority>3</priority> <properties> <property name="xpath"> <value><![CDATA[//ClassOrInterfaceDeclaration[@Interface='false']/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration/VariableDeclarator[count( .//.//.//VariableInitializer[@Image!='false'] )=0 ]]]></value> </property> </properties> </rule>

原文链接:https://www.f2er.com/xml/297874.html

猜你在找的XML相关文章