I'm adding Checkstyle to my project, but the rule to detect whitespaces is not good enough (RegexpSingleline):
(?<=\S)\s+$
It detects trailing spaces and ignores lines with whitespaces only (it should allow indentated blank lines). It works fine most of the time, but it complains about javadoc/multiline comments using a blank line:
/**
* Some text
*
* More text
*/
The empty line between the two lines is 'asterisk-whitespace' (default Eclipse formatting), thus triggering the rule, and so far I couldn't make it ignore this special situation. How can I fix this regexp for this case?
Thanks!
Note: it does not need to be a multiline check and verify if the line is indeed part of a comment, it is fine enough as single line.
Summarizing the desired rules...
The regex should match lines with trailing spaces:
x = y;
void function() {
Except when there is nothing but whitespaces on the line (a single asterisk before the last whitespace is allowed in this exception, but ONLY when the asterisk the the only non-whitespace char):
(only whitespaces here, all ok)
/**
* (this text is not here, and this line is ok - this case is my uncovered situation)
*/
Replace the original expression
\s+$
to
(?<!\*)\s+$|\*\s\s+$
The left side of the pipe looks for whitespaces at the beginning of the line, if it's beginning with an *. The right side of the pipe looks for double whitespaces at the end of the line.
Edit:
In the meantime, the Eclipse code formatter fixed the issue with the trailing spaces in empty JavaDoc lines. Hopefully, we never have to adjust the Checkstyle regexp here again ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With