Checkstyle configuration for Java code written by GantSign.
The default severity level is error
; the goal is to ensure quality rather than
suggest it.
Because the rules are quite strict @SuppressWarnings
can be used to suppress
errors where necessary. It is the responsibility of the code reviewer to judge
whether suppression of the rule is the appropriate solution.
Gantsign rules are based on the Google Java Style Guide Checkstyle rules. It's recommended that your source code be automatically formated as part of your build. You can find formatting tools at https://github.com/google/google-java-format).
Any file compliant with these rules is compliant with Google Java Style Guide Checkstyle rules. The reverse isn't necessarily true as the GantSign rules include some additional checks.
-
-
Declaration order: enforce declarations appear in the following order:
- Class (
static
) variables. First thepublic
class variables, thenprotected
, then package level (no access modifier), and thenprivate
. - Instance variables. First the
public
class variables, thenprotected
, then package level (no access modifier), and thenprivate
. - Constructors
- Methods
- Class (
-
-
- Modifiers: ban redundant modifiers (e.g. public for methods in an interface).
-
- Imports: ban redundant imports.
-
- Deprecated: require
@Deprecated
annotation and@deprecated
JavaDoc tag if either are present.
- Deprecated: require
-
- Override: require
@Overrides
annotation if@inheritDoc
JavaDoc tag is present.
- Override: require
-
- Package annotations: ensure package annotations are only used in the
package-info.java
file.
- Package annotations: ensure package annotations are only used in the
-
- Interfaces: make sure interfaces contain methods and not just constants;
no more interfaces like
javax.swing.SwingConstants
.
- Interfaces: make sure interfaces contain methods and not just constants;
no more interfaces like
-
- Equals: if you define your own type-specific equals method e.g.
Person.equals(Person)
, you must also override the default equals method e.g.Person.equals(Object)
.
- Equals: if you define your own type-specific equals method e.g.
-
- HashCode: if you override
equals()
you must also overridehashCode()
.
- HashCode: if you override
-
- Numbers: ban magic numbers (i.e. numbers not defined with constants); sensible exclusions apply (e.g. array initializers).
-
-
Boolean logic: force obvious simplification of boolean logic:
e.g.
if (booleanValue == true)
should be:
if (booleanValue)
-
-
-
Boolean returns: ban unnecessary
if
else
blocks for boolean returns:e.g.
if (booleanValue) { return true; } else { return false; }
should be:
return booleanValue;
-
-
- String: ban use of identity equals on strings literals.
-
- Initialization: ban explicitly initializing fields to their default values.
-
- Wrapper types: ban using constructor of wrapper types.
-
- Collections: enforce using Collection interfaces for return types, parameter types and fields for basic collection implementation types.
-
- Exceptions: ban mutable exceptions; be aware this only checks the fields in the exception are declared final.
-
- Exception handling: ban throwing
java.lang.Throwable
,RuntimeException
,Error
,Throwable
,java.lang.Error
andjava.lang.RuntimeException
.
- Exception handling: ban throwing
This software is licensed under the terms in the file named "LICENSE" in the root directory of this project.
John Freeman
GantSign Ltd. Company No. 06109112 (registered in England)