Checkstyle 3.1 Released - it's not just about layout


News: Checkstyle 3.1 Released - it's not just about layout

  1. Checkstyle is a tool to run a set of checks over Java source code. Traditionally it has been used to enforce a coding standard, but release 3.x architecture changes all that - it's not just about layout anymore.

    The 3.x architecture is based around pluggable modules. This means that users can now write their own checks without changing the sourcecode of Checkstyle itself. A detailed tutorial is provided on how to write a check at

    Using the new pluggable modules it is possible to developed sophisticated checks for J2EE projects. For example, Checkstyle now comes with checks to detect:

        * Usage of the flawed double checked locking pattern
        * Instantiation of illegal objects. Great for finding where people are violating J2EE container requirements by creating sockets or threads

    Great care was taken in designing the new architecture to not sacrifice the excellent performance of Checkstyle. The configuration has been completely revamped and it is now possible to configure down to the token level. So for example, whitespace checking can be configured to only look at the "==" token.

    The 3.1 release of Checkstyle provides standard checks in many areas including:

        * Javadoc Comments
        * Naming Conventions
        * Headers
        * Imports
        * Size Violations
        * Whitespace
        * Modifiers
        * Blocks
        * Coding Problems
        * Class Design
        * Miscellaneous Checks

    Plenty of documentation is available at

    Third-party plug-ins are available for Maven, jEdit, NetBeans, Centipede, JBuilder, Eclipse/WSAD, Emacs JDE, BlueJ.


    Threaded Messages (13)

  2. The real question is: Does it give a beauty quotient? You know, the one where Cedric's code examples always score lower than mine? ;-)


    Cameron Purdy
    Tangosol, Inc.
    Coherence: Easily share live data across a cluster!
  3. The real question is: Does it give a beauty quotient? You know, the one where Cedric's code examples always score lower than mine? ;-)

    If such a plug-in exists, I don't believe is is written in a Turing-complete language.

  4. It does do that.... and more[ Go to top ]

    The author just wrote to me to tell me that it does the following:

    if [code belongs to cedric or cameron] {
       1. laugh
       2. Generate Ruby code from it (the 100 line example turns into 3)
       3. laugh again
  5. Great to see the development of this tool continuing. What interesting with the Checkstyle 3+ releases it the move anway from just style checking, to include more complex code analysis check. This is more akin to what you would do in a formal code review.

    I think to tool is now best use with 2 different configuration's one for your daily grind style checks (best used in one of the Eclipse checkstyle plugins) and confirguration for a more comprehensive code review.
  6. to include more complex code analysis check

    Has anyone looked at the IntelliJ Code Inspection reports?
    Simply amazing.

    Also worthwhile noting that the checkstyle plugin in the imminent RC1 release of Maven (yay! Finally!) supports this release of checkstyle.

  7. IDEA Code Inspections[ Go to top ]

    Yes, the Code Inspection functionality in IDEA is very impressive. Since IDEA has a "deep understanding" of the code in a project, it can produce these reports. At the moment Checkstyle focuses on checking each file seperately. this is a feature and a limitation.
  8. We've been using Checkstyle on a 300K+ line codebase for over a year now. All files must pass Checkstyle before being committed to the base. I think its fair to say that its prevented many a broken window.

  9. PMD?[ Go to top ]

    Anyone know how this compares to PMD? We use that and it sounds like Checkstyle does some similar stuff. One thing I really like about PMD is how easy it is to write new rules (uses XSL) and that it can also detect copy-paste code.
  10. Writing plugins is easy[ Go to top ]

    Oliver and the group have a done a fantastic job with the new architecture. It can literally take as little as a couple of hours for your first simple custom check and it just gets easier. I've recently written a whole load of them to codify "best practices" we use. It was a breeze. Makes most manual code reviews that I've been involved in seem like a joke. :-)

    Checkstyle is not just for formatting anymore. It goes way beyond that.

    As for duplicate code checking, watch this space. There will be something coming within days. It will be licensed similarly to clover/jcoverage so free for open source/free/non-commercial software and minimal cost per project for commercial use. Criticall it will have a checkstyle plugin. I'm just getting the download and packaging sorted out now.


  11. Duplicate Code Analyser[ Go to top ]

    As requested, here is a link to Simian

    It has a plugin for checkstyle (as well as ant and command line interface).


  12. "May your bits rot in hell"[ Go to top ]

    We first started to use checkstyle over a year ago on a pretty high profile project, integrated into a continuous integration set-up so that we'd all get an hourly e-mail listing everyone's sins in painful detail :) Despite the fact that the half the team consisted of contractors, the end result was some of the best-commented, most consistent and, yes, bug free code we've ever produced.

    It wasn't a hit with everyone, though. One of the contractors' last commit message was (approximately) "Goodbye checkstyle. I shall not miss you. May your bits rot in hell."

    Needless to say, I love checkstyle, and we've been using it ever since. I'm looking forward to using the new release.

     - Peter
  13. Lint? (EOM)[ Go to top ]

  14. I'm sold[ Go to top ]

    I added checkstyle 3.1 to the Hibernate core (approx 46k LOC) Ant build two days ago. I'm very impressed, especially in comparison to code formatters.

    I did notice that the array [] position checker has a bug which causes checkstyle to NPE on a couple of classes. But I can live without that check ;)