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 --- .../org/sonar/plugins/checkstyle/rules.xml | 1312 ++++++++------------ 1 file changed, 522 insertions(+), 790 deletions(-) (limited to 'plugins/sonar-checkstyle-plugin') diff --git a/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml b/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml index 5f7494d662d..4f9030f57f5 100644 --- a/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml +++ b/plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml @@ -1,4 +1,4 @@ - + @@ -15,1689 +15,1429 @@ - -MAJOR + + MAJOR - Checks the header of a source file against a header that contains a regular expression for each line of the source header.

-

Rationale: In some projects checking against a fixed header is not sufficient, e.g. the header might require a copyright line where the year information is not static. For example, consider the following header:

-
-	line  1: ^/{71}$
-	line  2: ^// checkstyle:$
-	line  3: ^// Checks Java source code for adherence to a set of rules\.$
-	line  4: ^// Copyright \(C\) \d\d\d\d  Oliver Burn$
-	line  5: ^// Last modification by \$Author.*\$$
-	line  6: ^/{71}$
-	line  7:
-	line  8: ^package
-	line  9:
-	line 10: ^import
-	line 11:
-	line 12: ^/\*\*
-	line 13: ^ \*([^/]|$)
-	line 14: ^ \*/
-
-

Lines 1 and 6 demonstrate a more compact notation for 71 '/' characters. Line 4 enforces that the copyright notice includes a four digit year. Line 5 is an example how to enforce revision control keywords in a file header. Lines 12-14 is a template for javadoc (line 13 is so complicated to remove conflict with and of javadoc comment).

-

Different programming languages have different comment syntax rules, but all of them start a comment with a non-word character. Hence you can often use the non-word character class to abstract away the concrete comment syntax and allow checking the header for different languages with a single header definition. For example, consider the following header specification (note that this is not the full Apache license header):

-
-	line 1: ^#!
-	line 2: ^<\?xml.*>$
-	line 3: ^\W*$
-	line 4: ^\W*Copyright 2006 The Apache Software Foundation or its licensors, as applicable\.$
-	line 5: ^\W*Licensed under the Apache License, Version 2\.0 \(the "License"\);$
-	line 6: ^\W*$
-
-

Lines 1 and 2 leave room for technical header lines, e.g. the "#!/bin/sh" line in Unix shell scripts, or the xml file header of XML files. Set the multiline property to "1, 2" so these lines can be ignored for file types where they do no apply. Lines 3 through 6 define the actual header content. Note how lines 2, 4 and 5 use escapes for characters that have special regexp semantics.

]]>
+ - + - +
- -MAJOR + + MAJOR - + - + - + - + - -MAJOR + + MAJOR - - + - -MAJOR + + MAJOR - - + - - + -MINOR + MINOR - This check makes sure that all package annotations are in the package-info.java file.

-

According to the Java JLS 3rd ed.

-

The JLS does not enforce the placement of package annotations. This placement may vary based on implementation. The JLS does highly recommend that all package annotations are placed in the package-info.java file. See Java Language specification, sections 7.4.1.1.

]]>
+
- -MAJOR + + MAJOR - - This check allows you to specify what warnings that SuppressWarnings is not allowed to suppress. You can also specify a list of TokenTypes that the configured warning(s) cannot be suppressed on.

-

Limitations: This check does not consider conditionals inside the SuppressWarnings annotation. -For example: @SupressWarnings((false) ? (true) ? "unchecked" : "foo" : "unused") According to the above example, the "unused" warning is being suppressed not the "unchecked" or "foo" warnings. All of these warnings will be considered and matched against regardless of what the conditional evaluates to.

]]>
+ - - + - - +
- -MAJOR + + MAJOR - - Checks that any combination of String literals with optional assignment is on the left side of an equals() comparison.

-

Rationale: Calling the equals() method on String literals will avoid a potential NullPointerException. Also, it is pretty common to see null check right before equals comparisons which is not necessary in the below example.

