checkstyle Command Line

Description

This document describes how to run checkstyle using the command line tool. The latest version of checkstyle can be found at http://checkstyle.sourceforge.net. This command line tool is included in the checkstyle distribution.

Installation

The easiest way is to include checkstyle-all-1.4.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:

  1. checkstyle-1.4.jar
  2. ANTLR 2.7.1 classes. antlr.jar is included in the distribution.
  3. Jakarta Regexp 1.2 classes. jakarta-regexp-1.2.jar is included in the distribution.

Usage

The command line usage is:

  java -D<property>=<value>  \
       com.puppycrawl.tools.checkstyle.Main \
       [-f <format>] [-o <toFile>] file...

Checkstyle will process the specified files and by default report errors to standard out in plain format. The options are:

The default behaviour of checkstyle can be changed by setting system properties using the -D<property>=<value> arguments to java. The following table describes what properties can be set:

Property Description
checkstyle.allow.tabs Indicates whether to allow tabs. Defaults to "no".
checkstyle.allow.protected Indicates whether to allow protected data. Defaults to "no".
checkstyle.allow.noauthor Indicates whether to allow no @author tag to be defined for class and interface Javadoc comments. Defaults to "no".
checkstyle.maxlinelen Specifies the maximum line length. Default value is defined here.
checkstyle.ignore.importlength Specifies whether to ignore the maximum line length for import statements. Defaults to "false".
checkstyle.maxmethodlen Specifies the maximum method length. Default value is defined here.
checkstyle.maxconstructorlen Specifies the maximum constructor length. Default value is defined here.
checkstyle.maxfilelen Specifies the maximum file length. Default value is defined here.
checkstyle.pattern.member Specifies the regular expression to match against member variables. Default value is defined here.
checkstyle.pattern.publicmember Specifies the regular expression to match against public member variables. Default value is defined here.
checkstyle.pattern.parameter Specifies the regular expression to match against parameters. Default value is defined here.
checkstyle.pattern.const Specifies the regular expression to match against static/final variables. Default value is defined here.
checkstyle.pattern.static Specifies the regular expression to match against static variables. Default value is defined here.
checkstyle.pattern.type Specifies the regular expression to match against type names. Default value is defined here.
checkstyle.header.file Specifies the file containing the header lines. Default is to not check.
checkstyle.header.ignoreline Specifies the line in the header to ignore when comparing. Default it to not ignore any line.
checkstyle.javadoc.scope Specifies the visibility scope where javadoc comments are checked. Valid values are "nothing", "public", "protected", "package", "private" and "anoninner". Defaults to "private".
checkstyle.ignore.imports Specifies whether to ignore checking import statements. Defaults to "no".
checkstyle.ignore.whitespace Specifies whether to ignore checking whitespace. Defaults to "no".
checkstyle.ignore.whitespace.cast Specifies whether to ignore checking for whitespace after a cast. Defaults to "no".
checkstyle.ignore.braces Specifies whether to ignore checking braces. Defaults to "no".
checkstyle.cache.file Specifies the name of a file that can be used to cache details of files that pass checkstyle. This can signicantly increase the speed of checkstyle on successive runs.

Older versions of the checkstyle task supported the boolean parameters checkstyle.javadoc.relax and checkstyle.javadoc.ignore. These parameters have been removed because they were conflicting with each other and the semantics of relaxJavadoc was not specified. The two parameters have been replaced by the checkstyle.javadoc.scope parameter. Instead of checkstyle.javadoc.ignore=true you can now use checkstyle.javadoc.scope=nothing. The behaviour of checkstyle.javadoc.relax=true is roughly the same as checkstyle.javadoc.scope=protected.

Examples

Run checkstyle on a file

  java  com.puppycrawl.tools.checkstyle.Main  Check.java

Run checkstyle on a file and allow tabs

  java  -Dcheckstyle.allow.tabs=yes \
        com.puppycrawl.tools.checkstyle.Main Check.java

Run checkstyle on a file and output to a file in XML format

  java  -Dcheckstyle.allow.tabs=yes  \
        com.puppycrawl.tools.checkstyle.Main \
        -f xml -o build/checkstyle_errors.xml Check.java

Run checkstyle on a file and disable pattern matching

  java  -Dcheckstyle.pattern.parameter=. \
        -Dcheckstyle.pattern.static=. \
        -Dcheckstyle.pattern.const=. \
        -Dcheckstyle.pattern.member=. \
        com.puppycrawl.tools.checkstyle.Main Check.java

Copyright © 2001 Oliver Burn. All rights Reserved.