NoWhitespaceBeforeCaseDefaultColon
Since Checkstyle 8.45
Description
Checks that there is no whitespace before the colon in a switch block.
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="NoWhitespaceBeforeCaseDefaultColon"/>
</module>
</module>
Example:
class Example1 {
void example() {
switch(1) {
case 1 : // violation '':' is preceded with whitespace'
break;
case 2:
break;
default : // violation '':' is preceded with whitespace'
break;
}
switch(2) {
case 2:
break;
case 3, 4
: break; // violation '':' is preceded with whitespace'
case 5,
6: break;
default
: // violation '':' is preceded with whitespace'
break;
}
switch(DayOfWeek.MONDAY) {
case MONDAY, FRIDAY, SUNDAY: System.out.println(" 6"); break;
// violation below '':' is preceded with whitespace'
case TUESDAY : System.out.println(" 7"); break;
}
}
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks.whitespace