-

For example: -

-  String nullString = null;
-  nullString.equals("My_Sweet_String");
-
-

- -

-should be refactored to: -

-  String nullString = null;
-  "My_Sweet_String".equals(nullString);
-
-

-

Limitations: If the equals method is overridden or a covariant equals method is defined and the implementation is incorrect (where s.equals(t) does not return the same result as t.equals(s)) then rearranging the called on object and parameter may have unexpected results.

-

Java's Autoboxing feature has an affect on how this check is implemented. Pre Java 5 all IDENT + IDENT object concatenations would not cause a NullPointerException even if null. Those situations could have been included in this check. They would simply act as if they surrounded by String.valueof() which would concatenate the String null.

-

The following example will cause a NullPointerException as a result of what autoboxing does.

-
-  Integer i = null, j = null;
-  String number = "5"
-  number.equals(i + j);
-
-

Since, it is difficult to determine what kind of Object is being concatenated all ident concatenation is considered unsafe.

]]>
-
- - - -MAJOR + + + + + + MAJOR - Checks that the clone method is not overridden from the Object class.

- -

Rationale: The clone method relies on strange/hard to follow rules that do not work it all situations. Consequently, it is difficult to override correctly. Below are some of the rules/reasons why the clone method should be avoided. -

    -
  • Classes supporting the clone method should implement the Cloneable interface but the Cloneable interface does not include the clone method. As a result, it doesn't enforce the method override.
  • -
  • The Cloneable interface forces the Object's clone method to work correctly. Without implementing it, the Object's clone method will throw a CloneNotSupportedException.
  • -
  • Non-final classes must return the object returned from a call to super.clone().
  • -
  • Final classes can use a constructor to create a clone which is different from non-final classes.
  • -
  • If a super class implements the clone method incorrectly all subclasses calling super.clone() are doomed to failure.
  • -
  • If a class has references to mutable objects then those object references must be replaced with copies in the clone method after calling super.clone().
  • -
  • The clone method does not work correctly with final mutable object references because final references cannot be reassigned.
  • -
  • If a super class overrides the clone method then all subclasses must provide a correct clone implementation.
  • -

-

Two alternatives to the clone method, in some cases, is a copy constructor or a static factory method to return copies of an object. Both of these approaches are simpler and do not conflict with final fields. The do not force the calling client to handle a CloneNotSuportException. They also are typed therefore no casting is necessary. Finally, they are more flexible since they can take interface types rather than concrete classes.

- -

Sometimes a copy constructor or static factory is not an acceptable alternative to the clone method. The example below highlights the limitation of a copy constructor (or static factory). Assume Square is a subclass for Shape.

-

-

-  Shape s1 = new Square();
-  System.out.println(s1 instanceof Square); //true
-

-

...assume at this point the code knows nothing of s1 being a Square that's the beauty of polymorphism but the code wants to copy the Square which is declared as a Shape, its super type...

-

-

-  Shape s2 = new Shape(s1); //using the copy constructor
-  System.out.println(s2 instanceof Square); //false
-

- -

The working solution (without knowing about all subclasses and doing many casts) is to do the following (assuming correct clone implementation).
-

-  Shape s2 = s1.clone();
-  System.out.println(s2 instanceof Square); //true
-

- -

Just keep in mind if this type of polymorphic cloning is required then a properly implemented clone method may be the best choice.

- -

Much of this information was taken from Effective Java: Programming Language Guide First Edition by Joshua Bloch pages 45-52. Give Bloch credit for writing an excellent book.

- -

