Keeping your Java Coding standards up using CheckStyle

In some circumstances it is useful to follow some coding guidelines. Most companies that produce software have such guidelines defined and enforced. But how do we check that these guidelines are all being followed? Opening all the source files one by one to check them visually by reading code is a time consuming task not many people would accept doing. Even if a developer accepts such practice, he’ll certainly not enjoy its job if he has to correct all the errors he sees there!

Thankfully, a nice little tool exists for automating such job. Let me introduce CheckStyle, a nice utility that takes a coding style guidelines’ file described in XML and then runs through your sources in order to generate reports on what needs to be changed to be compliant to the rules. As an example, the Sun’s Java developer standard coding guidelines are included in an example XML file.

It gets even nicer as this tool can be included in your ant build script and integrated with cruisecontrol’s automated build system generating graphs of your CheckStyle performances in order to have you forced to keep coding standards up! A plugin exists for the eclipse IDE so each developer can check its source before commiting.

Moreover, it is possible to have an SVN pre-commit hook setup so that no developer can commit code that does not comply to the coding guidelines that you’ve decided upon!

Leave a Reply