Currently checkstyle doesn't issue any warnings for unwanted blank lines in the code.
Can you please add a feature for that.
Thanks & Regards
Logged In: YES
Please elaborate: When is a blank line 'unwanted'?
Logged In: YES
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:
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 )
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.
we are already working on this https://github.com/checkstyle/checkstyle/issues/2944
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.