Miscellaneous Checks

Checkstyle Logo

GenericIllegalRegexp

Description

A generic check for code problems - the user can search for any pattern. This is similar to a recursive grep, only that it's integrated in checkstyle.

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.

Properties

name description type default value
format illegal pattern regular expression ^$ (empty)
ignoreCase Controls whether to ignore case when searching. Boolean false
message message which is used to notify about violations, if empty then default(hard-coded) message is used. String ""(empty)

Examples

To configure the check for calls to System.out.println:

<module name="GenericIllegalRegexp">
    <!-- . matches any character, so we need to
         escape it and use \. to match dots. -->
    <property name="format" value="System\.out\.println"/>
</module>
      

To configure the check to find trailing whitespace at the end of a line:

<module name="GenericIllegalRegexp">
    <!-- \s matches whitespace character, $ matches end of line. -->
    <property name="format" value="\s$"/>
</module>
      

To configure the check to find case-insensitive occurrences of "debug":

<module name="GenericIllegalRegexp">
    <property name="format" value="debug"/>
    <property name="ignoreCase" value="true"/>
</module>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker

NewlineAtEndOfFile

Description

Checks whether files end with a new line.

Rationale: Any source files and text files in general should end with a newline character, especially when using SCM systems such as CVS. CVS will even print a warning when it encounters a file that doesn't end with a newline.

Properties

name description type default value
lineSeparator type of line separator One of "system" (system default), "crlf" (Windows-style), "cr" (Mac-style) and "lf" (Unix-style) system default

Examples

To configure the check:

<module name="NewlineAtEndOfFile"/>
      

To configure the check to always use Unix-style line separators:

<module name="NewlineAtEndOfFile">
    <property name="lineSeparator" value="lf"/>
</module>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

Checker

TodoComment

Description

A check for TODO: comments. Actually it is a generic regular expression matcher on Java comments. To check for other patterns in Java comments, set property format.

Properties

name description type default value
format pattern to check regular expression TODO:

Notes

Using TODO: comments is a great way to keep track of tasks that need to be done. Having them reported by Checkstyle makes it very hard to forget about them.

Examples

To configure the check:

<module name="TodoComment"/>
      

To configure the check for comments that contain WARNING:

<module name="TodoComment">
    <property name="format" value="WARNING"/>
</module>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker

Translation

Description

A FileSetCheck that ensures the correct translation of code by checking property files for consistency regarding their keys. Two property files describing one and the same context are consistent if they contain the same keys.

Consider the following properties file in the same directory:

      #messages.properties
      hello=Hello
      cancel=Cancel

      #messages_de.properties
      hell=Hallo
      ok=OK
      

The Translation check will find the typo in the german hello key, the missing ok key in the default resource file and the missing cancel key in the german resource file:

      messages_de.properties: Key 'hello' missing.
      messages_de.properties: Key 'cancel' missing.
      messages.properties: Key 'hell' missing.
      messages.properties: Key 'ok' missing.
      

Properties

name description type default value
fileExtensions file type extension to identify translation files. Setting this property is typically only required if your translation files are preprocessed and the original files do not have the extension .properties String Set properties

Example

To configure the check:

<module name="Translation"/>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

Checker

UpperEll

Description

Checks that long constants are defined with an upper ell. That is ' L' and not 'l'. This is in accordance to the Java Language Specification, Section 3.10.1.

Rationale: The letter l looks a lot like 1.

Examples

To configure the check:

<module name="UpperEll"/>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker

ArrayTypeStyle

Description

Checks the style of array type definitions. Some like Java-style: public static void main(String[] args) and some like C-style: public static void main(String args[])

Properties

name description type default value
javaStyle Controls whether to enforce Java style (true) or C style (false). Boolean true

Examples

To configure the check to enforce Java style:

<module name="ArrayTypeStyle"/>
      

To configure the check to enforce C style:

<module name="ArrayTypeStyle">
    <property name="javaStyle" value="false"/>
</module>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker

FinalParameters

Description

Check that method/constructor parameters are final. Interface methods are not checked - the final keyword does not make sense for interface method parameters as there is no code that could modify the parameter.

Rationale: Changing the value of parameters during the execution of the method's algorithm can be confusing and should be avoided. A great way to let the Java compiler prevent this coding style is to declare parameters final.

Properties

name description type default value
tokens blocks to check subset of tokens METHOD_DEF, CTOR_DEF METHOD_DEF, CTOR_DEF

Examples

To configure the check to enforce final parameters for methods and constructors:

<module name="FinalParameters"/>
      

To configure the check to enforce final parameters only for constructors:

<module name="FinalParameters">
    <property name="tokens" value="CTOR_DEF"/>
</module>
      

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker


Back to the Checkstyle Home Page