This check is almost exactly the same as the "No Finalizer Check".

]]>
-
- - - -MAJOR + + + + + + MAJOR - Verifies there are no finalize() methods defined in a class.

]]>
+
-MINOR + MINOR - Checks that there are no static import statements. Rationale: Importing static members can lead to naming conflicts between class' members. It may lead to poor code readability since it may no longer be clear what class a member resides in (without looking at the import statement).

]]>
+ - - +
-MINOR + MINOR - Checks that each Java package has a Javadoc file used for commenting. By default it only allows a package-info.java file, but can be configured to allow a package.html file. An error will be reported if both files exist as this is not allowed by the Javadoc tool.

]]>
+ - - +
- -MAJOR + + MAJOR MULTIPLE - A check for detecting that matches across multiple lines. Rationale: This check can be used to when the regular expression can be span multiple lines.

]]>
+ - + - + - + - + - +
- -MAJOR + + MAJOR - A check for detecting single lines that match a supplied regular expression. Works with any file type. Rationale: This check can be used to prototype checks and to find common bad practice such as calling ex.printStacktrace(), System.out.println(), System.exit(), etc.

]]>
+ MULTIPLE - + - + - + - + - +
- -MAJOR + + MAJOR - This class is variation on RegexpSingleline for detecting single lines that match a supplied regular expression in Java files. It supports suppressing matches in Java comments.

]]>
+ MULTIPLE - + - + - + - + - + - +
-MINOR + MINOR - Checks for the number of types declared at the outer (or root) level in a file. Rationale: It is considered good practice to only define one outer type per file.

]]>
+ - +
-MINOR + MINOR - Checks that there are no tab characters ('\t') in the source code. Rationale: -
    -
  • Developers should not need to configure the tab width of their text editors in order to be able to read source code.
  • -
  • From the Apache jakarta coding standards: In a distributed development environment, when the commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.
  • -

]]>
+ - +
-MINOR + MINOR - Checks that the whitespace around the Generic tokens < and > is correct to the typical convention. The convention is not configurable.

-

-For example the following is legal: -

-
-  List x = new ArrayList();
-  List> y = new ArrayList>();
-
-

-But the following example is not: -

