Checkstyle Home Page

Checkstyle

Documentation

SourceForge

Developers

Overview

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.

By default it supports the Sun Code Conventions. However, Checkstyle is highly configurable.

My experience from using a similar proprietary tool at a previous employer was that it increased the productivity of code reviews. This is because it allowed the reviewers to get on with reviewing the code and not get into "style" debates.

Features

The things that checkstyle checks for are:

  • Unused or duplicate import statements. Note: this can be turned off.
  • Javadoc comments are defined for class, interface, variable and method declarations. Note: This can be made to check only public and protected declarations.
  • Javadoc tags for a method match the actual code.
  • The file starts with a specified header. This is useful to ensure that a file has a copyright notice.
  • An @author tag exists for class and interface Javadoc comments. Note: this can be turned off.
  • Format of variable names match specified regular expressions. For example, can enforce that all static variables must start with "s".
  • Format of class and interface names match a specified regular expression.
  • Format of parameter names match a specified regular expression.
  • Variables that are not declared as private or protected.
  • Correct use of white space around binary and unary operators. For example, x -=- 1; is illegal, whereas x -= -1; is not.
  • Ensure white space follows casts and commas. For example both x = (File)obj and run(arg1,arg2) are illegal, whereas x = (File) obj and run(arg1, arg2) are not. Note: these checks can be turned off.
  • Ensure {}'s are used for if/while/for/do constructs.
  • Lines do not contain tabs. Note: this check can be turned off.
  • Lines are not longer than a specified length.
  • Methods/Constructors are not longer than a specified number of lines.
  • Files are not longer than a specified number of lines.

Download

The latest release of Checkstyle can be downloaded from the SourceForge download page.

If you want to live on the bleeding edge, you can checkout the current development code from CVS and compile yourself.

Related Tools

Checkstyle is most useful if you integrate it in your build process or your development environment. The distribution includes:

  • An Ant task.
  • A command line tool.

Additionally

If you have written a plugin for other IDEs, like Netbeans or Eclipse, please let us know, so we can provide a link here.


Copyright © 2001 Oliver Burn. All rights Reserved.