Since Checkstyle 6.19
validateComments
to true.
Setting validateComments
to false will ignore cases like:
int i; // Multiple whitespaces before comment tokens will be ignored. private void foo(int /* whitespaces before and after block-comments will be ignored */ i) {
Sometimes, users like to space similar items on different lines to the same column position for easier reading. This feature isn't supported by this check, so both braces in the following case will be reported as violations.
public long toNanos(long d) { return d; } // 2 violations public long toMicros(long d) { return d / (C1 / C0); }
name | description | type | default value | since |
---|---|---|---|---|
validateComments | Control whether to validate whitespaces surrounding comments. | boolean | false |
6.19 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="SingleSpaceSeparator"/> </module> </module>
Example:
class Example1 { int foo() { // violation 'Use a single space' return 1; // violation 'Use a single space' } int fun1() { return 3; } void fun2() {} // violation 'Use a single space' }
To configure the check so that it validates comments:
<module name="Checker"> <module name="TreeWalker"> <module name="SingleSpaceSeparator"> <property name="validateComments" value="true"/> </module> </module> </module>
Example:
class Example2 { // violation below 'Use a single space' void fun1() {} // 2 whitespaces before the comment starts // violation below 'Use a single space' void fun2() { return; } /* 2 whitespaces before the comment starts */ // violation below 'Use a single space' /* 2 whitespaces after the comment ends */ int a; String s; /* OK, 1 whitespace */ /** * This is a Javadoc comment */ int b; // 2 whitespaces after the javadoc comment ends // violation above 'Use a single space' float f1; /** * OK, 1 white space after the doc comment ends */ float f2; }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.whitespace