Checkstyle rules

These rules are used by the Maven Checkstyle plugin.

The rules are designed to take advantage of the Eclipse default formatting settings and code clean-up as much as possible. However, it also works with the Java code style established in the organization.

It also disables some of the styles that the does not make sense in all projects, although it does extend some rules to make things stricter. The following sections itemize the changes to the default Eclipse Checkstyle rule set.

AvoidInlineConditionals

Although some junior developers may find this confusing, this short cut can help readability with many translations to and from boolean values.

final char flagCharacter = flag ? 'Y' : 'N';

versus

final char flagCharacter;
if (flag) {
  flagCharacter = 'Y';
} else {
  flagCharacter = 'N';
}

DesignForExtension

Although in theory this check is a good idea, a lot of JEE system components especially JPA cannot function correctly with final classes or methods. As such this check is disabled by default.

FileTabCharacter

Eclipse formatting uses tab characters by default. To prevent having to reconfigure Eclipse, this was disabled. However, the M2E Codestyle Maven Plugin combined with the Java code style will ensure that spaces are already used.

HiddenField

This rule is enabled with the following modifiers:

  • ignoreConstructorParameter: "true"
  • ignoreSetter: "true"

    These modifiers were enabled to allow us to do the following without having to make up new names for the arguments:

    public Constructor(final Object field) {
      this.field = field;
    }
    
    public void setField(final Object field) {
      this.field = field;
    }

Imports

The rules associated with this ruleset are not just enabled, but flagged as ERROR in the code. This will flag any developers who do not execute Organize Imports on the IDE.

LineLength

Line lengths are determined automatically with the Eclipse formatter. That is why this check is disabled.

MagicNumber

Although this check is a good idea. It quickly becomes impractical because it introduces another level of indirection which may lead to many one-off constants that make the source harder to read.

RegexpSinglelineJava

Only Java code was considered to be checked for regular expressions. These checks all have the parameter ignoreComments set to true. The primary reason was that Eclipse default formatting adds one space at the end of each empty JavaDoc line. The following lists all the rules that use the RegexpSinglelineJava module.

\s+$

triggers Line has trailing spaces. As noted this is only on Java code.

\bSystem\.out\b

triggers Outputting to system out. The code should use logging facilities.

\bSystem\.err\b

triggers Outputting to system err. The code should use logging facilities.

\.printStackTrace\(\)\b

triggers Printing stack trace. The code should use logging facilities. This only pertains to the no-arg version of printStackTrace as we may use this method to write the stack trace to a stream if needed.

SuppressionCommentFilter

This was explicitly enabled to allow developer leads to disable checks on some blocks of the code if there was no way around the issue that would not reduce readability.