Rule forbidding whitespace-only lines ^[\s\t]+$

16 views
Skip to first unread message

Brett Randall

unread,
Dec 22, 2017, 10:38:45 PM12/22/17
to checkstyle
Hi,

Reasonably new to Checkstyle.  I hoped that this might be a standard rule, which it might be, but if-so I can't find it!

Is it possible to forbid line containing only whitespace characters?  Or especially only spaces and tabs, since these are most-commonly left on lines by some editors as remnant indentation.

In other words, forbid lines matching ^[\s\t]+$ (or "^[\\s\\t]+$" as a Java regex string).

Maybe there is a way that could be added as a regex.

How are others dealing with this - don't use Checkstyle to police empty-lines, or don't enforce anything about lines containing only whitespace?

Thanks
Brett

Павел Блудов

unread,
Dec 22, 2017, 10:51:39 PM12/22/17
to checkstyle

Maybe there is a way that could be added as a regex.


There is a bunch of samples:

The one you are looking for is "Trailing whitespace".

Brett Randall

unread,
Dec 24, 2017, 12:28:25 AM12/24/17
to checkstyle
Thanks! Too easy.  And since line-all-whitespace is just a special-case of trailing-whitespace.

I guess I still expected to find a Whitespace category rule for this case, but easy-enough to do with regex once you know to go there.

Brett
Reply all
Reply to author
Forward
0 new messages