#457 Warning for unwanted blank lines.

Check (274)
Deepak Jain


Currently checkstyle doesn't issue any warnings for unwanted blank lines in the code.
Can you please add a feature for that.

Thanks & Regards


  • Lars Kühne

    Lars Kühne - 2007-05-01

    Logged In: YES
    Originator: NO

    Please elaborate: When is a blank line 'unwanted'?

  • Dale King

    Dale King - 2007-05-07

    Logged In: YES
    Originator: NO

    I personally, have some internalized rules for the use of blank lines or as I prefer to think of it as vertical separation since a line with only a brace on it comes into play as well. The question is how to generalize it enough for use in checkstyle.

    Some simple rules that could be valuable that I can think of off the top of my head:

    • Put a limit on the number of consecutive blank lines in different contexts such as within a method, within the class definition, or at the top level.
    • Do not allow a blank line to follow an opening brace or to precede a closing brace.

    One of my own rules is that anything that causes branching behavior (if, for, while, break, continue, return, throw, and sometimes method calls) must be separated from the linear code that surrounds it. That separation can either be a blank line or may be a brace only line.

    So if I have an if:

    bar = getFoo();
    if( bar == baz )
    throw biz;

    The if is not correct because it must have a blank line before and after it. The throw is OK because the braces form the separation.

    The same rule partially applies to method calls, but it depends on the intent of the call. If the call is a simple getter such as getFoo then the blank line rule is not triggered. If the call is conceptually a big operation as perhaps doBibble is then that would trigger the rule. That is something that is probably not checkable

    The goal is to make the structure of the code more visible using visual clues. If see this line separated from others there is a bit more complexity to look at. If I see a group of lines with no separation then those are a unit that doesn't have a lot of hidden complexity inside.

  • Roman Ivanov

    Roman Ivanov - 2016-02-28
    • status: open --> closed
    • Group: --> Future

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks