builder/resources/rules: extract rule documentation
This commit is contained in:
parent
34d03f5ce5
commit
42c310cdcc
155 changed files with 2133 additions and 0 deletions
12
src/builder/resources/rules/AbbreviationAsWordInName.md
Normal file
12
src/builder/resources/rules/AbbreviationAsWordInName.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Enforces proper `CamelCase` and avoids sequences of consecutive uppercase characters in identifiers. Does not apply to @Overridden methods.
|
||||
|
||||
Valid:
|
||||
````
|
||||
class DaoManager {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class DAOManager {}
|
||||
````
|
12
src/builder/resources/rules/AbstractClassName.md
Normal file
12
src/builder/resources/rules/AbstractClassName.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
The name of an `abstract` class must start with `Abstract`. Classes that start with `Abstract` must be `abstract`.
|
||||
|
||||
Valid:
|
||||
````
|
||||
abstract class AbstractCardHand implements CardHand {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
abstract class BaseCardHand implements CardHand {}
|
||||
````
|
1
src/builder/resources/rules/AnnonInnerLength.md
Normal file
1
src/builder/resources/rules/AnnonInnerLength.md
Normal file
|
@ -0,0 +1 @@
|
|||
Anonymous inner classes should be no more than 20 lines.
|
20
src/builder/resources/rules/AnnotationLocation.md
Normal file
20
src/builder/resources/rules/AnnotationLocation.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Annotations must be on a line by themselves unless annotating a method parameter or among class modifiers.
|
||||
|
||||
Valid:
|
||||
````
|
||||
@Component
|
||||
@Qualifier("Red")
|
||||
class RedStick implements Stick {
|
||||
|
||||
public @NonNull String getLabel(@Value("${stick.length}") final int length) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
@Component @Qualifier("Red")
|
||||
class RedStick implements Stick {}
|
||||
````
|
15
src/builder/resources/rules/AnnotationUseStyle.md
Normal file
15
src/builder/resources/rules/AnnotationUseStyle.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
Annotations should only use brackets and named attributes when they are needed. If only the default parameter is specified, then only the attribute value should be given. If there are no parameters, then no brackets should be given.
|
||||
|
||||
Valid:
|
||||
````
|
||||
@Entity
|
||||
@Table("names")
|
||||
@MyAnnotation(realm = "external")
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
@Entity()
|
||||
@Table(value = "names")
|
||||
````
|
2
src/builder/resources/rules/AnonInnerLength.md
Normal file
2
src/builder/resources/rules/AnonInnerLength.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Anonymous inner classes should be no more than 20 lines.
|
12
src/builder/resources/rules/ArrayTypeStyle.md
Normal file
12
src/builder/resources/rules/ArrayTypeStyle.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Enforces Java style arrays.
|
||||
|
||||
Valid:
|
||||
````
|
||||
public static void main(String[] args) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
public static void main(String args[]) {}
|
||||
````
|
20
src/builder/resources/rules/AtclauseOrder.md
Normal file
20
src/builder/resources/rules/AtclauseOrder.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Javadoc `@` clauses must be in the order:
|
||||
|
||||
````
|
||||
/**
|
||||
*
|
||||
* @param ...
|
||||
* @author ...
|
||||
* @version ...
|
||||
* @serial ...
|
||||
* @return ...
|
||||
* @throws ...
|
||||
* @exception ...
|
||||
* @serialData ...
|
||||
* @serialField ...
|
||||
* @see ...
|
||||
* @since ...
|
||||
* @deprecated ...
|
||||
*/
|
||||
````
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
Checks that condition expressions don't become less readable by attempting to use a constant on the left-hand-side of a comparison.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (a == 12) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if (12 == a) {}
|
||||
````
|
13
src/builder/resources/rules/AvoidEscapedUnicodeCharacters.md
Normal file
13
src/builder/resources/rules/AvoidEscapedUnicodeCharacters.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
Prevents use of obscure escape codes (e.g. `\u221e`). However, non-printable/control characters are still permitted.
|
||||
|
||||
Valid:
|
||||
````
|
||||
String unitAbbrev = "??s";
|
||||
String byteOrdered = '\ufeff' = content;
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
String unitAbbrev = "\u03bcs";
|
||||
````
|
20
src/builder/resources/rules/AvoidHidingCauseException.md
Normal file
20
src/builder/resources/rules/AvoidHidingCauseException.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Ensures that an exception is re-thrown properly and is not swallowed by a `catch` block.
|
||||
|
||||
Valid:
|
||||
````
|
||||
try {
|
||||
doSomething();
|
||||
} catch (MyException e) {
|
||||
throw new MyOtherException(e);
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
try {
|
||||
doSomething();
|
||||
} catch (MyException e) {
|
||||
throw new MyOtherException();
|
||||
}
|
||||
````
|
2
src/builder/resources/rules/AvoidInlineConditionals.md
Normal file
2
src/builder/resources/rules/AvoidInlineConditionals.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Prevents use of the `?:` operators.
|
17
src/builder/resources/rules/AvoidNestedBlocks.md
Normal file
17
src/builder/resources/rules/AvoidNestedBlocks.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
Avoid unnecessary blocks.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (isDebug()) {
|
||||
// ...
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
// if (isDebug())
|
||||
{
|
||||
// ...
|
||||
}
|
||||
````
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
Prevents the use of boolean operators that don't allow short-circuiting the expression. (e.g. '|', '&', '|=' and '&=')
|
||||
|
||||
Valid:
|
||||
````
|
||||
if ((a < b) || (b > getExpensiveValue())) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if ((a < b) | (b > getExpensiveValue())) {}
|
||||
````
|
10
src/builder/resources/rules/AvoidStarImport.md
Normal file
10
src/builder/resources/rules/AvoidStarImport.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
Prevents the use of the star import.
|
||||
|
||||
Invalid:
|
||||
````
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
````
|
19
src/builder/resources/rules/AvoidStaticImport.md
Normal file
19
src/builder/resources/rules/AvoidStaticImport.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
Prevents importing static members, unless they are one of the following:
|
||||
|
||||
* `org.assertj.core.api.Assertions.assertThat`
|
||||
* `org.mockito.BDDMockito.given`
|
||||
* `org.mockito.Mockito.*`
|
||||
* `org.mockito.Matchers.*`
|
||||
* `org.mockito.Mockito.*`
|
||||
|
||||
Valid:
|
||||
````
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
````
|
12
src/builder/resources/rules/BooleanExpressionComplexity.md
Normal file
12
src/builder/resources/rules/BooleanExpressionComplexity.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Restrict the number of number of &&, ||, &, | and ^ in an expression to 2.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (a || (b && c)) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if (a > b || b > c || c == a || d > a) {}
|
||||
````
|
29
src/builder/resources/rules/CatchParameterName.md
Normal file
29
src/builder/resources/rules/CatchParameterName.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
Checks that catch parameter names conform to the following characteristic:
|
||||
|
||||
* allows names beginning with two lowercase letters followed by at least one uppercase or lowercase letter
|
||||
* allows e abbreviation (suitable for exceptions end errors)
|
||||
* allows ex abbreviation (suitable for exceptions)
|
||||
* allows t abbreviation (suitable for throwables)
|
||||
* prohibits numbered abbreviations like e1 or t2
|
||||
* prohibits one letter prefixes like pException
|
||||
* prohibits two letter abbreviations like ie or ee
|
||||
* prohibits any other characters than letters
|
||||
|
||||
Valid:
|
||||
````
|
||||
catch(Exception txD) {}
|
||||
catch(Exception txf) {}
|
||||
catch(Exception e) {}
|
||||
catch(Error e) {}
|
||||
catch(Exception ex) {}
|
||||
catch(Throwable t) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
catch(Exception e2) {}
|
||||
catch(Exception pExceptions) {}
|
||||
catch(Exception gh) {}
|
||||
catch(Exception e_x) {}
|
||||
````
|
30
src/builder/resources/rules/ClassDataAbstractionCoupling.md
Normal file
30
src/builder/resources/rules/ClassDataAbstractionCoupling.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
Restricts to 7 the number of different classes instantiated within a class when that class is instantiated.
|
||||
|
||||
Valid:
|
||||
````
|
||||
class Valid {
|
||||
private final Item i1 = new Item();
|
||||
private final Item i2 = new Item();
|
||||
private final Item i3 = new Item();
|
||||
private final Item i4 = new Item();
|
||||
private final Item i5 = new Item();
|
||||
private final Item i6 = new Item();
|
||||
private final Item i7 = new Item();
|
||||
private final Item i8 = new Item();
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Invalid {
|
||||
private final ItemA i1 = new ItemA();
|
||||
private final ItemB i2 = new ItemB();
|
||||
private final ItemC i3 = new ItemC();
|
||||
private final ItemD i4 = new ItemD();
|
||||
private final ItemE i5 = new ItemE();
|
||||
private final ItemF i6 = new ItemF();
|
||||
private final ItemG i7 = new ItemG();
|
||||
private final ItemH i8 = new ItemH();
|
||||
}
|
||||
````
|
4
src/builder/resources/rules/ClassFanOutComplexity.md
Normal file
4
src/builder/resources/rules/ClassFanOutComplexity.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Restricts the number of other classes that a class can rely on to 20.
|
||||
|
||||
While `ClassDataAbstractionCoupling` limits the number of classes that are instantiated when the class is, this check counts all fields whether they are assigned a value or not.
|
14
src/builder/resources/rules/ClassTypeParameterName.md
Normal file
14
src/builder/resources/rules/ClassTypeParameterName.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
Restricts class generics parameters to be a single uppercase letter.
|
||||
|
||||
Valid:
|
||||
````
|
||||
class Deliverator <A> {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Invalidator <a> {}
|
||||
class Invalidator <BB> {}
|
||||
class Invalidator <C3> {}
|
||||
````
|
45
src/builder/resources/rules/CommentsIndentation.md
Normal file
45
src/builder/resources/rules/CommentsIndentation.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
Requires the indentation of comments to match the surrounding code.
|
||||
|
||||
Valid:
|
||||
````
|
||||
/**
|
||||
* This is okay.
|
||||
*/
|
||||
int size = 20;
|
||||
|
||||
public foo() {
|
||||
super();
|
||||
// this is okay
|
||||
}
|
||||
|
||||
public void foo11() {
|
||||
CheckUtils
|
||||
.getFirstNode(new DetailAST())
|
||||
.getFirstChild()
|
||||
.getNextSibling();
|
||||
// this is okay
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
/**
|
||||
* This is NOT okay.
|
||||
*/
|
||||
int size = 20;
|
||||
|
||||
public foo() {
|
||||
super();
|
||||
// this is NOT okay
|
||||
// this is NOT okay
|
||||
}
|
||||
|
||||
public void foo11() {
|
||||
CheckUtils
|
||||
.getFirstNode(new DetailAST())
|
||||
.getFirstChild()
|
||||
.getNextSibling();
|
||||
// this is NOT okay
|
||||
}
|
||||
````
|
20
src/builder/resources/rules/ConfusingCondition.md
Normal file
20
src/builder/resources/rules/ConfusingCondition.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Checks that the expression with the `if` condition in an `if-then-else` statement is not negated.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (isValid()) {
|
||||
handleValidCondition();
|
||||
} else {
|
||||
handleInvalidCondition();
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if (!isValid()) {
|
||||
handleInvalidCondition();
|
||||
} else {
|
||||
handleValidCondition();
|
||||
}
|
||||
````
|
15
src/builder/resources/rules/ConstantName.md
Normal file
15
src/builder/resources/rules/ConstantName.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
> This check cannot be suppressed.
|
||||
|
||||
Requires constants (static, final fields) to be all uppercase. Numbers and numbers are permitted but not as the first character.
|
||||
|
||||
Valid:
|
||||
````
|
||||
private static final int JACK_CARD = 11;
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
private static final int ace_card = 1;
|
||||
private static final int 12_CARD = 12;
|
||||
````
|
2
src/builder/resources/rules/ConstructorWithoutParams.md
Normal file
2
src/builder/resources/rules/ConstructorWithoutParams.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Exception class constructors must accept parameters for message and/or cause. This check is applied to classes whose name ends with `Exception`.
|
26
src/builder/resources/rules/CovariantEquals.md
Normal file
26
src/builder/resources/rules/CovariantEquals.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
> This check cannot be suppressed.
|
||||
|
||||
Checks that classes which define a covariant equals() method also override method equals(Object).
|
||||
|
||||
Valid:
|
||||
````
|
||||
class Test {
|
||||
public boolean equals(Test i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Test {
|
||||
public boolean equals(Test i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
````
|
36
src/builder/resources/rules/CyclomaticComplexity.md
Normal file
36
src/builder/resources/rules/CyclomaticComplexity.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
|
||||
Restricts the cyclomatic complexity of a method to 5. The cyclomatic complexity is a measure of the number of decision points in a method.
|
||||
|
||||
A method with no branches has a complexity of 1. For each `if`, `while`, `do`, `for`, `?:`, `catch`, `switch`, `case`, `&&` and `||` the complexity goes up by 1.
|
||||
|
||||
Valid:
|
||||
````
|
||||
void isValid(int a, int b, int c) {
|
||||
// 1
|
||||
if (a > b) { // +1 = 2
|
||||
switch (c) { // +1 = 3
|
||||
case 1: // +1 = 4
|
||||
break;
|
||||
case 2: // +1 = 5
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
void isInvalid(int a, int b, int c) {
|
||||
// 1
|
||||
if (a > b) { // +1 = 2
|
||||
switch (c) { // +1 = 3
|
||||
case 1: // +1 = 4
|
||||
break;
|
||||
case 2: // +1 = 5
|
||||
break;
|
||||
case 3: // +1 = 6
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
45
src/builder/resources/rules/DeclarationOrder.md
Normal file
45
src/builder/resources/rules/DeclarationOrder.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
Ensure class elements appear in the correct order.
|
||||
|
||||
Valid:
|
||||
````
|
||||
class Valid {
|
||||
// static
|
||||
public static int a;
|
||||
protected static int b;
|
||||
static int c;
|
||||
private static int d;
|
||||
|
||||
// instance
|
||||
public int e;
|
||||
protected int f;
|
||||
int g;
|
||||
private int h;
|
||||
|
||||
// constructors
|
||||
Valid() {}
|
||||
|
||||
// methods
|
||||
void foo() {}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Invalid {
|
||||
protected static int b;
|
||||
public static int a;
|
||||
private static int d;
|
||||
|
||||
public int e;
|
||||
static int c;
|
||||
protected int f;
|
||||
private int h;
|
||||
|
||||
void foo() {}
|
||||
|
||||
Valid() {}
|
||||
|
||||
int g;
|
||||
}
|
||||
````
|
26
src/builder/resources/rules/DefaultComesLast.md
Normal file
26
src/builder/resources/rules/DefaultComesLast.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
Check that the `default` is after all the `case`s in a `switch` statement.
|
||||
|
||||
Valid:
|
||||
````
|
||||
switch (a) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
switch (a) {
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
````
|
11
src/builder/resources/rules/DesignForExtension.md
Normal file
11
src/builder/resources/rules/DesignForExtension.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
Judicous use of `@SuppressWarnings("designdorextension")` is recommended for this check.
|
||||
|
||||
This check is primarily intended for use in library modules rather than applications.
|
||||
|
||||
Classes that are deemed by their designer to be 'designed for extension', must take steps to prevent a subclass from breaking the class's behaviour by overriding methods incorrectly. This can be done through a combination of:
|
||||
|
||||
* Defining 'hook' methods with empty implementations that subclasses override to add their own behaviour
|
||||
* Marking methods that are non-private and non-static as abstract or final
|
||||
|
||||
> See the official [Checkstyle documentation](http://checkstyle.sourceforge.net/config_design.html#DesignForExtension) for more details and [Effective Java], 2nd Edition by Josh Bloch: Item 17: Design and document for inheritance or else prohibit it.
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
Checks that the diamond operator is used where possible.
|
||||
|
||||
Valid:
|
||||
````
|
||||
Map<Long, String> idTable = new HashMap<>();
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
Map<Long, String> idTable = new HashMap<Long, String>();
|
||||
````
|
4
src/builder/resources/rules/EitherLogOrThrow.md
Normal file
4
src/builder/resources/rules/EitherLogOrThrow.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Checks that when an exception is caught, that if it is logged then it is not also re-thrown. Log or throw; one or the other or neither, but not both.
|
||||
|
||||
Accepts `java.util.logging.Logger` and `org.slf4j.Logger`.
|
15
src/builder/resources/rules/EmptyBlock.md
Normal file
15
src/builder/resources/rules/EmptyBlock.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
Checks for empty blocks.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (a >b) {
|
||||
doSomething();
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if (a > b) {
|
||||
}
|
||||
````
|
20
src/builder/resources/rules/EmptyCatchBlock.md
Normal file
20
src/builder/resources/rules/EmptyCatchBlock.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Checks that `catch` blocks are not empty, or are commented with the word `expected` or `ignore`.
|
||||
|
||||
Valid:
|
||||
````
|
||||
try {
|
||||
something();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
try {
|
||||
something();
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
````
|
12
src/builder/resources/rules/EmptyForInitializerPad.md
Normal file
12
src/builder/resources/rules/EmptyForInitializerPad.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Checks that there is no padding in an empty `for` loop **initialiser**.
|
||||
|
||||
Valid:
|
||||
````
|
||||
for (; i < j ; i++) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
for ( ; i < j ; i++) {}
|
||||
````
|
12
src/builder/resources/rules/EmptyForIteratorPad.md
Normal file
12
src/builder/resources/rules/EmptyForIteratorPad.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Checks that there is no padding in an empty `for` loop **iterator**.
|
||||
|
||||
Valid:
|
||||
````
|
||||
for (Iterator i = list.getIterator(); i.hasNext() ;) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
for (Iterator i = list.getIterator(); i.hasNext() ; ) {}
|
||||
````
|
52
src/builder/resources/rules/EmptyLineSeparator.md
Normal file
52
src/builder/resources/rules/EmptyLineSeparator.md
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
Checks that there are blank lines between header, package, import blocks, field, constructors, methods, nested classes, static initialisers and instance initialisers.
|
||||
|
||||
Valid:
|
||||
````
|
||||
/**
|
||||
* Licence header.
|
||||
*/
|
||||
|
||||
package net.kemitix.foo;
|
||||
|
||||
import ...;
|
||||
import ...;
|
||||
|
||||
class Foo {
|
||||
|
||||
private int a;
|
||||
|
||||
private int b;
|
||||
|
||||
Foo() {}
|
||||
|
||||
Foo(int a, int b) {}
|
||||
|
||||
int getA() {}
|
||||
|
||||
int getB() {}
|
||||
|
||||
class Bar {
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
/**
|
||||
* Licence header.
|
||||
*/
|
||||
package net.kemitix.foo;
|
||||
import ...;
|
||||
import ...;
|
||||
class Foo {
|
||||
private int a;
|
||||
private int b;
|
||||
Foo() {}
|
||||
Foo(int a, int b) {}
|
||||
int getA() {}
|
||||
int getB() {}
|
||||
class Bar {
|
||||
}
|
||||
}
|
||||
````
|
12
src/builder/resources/rules/EmptyStatement.md
Normal file
12
src/builder/resources/rules/EmptyStatement.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Checks for empty statements. An empty statement is a standalone semicolon (;).
|
||||
|
||||
Valid:
|
||||
````
|
||||
doSomething();
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
doSomething();;
|
||||
````
|
49
src/builder/resources/rules/EnumValueName.md
Normal file
49
src/builder/resources/rules/EnumValueName.md
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
Enums are considered to be of two distinct types: 'Class' or 'Value' enumerations. The distinction being that Class Enumerations have methods (other than `toString()`) defined.
|
||||
|
||||
The values defined in the `enum` must match the appropriate pattern:
|
||||
|
||||
* Class: `^[A-Z][a-zA-Z0-9]*$`
|
||||
* Value: `^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$`
|
||||
|
||||
The difference being that Class enumerations can't contain underscores but can include lowercase letters (after the first initial capital). Value enumerations can include underscores, but not as the first or second character.
|
||||
|
||||
Valid:
|
||||
````
|
||||
enum ValidConstants {
|
||||
|
||||
ALPHA, BETA;
|
||||
}
|
||||
|
||||
enum ValidClassLike {
|
||||
|
||||
Alpha("a"),
|
||||
Beta("b");
|
||||
|
||||
private String name;
|
||||
|
||||
ValidClassLike(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
enum InvalidConstants {
|
||||
|
||||
alpha, Beta, GAMMA_RAY;
|
||||
}
|
||||
|
||||
enum InvalidClassLike {
|
||||
|
||||
alpha("a"),
|
||||
beta("b");
|
||||
|
||||
private String name;
|
||||
|
||||
InvalidClassLike(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
````
|
14
src/builder/resources/rules/EqualsAvoidNull.md
Normal file
14
src/builder/resources/rules/EqualsAvoidNull.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
Checks that string literals are on the left side in an `equals()` comparison.
|
||||
|
||||
Valid:
|
||||
````
|
||||
String nullString = null;
|
||||
"value".equals(nullString);
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
String nullString = null;
|
||||
nullString.equals("value");
|
||||
````
|
4
src/builder/resources/rules/EqualsHashCode.md
Normal file
4
src/builder/resources/rules/EqualsHashCode.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
> This check cannot be suppressed.
|
||||
|
||||
Checks that when a class overrides the `equals()` method, that it also overrides the `hashCode()` method.
|
2
src/builder/resources/rules/ExecutableStatementCount.md
Normal file
2
src/builder/resources/rules/ExecutableStatementCount.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Limits the number of executable statements in a method to 30.
|
22
src/builder/resources/rules/ExplicitInitialization.md
Normal file
22
src/builder/resources/rules/ExplicitInitialization.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Checks that fields are not being explicitly initialised to their already default value.
|
||||
|
||||
Valid:
|
||||
````
|
||||
class Valid {
|
||||
|
||||
private int foo;
|
||||
|
||||
private Object bar;
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Invalid {
|
||||
|
||||
private int foo = 0;
|
||||
|
||||
private Object bar = null;
|
||||
}
|
||||
````
|
42
src/builder/resources/rules/FallThrough.md
Normal file
42
src/builder/resources/rules/FallThrough.md
Normal file
|
@ -0,0 +1,42 @@
|
|||
|
||||
Checks that when a `case` in a `switch` statement falls through (i.e. doesn't end with `break;`) that the fall through is documented with a comment.
|
||||
|
||||
Valid:
|
||||
````
|
||||
switch (i) {
|
||||
case 0:
|
||||
i++; // fall through
|
||||
|
||||
case 1:
|
||||
i++;
|
||||
// falls through
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 4: { i++ } // fallthrough
|
||||
case 5:
|
||||
i++;
|
||||
/* fallthrou */
|
||||
case 6:
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
switch (i) {
|
||||
case 0:
|
||||
i++;
|
||||
case 1:
|
||||
i++;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4: { i++ }
|
||||
case 5:
|
||||
i++;
|
||||
case 6:
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
````
|
2
src/builder/resources/rules/FileLength.md
Normal file
2
src/builder/resources/rules/FileLength.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that each file has no more than 2000 lines.
|
2
src/builder/resources/rules/FileTabCharacter.md
Normal file
2
src/builder/resources/rules/FileTabCharacter.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that there are no tab characters in the source files.
|
18
src/builder/resources/rules/FinalClass.md
Normal file
18
src/builder/resources/rules/FinalClass.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
Checks that classes which have only private constructors are also declared as `final`. These classes can't be extended by a subclass as they can't call `super()` from their constructors.
|
||||
|
||||
Valid:
|
||||
````
|
||||
final class Valid {
|
||||
|
||||
private Valid() {}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Invalid {
|
||||
|
||||
private Invalid() {}
|
||||
}
|
||||
````
|
12
src/builder/resources/rules/FinalParameters.md
Normal file
12
src/builder/resources/rules/FinalParameters.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Parameters to a method must be `final`.
|
||||
|
||||
Valid:
|
||||
````
|
||||
void foo(final int a) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
void foo(int a) {}
|
||||
````
|
16
src/builder/resources/rules/ForbidCCommentsInMethods.md
Normal file
16
src/builder/resources/rules/ForbidCCommentsInMethods.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
Prevents the use of `/* C-style */` comments inside methods.
|
||||
|
||||
Valid:
|
||||
````
|
||||
void doSomething() {
|
||||
// a comment
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
void doSomething() {
|
||||
/* invalid */
|
||||
}
|
||||
````
|
13
src/builder/resources/rules/ForbidReturnInFinallyBlock.md
Normal file
13
src/builder/resources/rules/ForbidReturnInFinallyBlock.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
Prevent the use of a `return` statement in the `finally` block.
|
||||
|
||||
Invalid:
|
||||
````
|
||||
try {
|
||||
doSomething();
|
||||
{ catch (IOException e) {
|
||||
// log error
|
||||
} finally (
|
||||
return true; // invalid
|
||||
}
|
||||
````
|
12
src/builder/resources/rules/ForbidWildcardAsReturnType.md
Normal file
12
src/builder/resources/rules/ForbidWildcardAsReturnType.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Prevents declaring a method from returning a wildcard type as its return value.
|
||||
|
||||
Valid:
|
||||
````
|
||||
<E> List<E> getList() {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
<E> List<? extends E> getList() {}
|
||||
````
|
13
src/builder/resources/rules/GenericWhitespace.md
Normal file
13
src/builder/resources/rules/GenericWhitespace.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
Checks that the angle brackets around Generics parameters have the correct whitespace padding:
|
||||
|
||||
Valid:
|
||||
````
|
||||
public void <K, V extends Number> boolean foo(K, V) {}
|
||||
class name<T1, T2, ..., Tn> {}
|
||||
OrderedPair<String, Box<Integer>> p;
|
||||
boolean same = Util.<Integer, String>compare(p1, p2);
|
||||
Pair<Integer, String> p1 = new Pair<>(1, "apple");
|
||||
List<T> list = ImmutableList.Builder<T>::new;
|
||||
sort(list, Comparable::<String>compareTo);
|
||||
````
|
2
src/builder/resources/rules/Header.md
Normal file
2
src/builder/resources/rules/Header.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that all `*.java` source files begin with the contents of the `LICENSE.txt` file.
|
30
src/builder/resources/rules/HiddenField.md
Normal file
30
src/builder/resources/rules/HiddenField.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
Checks that a local variable or parameter in a method doesn't have the same name as a field. Doesn't apply in constructors or setters.
|
||||
|
||||
Valid:
|
||||
````
|
||||
class Foo {
|
||||
|
||||
private int a;
|
||||
|
||||
Foo(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
setA(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Bar {
|
||||
|
||||
private int b;
|
||||
|
||||
void baz(int b) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
````
|
29
src/builder/resources/rules/HideUtilityClassConstructor.md
Normal file
29
src/builder/resources/rules/HideUtilityClassConstructor.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
Classes that only have static fields or methods should not have a public constructor. This includes the default constructor.
|
||||
|
||||
Valid:
|
||||
````
|
||||
final class StringUtils {
|
||||
|
||||
private Utils() {}
|
||||
|
||||
private static int count(chat c, String s) {}
|
||||
}
|
||||
|
||||
class StringUtils {
|
||||
|
||||
protected Utils() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private static int count(chat c, String s) {}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class StringUtils {
|
||||
|
||||
private static int count(chat c, String s) {}
|
||||
}
|
||||
````
|
24
src/builder/resources/rules/IllegalCatch.md
Normal file
24
src/builder/resources/rules/IllegalCatch.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
Prevent the following types from being in a `catch` statement:
|
||||
|
||||
* java.lang.Exception
|
||||
* java.lang.Throwable
|
||||
* java.lang.RuntimeException
|
||||
|
||||
Valid:
|
||||
````
|
||||
try {
|
||||
doSomething();
|
||||
} catch (SpecificException e) {
|
||||
// log
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
try {
|
||||
doSomething();
|
||||
} catch (Exception e) {
|
||||
// log
|
||||
}
|
||||
````
|
7
src/builder/resources/rules/IllegalImport.md
Normal file
7
src/builder/resources/rules/IllegalImport.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
Prevent `import`ing from the `sun.*` packages.
|
||||
|
||||
Invalid:
|
||||
````
|
||||
import sun.security.provider.Sun;
|
||||
````
|
16
src/builder/resources/rules/IllegalThrows.md
Normal file
16
src/builder/resources/rules/IllegalThrows.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
Prevent the following types from being `throw`n:
|
||||
|
||||
* java.lang.Exception
|
||||
* java.lang.Throwable
|
||||
* java.lang.RuntimeException
|
||||
|
||||
Valid:
|
||||
````
|
||||
throw new SpecificException("error");
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
throw new RuntimeException("boom!");
|
||||
````
|
2
src/builder/resources/rules/IllegalToken.md
Normal file
2
src/builder/resources/rules/IllegalToken.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that labels are not used.
|
28
src/builder/resources/rules/IllegalType.md
Normal file
28
src/builder/resources/rules/IllegalType.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
Prevents use of implementation classes as variables, parameters or method returns. Use the interfaces instead.
|
||||
|
||||
Prevents variables, parameters and method returns from being any of the following:
|
||||
|
||||
* java.util.ArrayDeque
|
||||
* java.util.ArrayList
|
||||
* java.util.EnumMap
|
||||
* java.util.EnumSet
|
||||
* java.util.HashMap
|
||||
* java.util.HashSet
|
||||
* java.util.IdentityHashMap
|
||||
* java.util.LinkedHashMap
|
||||
* java.util.LinkedHashSet
|
||||
* java.util.LinkedList
|
||||
* java.util.PriorityQueue
|
||||
* java.util.TreeMap
|
||||
* java.util.TreeSet
|
||||
|
||||
Valid:
|
||||
````
|
||||
Set<String> getNames();
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
HashSet<String> getNames();
|
||||
````
|
13
src/builder/resources/rules/InnerAssignment.md
Normal file
13
src/builder/resources/rules/InnerAssignment.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
Checks for assignments within an expressions. However, it still allows assignment in a while loop clause.
|
||||
|
||||
Valid:
|
||||
````
|
||||
while((line = reader.readLine()) != null) {
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
String s = Integer.toString(i = 2);
|
||||
````
|
2
src/builder/resources/rules/InnerTypeLast.md
Normal file
2
src/builder/resources/rules/InnerTypeLast.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Inner classes must appear at the bottom of a class, below fields and methods.
|
20
src/builder/resources/rules/InterfaceIsType.md
Normal file
20
src/builder/resources/rules/InterfaceIsType.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
An `interface` must define methods, not just constants.
|
||||
|
||||
Valid:
|
||||
````
|
||||
interface Foo {
|
||||
|
||||
static final String "Foo!!";
|
||||
|
||||
getBar();
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
interface Foo {
|
||||
|
||||
static final String "Foo!!";
|
||||
}
|
||||
````
|
12
src/builder/resources/rules/InterfaceTypeParameterName.md
Normal file
12
src/builder/resources/rules/InterfaceTypeParameterName.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
Checks that the type parameters for an interface are a single uppercase letter.
|
||||
|
||||
Valid:
|
||||
````
|
||||
interface <T> Portable {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
interface <Type> Portable {}
|
||||
````
|
4
src/builder/resources/rules/JavaNCSS.md
Normal file
4
src/builder/resources/rules/JavaNCSS.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Restricts the NCSS score for methods, classes and files to 40, 1200 and 1600 respectively. The NCSS score is a measure of the number of statements within a scope.
|
||||
|
||||
Too high an NCSS score suggests that the method or class is doing too much and should be decomposed into smaller units.
|
2
src/builder/resources/rules/JavadocMethod.md
Normal file
2
src/builder/resources/rules/JavadocMethod.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that all public, protected and package methods have a Javadoc block, that all `@throws` tags are used. Basic setters and getters do not require javadoc.
|
2
src/builder/resources/rules/JavadocPackage.md
Normal file
2
src/builder/resources/rules/JavadocPackage.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that each package has a `package-info.java` file.
|
2
src/builder/resources/rules/JavadocParagraph.md
Normal file
2
src/builder/resources/rules/JavadocParagraph.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that paragraphs in Javadoc blocks are wrapped in `<p>` elements and have blank lines between paragraphs. This first paragraph does not need the `<p>` elements.
|
2
src/builder/resources/rules/JavadocStyle.md
Normal file
2
src/builder/resources/rules/JavadocStyle.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks the formatting of the Javadoc blocks. See the official [Checkstyle documentation](http://checkstyle.sourceforge.net/config_javadoc.html#JavadocStyle) for all the checks that are applied.
|
2
src/builder/resources/rules/JavadocType.md
Normal file
2
src/builder/resources/rules/JavadocType.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks the format for Javadoc for classes and enums. Javadoc must be present, not have any unknown tags and not missing any `@param` tags. The `@author` tag must have a name and, in brackets, an email address.
|
16
src/builder/resources/rules/LeftCurly.md
Normal file
16
src/builder/resources/rules/LeftCurly.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
Checks that the left curly brace ('{') is placed at the end of the line. Does not check enums.
|
||||
|
||||
Valid:
|
||||
````
|
||||
class Foo {
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
class Bar
|
||||
{
|
||||
|
||||
}
|
||||
````
|
4
src/builder/resources/rules/LineLength.md
Normal file
4
src/builder/resources/rules/LineLength.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Limits the line length to 120 characters.
|
||||
|
||||
Doesn't check package or import lines.
|
4
src/builder/resources/rules/LocalFinalVariableName.md
Normal file
4
src/builder/resources/rules/LocalFinalVariableName.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Checks the format of local, `final` variable names, including `catch` parameters.
|
||||
|
||||
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.
|
4
src/builder/resources/rules/LocalVariableName.md
Normal file
4
src/builder/resources/rules/LocalVariableName.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Checks the format of local, non-`final` variable names.
|
||||
|
||||
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
Prevent the placement of variables or fields after methods in an expression.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (property && getProperty()) {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if (getProperty() && property) {}
|
||||
````
|
15
src/builder/resources/rules/MagicNumber.md
Normal file
15
src/builder/resources/rules/MagicNumber.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
Checks that numeric literals are defined as constants. Being constants they then have a name that aids in making them non-magical.
|
||||
|
||||
The numbers -1, 0, 1 and 2 are not considered to be magical.
|
||||
|
||||
Valid:
|
||||
````
|
||||
static final int SECONDS_PER_DAY = 24 * 60 * 60;
|
||||
static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
|
||||
````
|
||||
|
||||
Invalid
|
||||
````
|
||||
String item = getItem(200);
|
||||
````
|
2
src/builder/resources/rules/MapIterationInForEachLoop.md
Normal file
2
src/builder/resources/rules/MapIterationInForEachLoop.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks for unoptimised iterations over `Map`s. Check use of `map.values()`, `map.keySet()` and `map.entrySet()` against the use of the iterator produced to verify if another could be better.
|
4
src/builder/resources/rules/MemberName.md
Normal file
4
src/builder/resources/rules/MemberName.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Checks the format of non-static field names.
|
||||
|
||||
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.
|
2
src/builder/resources/rules/MethodCount.md
Normal file
2
src/builder/resources/rules/MethodCount.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Restricts the number of methods in a type to 30.
|
2
src/builder/resources/rules/MethodLength.md
Normal file
2
src/builder/resources/rules/MethodLength.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Restricts the number of lines in a method to 60. Include blank lines and single line comments. You should be able to see an entire method without needing to scroll.
|
4
src/builder/resources/rules/MethodName.md
Normal file
4
src/builder/resources/rules/MethodName.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Checks the format of method names.
|
||||
|
||||
Identifiers must match `^[a-z][a-zA-Z0-9]*$`.
|
15
src/builder/resources/rules/MethodParamPad.md
Normal file
15
src/builder/resources/rules/MethodParamPad.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
Checks that the padding between the method identifier and the left parenthesis is on the same line and doesn't have a space in-between.
|
||||
|
||||
Valid:
|
||||
````
|
||||
void getInstance();
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
void getInstance ();
|
||||
|
||||
void getValue
|
||||
();
|
||||
````
|
14
src/builder/resources/rules/MethodTypeParameterName.md
Normal file
14
src/builder/resources/rules/MethodTypeParameterName.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
Restricts method generics parameters to be a single uppercase letter.
|
||||
|
||||
Valid:
|
||||
````
|
||||
List<A> getItems() {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
List<a> getItems() {}
|
||||
List<BB> getItems() {}
|
||||
List<C3> getItems() {}
|
||||
````
|
29
src/builder/resources/rules/MissingDeprecated.md
Normal file
29
src/builder/resources/rules/MissingDeprecated.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
Both the `@Deprecated` annotation and the Javadoc tag `@deprecated` must be used in pairs.
|
||||
|
||||
Valid:
|
||||
````
|
||||
/**
|
||||
* Foo.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
void foo() {}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
/**
|
||||
* Foo.
|
||||
*/
|
||||
@Deprecated
|
||||
void foo() {}
|
||||
|
||||
/**
|
||||
* Bar.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
void bar() {}
|
||||
````
|
28
src/builder/resources/rules/MissingSwitchDefault.md
Normal file
28
src/builder/resources/rules/MissingSwitchDefault.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
Checks that `switch` statement has a `default` case.
|
||||
|
||||
Valid:
|
||||
````
|
||||
switch (foo) {
|
||||
case 1:
|
||||
//
|
||||
break;
|
||||
case 2:
|
||||
//
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateExcetion("Foo: " + foo);
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
switch (foo) {
|
||||
case 1:
|
||||
//
|
||||
break;
|
||||
case 2:
|
||||
//
|
||||
break;
|
||||
}
|
||||
````
|
9
src/builder/resources/rules/ModifiedControlVariable.md
Normal file
9
src/builder/resources/rules/ModifiedControlVariable.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
Checks that the control variable in a `for` loop is not modified inside the loop.
|
||||
|
||||
Invalid:
|
||||
````
|
||||
for (int i = 0; i < 1; i++) {
|
||||
i++;
|
||||
}
|
||||
````
|
16
src/builder/resources/rules/ModifierOrder.md
Normal file
16
src/builder/resources/rules/ModifierOrder.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
Check that modifiers are in the following order:
|
||||
|
||||
* `public`
|
||||
* `protected`
|
||||
* `private`
|
||||
* `abstract`
|
||||
* `static`
|
||||
* `final`
|
||||
* `transient`
|
||||
* `volatile`
|
||||
* `synchronized`
|
||||
* `native`
|
||||
* `strictfp`
|
||||
|
||||
Type annotations are ignored.
|
7
src/builder/resources/rules/MultipleStringLiterals.md
Normal file
7
src/builder/resources/rules/MultipleStringLiterals.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
Checks for multiple occurrences of the same string literal within a single file. Does not apply to empty strings ("").
|
||||
|
||||
Invalid:
|
||||
````
|
||||
String fooFoo = "foo" + "foo";
|
||||
````
|
13
src/builder/resources/rules/MultipleVariableDeclarations.md
Normal file
13
src/builder/resources/rules/MultipleVariableDeclarations.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
Checks that each variable is declared in its own statement and line.
|
||||
|
||||
Valid:
|
||||
````
|
||||
int a;
|
||||
int b;
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
int a, b;
|
||||
````
|
8
src/builder/resources/rules/MutableException.md
Normal file
8
src/builder/resources/rules/MutableException.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
Checks that `Exception` classes are immutable. However, you can still call `setStackTrace`.
|
||||
|
||||
Classes checked are those whose name ends with the following. Or that the class they extend does.
|
||||
|
||||
* `Exception`
|
||||
* `Error`
|
||||
* `Throwable`
|
2
src/builder/resources/rules/NPathComplexity.md
Normal file
2
src/builder/resources/rules/NPathComplexity.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that the NPATH score (number of paths) through a method is no more than 5. This is similar to [Cyclomatic Complexity](#cyclomaticcomplexity).
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
Checks the names of JUnit test classes. Classes checked are those that have at least one method annotated with `Test` or `org.junit.Test`.
|
||||
|
||||
Test class names must match: `.+Test\\d*|.+Tests\\d*|Test.+|Tests.+|.+IT|.+ITs|.+TestCase\\d*|.+TestCases\\d*`
|
32
src/builder/resources/rules/NeedBraces.md
Normal file
32
src/builder/resources/rules/NeedBraces.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
|
||||
Check that code blocks are surrounded by braces.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (obj.isValid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
while (obj.isValid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
do {
|
||||
this.notify();
|
||||
} while (o != null);
|
||||
|
||||
for (int i = 0; ;) {
|
||||
this.notify();
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if (obj.isValid()) return true;
|
||||
|
||||
while (obj.isValid()) return true;
|
||||
|
||||
do this.notify(); while (o != null);
|
||||
|
||||
for (int i = 0; ;) this.notify();
|
||||
````
|
22
src/builder/resources/rules/NestedForDepth.md
Normal file
22
src/builder/resources/rules/NestedForDepth.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Checks that `for` loops are not nested more than 1 deep.
|
||||
|
||||
Valid:
|
||||
````
|
||||
for (int i = 0; i < 1; i++) { // depth 0
|
||||
for (int j = 0; j < 1; j++) { // depth 1
|
||||
//
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
for (int i = 0; i < 1; i++) { // depth 0
|
||||
for (int j = 0; j < 1; j++) { // depth 1
|
||||
for (int k = 0; j < 1; k++) { // depth 2!
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
22
src/builder/resources/rules/NestedIfDepth.md
Normal file
22
src/builder/resources/rules/NestedIfDepth.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Checks that `if` blocks are not nested more than 1 deep.
|
||||
|
||||
Valid:
|
||||
````
|
||||
if (isValid()) { // depth 0
|
||||
if (isExpected()) { // depth 1
|
||||
doIt();
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
if (isValid()) { // depth 0
|
||||
if (isExpected()) { // depth 1
|
||||
if (isNecessary()) { // depth 2!
|
||||
doIt();
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
47
src/builder/resources/rules/NestedSwitch.md
Normal file
47
src/builder/resources/rules/NestedSwitch.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
|
||||
Checks that `switch` statements are not nested within one another.
|
||||
|
||||
Valid:
|
||||
````
|
||||
void doSomething(int a, int b) {
|
||||
|
||||
switch(a) {
|
||||
case 1:
|
||||
doMore(b);
|
||||
break;
|
||||
case 2:
|
||||
// ..
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void doMore(int b) {
|
||||
|
||||
switch(b) {
|
||||
case 1:
|
||||
//
|
||||
case 2:
|
||||
//
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
void doSomething(int a, int b) {
|
||||
|
||||
switch(a) {
|
||||
case 1:
|
||||
switch(b) {
|
||||
case 1:
|
||||
//
|
||||
case 2:
|
||||
//
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// ..
|
||||
}
|
||||
}
|
||||
}
|
||||
````
|
28
src/builder/resources/rules/NestedTryDepth.md
Normal file
28
src/builder/resources/rules/NestedTryDepth.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
Checks that `try` blocks are not nested.
|
||||
|
||||
Valid:
|
||||
````
|
||||
try {
|
||||
doSomething();
|
||||
doSomeOtherThing();
|
||||
} catch (SomeException se) {
|
||||
// handle it
|
||||
} catch (OtherExceptions oe) {
|
||||
// handle it
|
||||
}
|
||||
````
|
||||
|
||||
Invalid:
|
||||
````
|
||||
try {
|
||||
doSomething();
|
||||
try {
|
||||
doSomeOtherThing();
|
||||
} catch (OtherExceptions oe) {
|
||||
// handle it
|
||||
}
|
||||
} catch (SomeException se) {
|
||||
// handle it
|
||||
}
|
||||
````
|
2
src/builder/resources/rules/NewlineAtEndOfFile.md
Normal file
2
src/builder/resources/rules/NewlineAtEndOfFile.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
Checks that files end with a line-feed character, (i.e. unix-style line ending).
|
6
src/builder/resources/rules/NoClone.md
Normal file
6
src/builder/resources/rules/NoClone.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
> This check cannot be suppressed.
|
||||
|
||||
Checks that the `clone()` method from `Object` has not been overridden. Use a copy constructor, or better yet, a static factory method.
|
||||
|
||||
> See [Effective Java], 2nd Edition by Josh Bloch: Item 11: Override clone judiciously.
|
4
src/builder/resources/rules/NoFinalizer.md
Normal file
4
src/builder/resources/rules/NoFinalizer.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
Checks that the `finalize()` method from `Object` has not been overridden.
|
||||
|
||||
> See [Effective Java], 2nd Edition by Josh Bloch: Item 7: Avoid finalizers.
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue