Skip to content
Checkstyle rules for GantSign Java code style
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
checkstyle-lenient.xml
checkstyle.xml
configuration_1_3.dtd

README.md

GantSign Checkstyle Configuration

Build Status License

Checkstyle configuration for Java code written by GantSign.

Severity Level

The default severity level is error; the goal is to ensure quality rather than suggest it.

@SuppressWarnings Support

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.

Google Java Style Guide compatibility

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.

Additional rules for GantSign's code

  • DeclarationOrder

    • Declaration order: enforce declarations appear in the following order:

      1. Class (static) variables. First the public class variables, then protected, then package level (no access modifier), and then private.
      2. Instance variables. First the public class variables, then protected, then package level (no access modifier), and then private.
      3. Constructors
      4. Methods
  • RedundantModifier

    • Modifiers: ban redundant modifiers (e.g. public for methods in an interface).
  • RedundantImport

    • Imports: ban redundant imports.
  • MissingDeprecated

    • Deprecated: require @Deprecated annotation and @deprecated JavaDoc tag if either are present.
  • MissingOverride

    • Override: require @Overrides annotation if @inheritDoc JavaDoc tag is present.
  • PackageAnnotation

    • Package annotations: ensure package annotations are only used in the package-info.java file.
  • InterfaceIsType

    • Interfaces: make sure interfaces contain methods and not just constants; no more interfaces like javax.swing.SwingConstants.
  • CovariantEquals

    • 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).
  • EqualsHashCode

    • HashCode: if you override equals() you must also override hashCode().
  • MagicNumber

    • Numbers: ban magic numbers (i.e. numbers not defined with constants); sensible exclusions apply (e.g. array initializers).
  • SimplifyBooleanExpression

    • Boolean logic: force obvious simplification of boolean logic:

      e.g.

      if (booleanValue == true)

      should be:

      if (booleanValue)
  • SimplifyBooleanReturn

    • Boolean returns: ban unnecessary if else blocks for boolean returns:

      e.g.

      if (booleanValue) {
          return true;
      } else {
          return false;
      }

      should be:

      return booleanValue;
  • StringLiteralEquality

    • String: ban use of identity equals on strings literals.
  • ExplicitInitialization

    • Initialization: ban explicitly initializing fields to their default values.
  • IllegalInstantiation

    • Wrapper types: ban using constructor of wrapper types.
  • IllegalType

    • Collections: enforce using Collection interfaces for return types, parameter types and fields for basic collection implementation types.
  • MutableException

    • Exceptions: ban mutable exceptions; be aware this only checks the fields in the exception are declared final.
  • IllegalThrows

    • Exception handling: ban throwing java.lang.Throwable, RuntimeException, Error, Throwable, java.lang.Error and java.lang.RuntimeException.

License

This software is licensed under the terms in the file named "LICENSE" in the root directory of this project.

Author Information

John Freeman

GantSign Ltd. Company No. 06109112 (registered in England)

You can’t perform that action at this time.