#9 Checkstyle should check indention


I think, Checkstyle should also be able to check the
indention of files. It should be definable how many
spaces must be used for a single level of indention and
wether tabs are allowed for indention, including a
settable tabstop value.

Default should be 4 spaces indention (vimmers call that
shiftwidth) and a tab size of 8 spaces (vimmers call
that tabstop) with disallowing the use of tabs.

Changes in the defaults should also allow the following
setting (which I prefer):
A single tab for indention, forbidding the use of
spaces for indention at all. (Tab size is of no
interest then)


  • Oliver Burn
    Oliver Burn

    Logged In: YES

    I agree this would be a useful check. However, this would
    be a very difficult thing to implement in a flexible
    manner. Indentation engines (like Emacs C-Mode) require lots
    of configuration.

    I will postpone doing this until a very long rainy day.

  • Logged In: NO

    I agree that this is an important feature and it is, in my opinon,
    the only major thing missing in the current CheckStyle
    implementation. Checking indentation, however, is a tedious and
    complex task (as mentioned by oburn previously).

    One way to handle this issue would be to implement a simple
    indentation check first. The indentation level could be deduced
    by counting '{' characters, and the number of spaces could then
    be counted in front of fields and statements. When a statement
    is broken into several lines, one could do a simple check that it
    has at least the current indentation level + 1.

    I know that this solution would not solve the full problem, nor
    would it be applicable for everyone. People not enforcing the use
    of '{' characters in if, while and do would have problems. Also, the
    horrible details of full indentation of expressions and statements
    spanning multiple lines would be avoided. However, I do believe
    that this simple solution would be adequate for most users
    (including myself of course). Our main problem is people
    indenting whole blocks of code with the wrong number of spaces,
    which would be found pretty direct by this method. I wouldn't be
    too worried about enforcing the exact details of intra-statement
    indentation (as there are not really any complete rules for that).

    Anyway, those are just my thoughts on this issue.


    /Per, per ( at ) percederberg.net

  • didier dulac
    didier dulac

    Logged In: YES

    What about using a Jindent like tool to cope with indentation ?

  • Lars Kühne
    Lars Kühne

    Logged In: YES

    I agree that Jindent can be a useful tool if you start with
    a heap of code that does not follow you local conventions.

    On the other hand most users (including me) like to use
    checkstyle in their automated build process because they can
    be sure that their source will not be modified. I'd like to
    make sure that release code is correctly indented but I
    wouldn't want to include a tool like jindent (or astyle or
    jrefactory or ...) in my build process because it does not
    make such a guarantee.

    You are right, though, that we might be able to learn
    something from the mentioned projects (what are the options,
    how do they implement their checks)

  • Lars Kühne
    Lars Kühne

    Logged In: YES

    I have attached John Richardson's tar file to the request,
    so new users can start testing it.

    To try it out, add the file
    to the corresponding folder of the Checkstyle source tree,
    recompile Checkstyle, and add the following module to the

    <module name="Indentation"/>

    See the docs folder in the tar file for the config options

  • Lars Kühne
    Lars Kühne

    John Richardson's Feb 26 email to the devel list

  • Logged In: YES

    I'm sorry for the added spam of this test comment. I'm
    testing to see if I can attach files to this RFE after
    adding a comment. I have an interest in this feature and may
    want to attach files to the RFE, but can't for some reason.
    Hopefully I'll be able to after adding a comment...

  • Logged In: YES

    The indentation check is documented now, so I mark it as implemented. If you want more funcionality/configuration options for it fell free to sumbit new requests.