From 93d8dec0e5eb0fc6da292f6409a460aa0c9e86b6 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 29 Jul 2011 17:25:22 +0200 Subject: SONAR-75 rule search engine supports localized titles --- .../main/resources/org/sonar/plugins/pmd/rules.xml | 2977 ++++++++------------ 1 file changed, 1183 insertions(+), 1794 deletions(-) (limited to 'plugins/sonar-pmd-plugin') diff --git a/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml b/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml index b67167d0e91..7807310d803 100644 --- a/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml +++ b/plugins/sonar-pmd-plugin/src/main/resources/org/sonar/plugins/pmd/rules.xml @@ -1,2399 +1,1788 @@ - -MAJOR - + + MAJOR + rulesets/strictexception.xml/AvoidThrowingNewInstanceOfSameException - - - -public class Foo { - void bar() { - try { - // do something - } catch (SomeException se) { - // harmless comment - throw new SomeException(se); - } - } -} -]]> - - - -MAJOR - + + + + + + MAJOR + rulesets/android.xml/CallSuperFirst - - - -public class DummyActivity extends Activity { - public void onCreate(Bundle bundle) { - // missing call to super.onCreate(bundle) - foo(); - } -} -]]> - - - -MAJOR - + + + + + + MAJOR + rulesets/android.xml/CallSuperLast - - -public class DummyActivity extends Activity { - public void onPause() { - foo(); - // missing call to super.onPause() - } -} -]]> - - - -MAJOR - - rulesets/android.xml/ProtectLogD - - -public class DummyActivity extends Activity { - public void foo() { - Log.d("TAG", "msg1"); // Bad + + + + MAJOR + + rulesets/android.xml/ProtectLogD - bar(); - if (Config.LOGD) Log.d("TAG", "msg1"); // Good - } -} -]]> - -MAJOR - + + MAJOR + rulesets/android.xml/ProtectLogV - - - -public class DummyActivity extends Activity { - public void foo() { - Log.v("TAG", "msg1"); // Bad - bar(); - if (Config.LOGV) Log.v("TAG", "msg1"); // Good - } -} -]]> - - - - -MAJOR - - rulesets/basic.xml/EmptyInitializer - - - -public class Foo { + - static {} // Why ? - {} // Again, why ? + + + MAJOR -} -]]> - + rulesets/basic.xml/EmptyInitializer + - -MAJOR - + + MAJOR + rulesets/codesize.xml/CyclomaticComplexity - - - + + - + - - + - - + - -MAJOR - + + MAJOR + rulesets/strings.xml/AvoidStringBufferField - - - -class Foo { - private StringBuffer memoryLeak; -} -]]> - - - -MAJOR - + + + + + + MAJOR + - - -public class Foo -{ - public void bar() - { - try { - // Here do some stuff - } - catch( Exception e) { - // Handling the issue - } - finally - { - // is this really a good idea ? - throw new Exception(); - } - } -} - -]]> - - - -MAJOR - + + + + + + MAJOR + - - - + + - + - -MINOR - + + MINOR + - - -public class Example -{ - // Not a good idea... - public int []badBehavior() - { - // ... - return null; - } - - // Good behavior - public String[] bonnePratique() - { - //... - return new String[0]; - } -} - -]]> - - - -MINOR - + + + + + + MINOR + - - -// With a minimumNumberCaseForASwitch of 3 -public class Foo { - public void bar() { - switch (condition) { - case ONE: - instruction; - break; - default: - break; // not enough for a 'switch' stmt, - // a simple 'if' stmt would have been more appropriate - } - } -} - -]]> + + - + - -MAJOR - + + MAJOR + - - -public class abstract Example { - String field; - int otherField; -} - -]]> + - -CRITICAL - + + CRITICAL + - - - - public class GCCall -{ - public GCCall() - { - // Explicit gc call ! - System.gc(); - } - public void doSomething() - { - // Explicit gc call ! - Runtime.getRuntime().gc(); - } - - public explicitGCcall() { // Explicit gc call ! System.gc(); } - - public void doSomething() { // Explicit gc call ! Runtime.getRuntime().gc(); } -} -]]> - - - -MAJOR - + + + + + + MAJOR + - - - -// These are typo bugs, or at best needlessly complex and confusing: -int i = - -1; -int j = + - +1; -int z = ~~2; -boolean b = !!true; -boolean c = !!!true; - -// These are better: -int i = 1; -int j = -1; -int z = 2; -boolean b = true; -boolean c = false; - -// And these just make your brain hurt: -int i = ~-2; -int j = -~7; - ]]> - - - - -MAJOR - + + + + + + + MAJOR + - - - More details. Example : -
-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;
-  }
-}
-
]]>
-
- - -MAJOR - + + + + + + MAJOR + - - - -public class Foo { - void bar() { - // lots of complicated code - } - } - ]]> + + - + - -MINOR - + + MINOR + - - - -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; - } -} - - ]]> - - - -MAJOR - + + + + + + MAJOR + - - - -public class Bar { - // can be simplified to - // bar = isFoo(); - private boolean bar = (isFoo() == true); - - public isFoo() { return false;} -} - - ]]> - - - -MAJOR - + + + + + + MAJOR + - - - -public class Foo { - public void bar() { - int x = 2; - switch (x) { - case 2: int j = 8; - } - } -} - - ]]> - - - -MAJOR - + + + + + + MAJOR + - - - -public class Foo { - void bar(int a) { - switch (a) { - case 1: // do something - break; - default: // the default case should be last, by convention - break; - case 2: - break; - } - } -} - ]]> - - - - -MAJOR - + + + + + + + MAJOR + - - - -public class Foo { //Should be final - private Foo() { } -} - ]]> - - - -MAJOR - + + + + + + MAJOR + - - - -public class MyClass { - public void foo() { - final String finalLocalVariable; - } -} - ]]> - - - -MINOR - + + + + + + MINOR + - - - -public class Foo { - boolean bar() { - return (true); - } -} - ]]> - - - -CRITICAL - + + + + + + CRITICAL + - - - -// 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 - } -} -]]> - - - - -INFO - + + + + + + + INFO + - - - -// this is bad -import java.io.File; -public class Foo {} - ]]> - - - -MINOR - + + + + + + MINOR + - - - -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"; - } -} - ]]> - - - - -MAJOR - + + + + + + + MAJOR + - - - -public abstract class Foo { // should be AbstractFoo -} - ]]> - - - -MAJOR - + + + + + + MAJOR + - - - -// no package declaration -public class ClassInDefaultPackage { -} - ]]> + + - -MAJOR - + + MAJOR + - - - -package com.MyCompany; // <- should be lower case name -public class SomeClass { -} -]]> - - - -MAJOR - + + + + + + MAJOR + - - -public class Foo { -private Byte i = new Byte(0); // change to Byte i = -Byte.valueOf(0); -} -]]> + - -MAJOR - + + MAJOR + - - -public class Foo { -private Short i = new Short(0); // change to Short i = -Short.valueOf(0); -} - ]]> + - -MAJOR - + + MAJOR + - - -public class Foo { -private Long i = new Long(0); // change to Long i = -Long.valueOf(0); -} - ]]> - - -CRITICAL - - - - - -class Foo{ - public Object clone(){ - return new Foo(); // This is bad - } -} - ]]> + + CRITICAL + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - + + - -MINOR - + + MINOR + - - + + - -INFO - + + INFO + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MINOR - + + MINOR + - + - -MAJOR - + + MAJOR + - - - + + - -MINOR - + + MINOR + - - - + + - -MINOR - + + MINOR + - - + + - -MINOR - + + MINOR + - - + + - -MAJOR - + + MAJOR + - - + - -MAJOR - + + MAJOR + - - - + + - + - - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - + + - -MINOR - + + MINOR + - + - -MINOR - + + MINOR + - + - -MAJOR - + + MAJOR + - + - -MINOR - + + MINOR + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - + - -CRITICAL - + + CRITICAL + - - + + - -CRITICAL - + + CRITICAL + - - - + + - + - -CRITICAL - + + CRITICAL + - - + + - -CRITICAL - + + CRITICAL + - - - + + - -MAJOR - + + MAJOR + - - + + - -CRITICAL - + + CRITICAL + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - Example : -
-public class JumbledIncrementerRule1 {
-  public void foo() {
-   for (int i = 0; i < 10; i++) {
-    for (int k = 0; k < 20; i++) {
-     System.out.println("Hello");
-    }
-   }
-  }
-}
]]>
-
- -MINOR - + + + + + MINOR + - - + + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + + - -CRITICAL - + + CRITICAL + - - + + - -MINOR - + + MINOR + - - + + - -MAJOR - + + MAJOR + - - + + - -CRITICAL - + + CRITICAL + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - + - -INFO - + + INFO + - - + + - -MINOR - + + MINOR + - - + + - -MAJOR - + + MAJOR + - - + + - + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - + + - -CRITICAL - + + CRITICAL + - - - + + - -CRITICAL - + + CRITICAL + - - - Example : -
-if (object1!=null && object2.equals(object1)) { 
-  ...
-}      
-      
]]>
-
- -MAJOR - + + + + + MAJOR + - - - + + - -CRITICAL - + + CRITICAL + - - + + - -CRITICAL - + + CRITICAL + - - - + + - -MAJOR - + + MAJOR + - - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + - -MAJOR - + + MAJOR + - - + + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - Example : -
-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.toUpperCase();
-  }
-}
-
]]>
-
- -MAJOR - + + + + + MAJOR + - - - + + - -MINOR - + + MINOR + - + - -MAJOR - + + MAJOR + - - -Connection c = openConnection(); -try { - // do stuff, and maybe catch something -} finally { - c.close(); -} - -]]> + + - + - - + + - -MAJOR - + + MAJOR + - - - public class MyClass {
// this block gets run before any call to a constructor {
System.out.println("I am about to construct myself");
}
}
]]>
+ +
- -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + + - -CRITICAL - + + CRITICAL + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - Class c = new String().getClass(); with Class c = String.class;]]> + + - -MAJOR - + + MAJOR + - int x = 2;
x = x;
]]>
+
- -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -CRITICAL - + + CRITICAL + - - + + - -MAJOR - + + MAJOR + - - - + + - -MINOR - + + MINOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - - - -MAJOR - + + + + MAJOR + - -MAJOR - + + MAJOR + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - + + - -MINOR - + + MINOR + - - - + + - -CRITICAL - + + CRITICAL + - - + + - -CRITICAL - + + CRITICAL + - - - + + - -CRITICAL - + + CRITICAL + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - -public class Foo { - private void bar() { - buz("Howdy"); - buz("Howdy"); - buz("Howdy"); - buz("Howdy"); - } - private void buz(String x) {} -} -]]> + + - + - + - + - + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - + - -MINOR - + + MINOR + - + - -MINOR - + + MINOR + - - + - -MINOR - + + MINOR + - + - -MINOR - + + MINOR + - + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + - -MAJOR - + + MAJOR + - - + - -MINOR - + + MINOR + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - - + + - + - -MINOR - + + MINOR + - - + + - -MINOR - + + MINOR + - - + + - -MINOR - + + MINOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - + - -MAJOR - + + MAJOR + - - -public class ShortMethod { - public void a( int i ) { // Violation - } -} -]]> - - -MAJOR - + + + + + MAJOR + - - - + + - + - + - + - + - -MAJOR - + + MAJOR + rulesets/naming.xml/MethodNamingConventions - - - -public class Foo { - public void fooStuff() { - } -}]]> - - -MAJOR - + + + + + MAJOR + - - + + - -MINOR - + + MINOR + - - + + - -MAJOR - + + MAJOR + - - -public class MyClass { - // this is bad because it is a method - public void MyClass() {} - // this is OK because it is a constructor - public MyClass() {} -} -]]> - - -MAJOR - + + + + + MAJOR + - - -public class Foo { - public int hashcode() { - // oops, this probably was supposed to be hashCode - } -}]]> - - -MAJOR - + + + + + MAJOR + - - -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; -} -]]> - - -CRITICAL - + + + + + CRITICAL + - - - -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) - } -} -]]> - - -MAJOR - + + + + + MAJOR + - - - -public class Foo extends Bar { - // There's probably a better name for foo - int foo; -} -]]> - - -MAJOR - + + + + + MAJOR + - - - -public class Foo { - Object bar; - // bar is data or an action or both? - void bar() { - } -} -]]> - - -MAJOR - + + + + + MAJOR + - - -public class Foo { - private int m_foo; // OK - public void bar(String m_baz) { // Bad - int m_boz = 42; // Bad - } -} -]]> - - -MAJOR - + + + + + MAJOR + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - for (int i=0; i<42;i++) foo();]]> + + - -MAJOR - + + MAJOR + - - + + - + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - - -public abstract class ShouldBeAbstract -{ - public Object couldBeAbstract() - { - // Should be abstract method ? - return null; - } - - public void couldBeAbstract() - { - } -} -]]> - - -MAJOR - + + + + + MAJOR + - - - + + - + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - - + + - -MAJOR - + + MAJOR + - + - -MAJOR - + + MAJOR + - - + + - + - -MAJOR - + + MAJOR + - + MULTIPLE - - -public class a { - Factory f1; - - void myMethod() { - Factory f2; - int a; - } -} - - The following expression does the magic we need: -
-//VariableDeclarator
- [../Type/ReferenceType/ClassOrInterfaceType
-  [@Image = 'Factory'] and ..[@Final='false']]
-
- See the XPath rule tutorial for more information.]]> -
+ - + - - -
+ + +
\ No newline at end of file -- cgit v1.2.3