-
-  List < Integer > x = new ArrayList < Integer > ();
-  List < List < Integer > > y = new ArrayList < List < Integer > > ();
-
]]>
+
- -MAJOR + + MAJOR - -Rationale: Too large methods and classes are hard to read and costly to maintain. A large NCSS number often means that a method or class has too many responsabilities and/or functionalities which should be decomposed into smaller units.]]> + - - + - - + - - + -MINOR + MINOR - -
  • It is a duplicate of another import. This is, when a class is imported more than once.
  • -
  • The class imported is from the java.lang package, e.g. importing java.lang.String.
  • -
  • The class imported is from the same package.
  • -]]>
    +
    - -MAJOR + + MAJOR - - + ^Abstract.*$|^.*Factory$ - -MAJOR + + MAJOR - + - + - -MAJOR + + MAJOR - + -MINOR + MINOR - - + - - + -MINOR + MINOR - + - -MAJOR + + MAJOR - + - + -MINOR + MINOR - + - - + - -MAJOR + + MAJOR - - + - - + - + - -MAJOR + + MAJOR - - + - + - -MAJOR + + MAJOR - + - + -MINOR + MINOR MULTIPLE - - + ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$ - Controls whether to apply the check to public member + true - Controls whether to apply the check to protected member + true - Controls whether to apply the check to package-private member true - Controls whether to apply the check to private member + true -CRITICAL + CRITICAL - - + - -MAJOR + + MAJOR - - + - + -INFO + INFO - -
  • Class (static) variables. First the public class variables, then the protected, then package level (no access modifier), and then the private.
  • Instance variables. First the public class variables, then the protected, then package level (no access modifier), and then the private.
  • Constructors
  • Methods
  • ]]>
    +
    - -MAJOR + + MAJOR - + -MINOR + MINOR - + - -MAJOR + + MAJOR - - + - -MAJOR + + MAJOR - + - + - + -MINOR + MINOR - - for ( ; i < j; i++, j--)]]> + - + -MINOR + MINOR - - for (Iterator foo = very.long.line.iterator(); foo.hasNext(); )]]> + - + -MINOR + MINOR - + -CRITICAL + CRITICAL - + - -MAJOR + + MAJOR - - + - + - + - -MAJOR + + MAJOR - - + - -MAJOR + + MAJOR - - + - + - - + - -MAJOR + + MAJOR - Checks for long source files.

    -

    Rationale: If a source file becomes very long it is hard to understand. Therefore long classes should usually be refactored into several individual classes that focus on a specific task.

    ]]>
    + - +
    - -MAJOR + + MAJOR - + -MINOR + MINOR - - + - + -MINOR + MINOR - + - + - -MAJOR + + MAJOR - - + - + - + - + - - + - - + - -MAJOR + + MAJOR - - + - -MAJOR + + MAJOR - - + - + - -MAJOR + + MAJOR - + - + - -MAJOR + + MAJOR - - java.lang.Boolean class. In order to save memory and CPU cycles, it is preferable to use the predefined constants TRUE and FALSE. Constructor invocations should be replaced by calls to Boolean.valueOf(). Some extremely performance sensitive projects may require the use of factory methods for other classes as well, to enforce the usage of number caches or object pools.]]> + - + - -MAJOR + + MAJOR - - + - + - -MAJOR + + MAJOR - - + - + - -MAJOR + + MAJOR MULTIPLE - + - + - + - + - - + - -MAJOR + + MAJOR - - + - + - - + - + - + - + -MINOR + MINOR - -
  • groups imports: ensures that groups of imports come in a specific order (e.g., java. comes first, javax. comes second, then everything else)
  • -
  • adds a separation between groups : ensures that a blank line sit between each group
  • -
  • sorts imports inside each group: ensures that imports within each group are in lexicographic order
  • -
  • sorts according to case: ensures that the comparison between imports is case sensitive
  • -
  • groups static imports: ensures the relative order between regular imports and static imports
  • - -]]>
    + - - + - + - + - - + - - +
    -MINOR + MINOR - + - + 4 - + 0 - + 4 - + 8 - -MAJOR + + MAJOR - - + - + - -MAJOR + + MAJOR - - + - - + - -MAJOR + + MAJOR -
    Error messages about parameters and type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags. - Error messages about exceptions which are declared to be thrown, but for which no throws tag is present can be suppressed by defining property allowMissingThrowsTags. - Error messages about methods which return non-void but for which no return tag is present can be suppressed by defining property allowMissingReturnTag. -

    Javadoc is not required on a method that is tagged with the @Override annotation. - However under Java 5 it is not possible to mark a method required for an interface (this was corrected under Java 6). - Hence Checkstyle supports using the convention of using a single {@inheritDoc} tag instead of all the other tags. - -

    Note that only inheritable items will allow the {@inheritDoc} tag to be used in place of comments. - Static methods at all visibilities, private non-static methods and constructors are not inheritable.]]>
    - + - + - - + - - + - - + - - + - - + - + - - public void setNumber(final int number) { mNumber = number; } public int getNumber() { return mNumber; } public boolean isSomething() { return false; } . Default is false.]]> + - +
    - -MAJOR + + MAJOR - -
  • Ensures the first sentence ends with proper punctuation (That is a period, question mark, or exclamation mark, by default). - Javadoc automatically places the first sentence in the method summary table and index. With out proper punctuation the Javadoc may be malformed. - All items eligible for the {@inheritDoc} tag are exempt from this requirement.
  • -
  • Check text for Javadoc statements that do not have any description. - This includes both completely empty Javadoc, and Javadoc with only tags such as @param and @return.
  • -
  • Check text for incomplete HTML tags. Verifies that HTML tags have corresponding end tags and issues an "Unclosed HTML tag found:" error if not. - An "Extra HTML tag found:" error is issued if an end tag is found without a previous open tag.
  • -
  • Check that a package Javadoc comment is well-formed (as described above) and NOT missing from any package-info.java files.
  • -
  • Check for allowed HTML tags. The list of allowed HTML tags is "a", "abbr", "acronym", "address", "area", "b", - "bdo", "big", "blockquote", "br", "caption", "cite", "code", "colgroup", "del", "div", "dfn", "dl", "em", "fieldset", - "h1" to "h6", "hr", "i", "img", "ins", "kbd", "li", "ol", "p", "pre", "q", "samp", "small", "span", "strong", - "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thread", "tr", "tt", "ul"
  • - ]]>
    + - + - + - - + - - + - + - +
    - -MAJOR + + MAJOR -
    Error messages about type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags.]]>
    + - + - + - + - + - - + - +
    - -MAJOR + + MAJOR - + - + - + -MINOR + MINOR - - eol and nlow take into account property maxLineLength.]]> + - - + - + - + - -MAJOR + + MAJOR - + - + - + - + - -MAJOR + + MAJOR - - + ^[a-z][a-zA-Z0-9]*$ - -MAJOR + + MAJOR MULTIPLE - - + ^[a-z][a-zA-Z0-9]*$ - - + -MINOR + MINOR - + - + - + - -MAJOR + + MAJOR MULTIPLE - - + ^[a-z][a-zA-Z0-9]*$ - Controls whether to apply the check to public member + true - Controls whether to apply the check to protected member + true - Controls whether to apply the check to package-private member + true - Controls whether to apply the check to private member + true - -MAJOR + + MAJOR - + - + - - + - + - -MAJOR + + MAJOR - - + ^[a-z][a-zA-Z0-9]*$ - Controls whether to allow a method name to have the same name as the residing class name. This is not to be confused with a constructor. An easy mistake is to place a return type on a constructor declaration which turns it into a method. + false - -MAJOR + + MAJOR - - + - - + - + - + - -MAJOR + + MAJOR - - + - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR - - + -MINOR + MINOR - - + - -MAJOR + + MAJOR MULTIPLE - - + - - + - + - - + - -MAJOR + + MAJOR - - + - -MAJOR + + MAJOR - - + - + - -MAJOR + + MAJOR - - + - + -MINOR + MINOR - + - + - -MAJOR + + MAJOR - + - + - -MAJOR + + MAJOR - + - + -MINOR + MINOR - - + - - + - + -MINOR + MINOR - + - - + - + -MINOR + MINOR - + - - + - + -MINOR + MINOR - + - - + - + - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR - - + ^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$ - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR - - + ^[a-z][a-zA-Z0-9]*$ - -MAJOR + + MAJOR - + - + - + -MINOR + MINOR - - + - + - + -MINOR + MINOR - + - + -MINOR + MINOR - - + - - + - - + - -MAJOR + + MAJOR MULTIPLE - + - + - - + - + - - + - - + - + - -MAJOR + + MAJOR - + - + - + - -MAJOR + + MAJOR - + - + - + -MINOR + MINOR - + - + - + - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR MULTIPLE - - + ^[a-z][a-zA-Z0-9]*$ - Controls whether to apply the check to public member + true - Controls whether to apply the check to protected member + true - Controls whether to apply the check to package-private member + true - Controls whether to apply the check to private member + true - -MAJOR + + MAJOR - - + - + - + - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR - + - -MAJOR + + MAJOR - + - + -MINOR + MINOR MULTIPLE - + - + -MINOR + MINOR - + - + - - + - - + MAJOR MULTIPLE - + ^[A-Z][a-zA-Z0-9]*$ - + - Controls whether to apply the check to public member + true - Controls whether to apply the check to protected member + true - Controls whether to apply the check to package-private member + true - Controls whether to apply the check to private member + true - -MAJOR + + MAJOR - + - + - + - -MAJOR + + MAJOR - + - - + -MINOR + MINOR - + -INFO + INFO - + -MINOR + MINOR - Section 3.10.1.]]> + - -MAJOR + + MAJOR - - + - + - + - - + -MINOR + MINOR - - + - + -MINOR + MINOR - + - + - + - + -MINOR + MINOR - - + - + - + - +
    \ No newline at end of file -- cgit v1.2.3