Add NoWhitespaceBeforeCaseDefaultColon

commit-id:3265f01a
This commit is contained in:
Paul Campbell 2021-08-11 16:34:55 +01:00
parent a5b7542ac3
commit e34168f6bb
2 changed files with 36 additions and 0 deletions

View file

@ -1538,3 +1538,10 @@ rules:
enabled: true
source: SEVNTU
uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/MoveVariableInsideIfCheck.html
-
name: NoWhitespaceBeforeCaseDefaultColon
parent: TREEWALKER
level: LAYOUT
enabled: true
source: CHECKSTYLE
uri: https://checkstyle.sourceforge.io/config_whitespace.html#NoWhitespaceBeforeCaseDefaultColon

View file

@ -0,0 +1,29 @@
Checks that there is no whitespace before the colon in a switch block. .
Valid:
````
switch(1) {
case 1:
break;
case 2:
break;
default:
break;
}
````
Invalid:
````
switch(2) {
case 2: // ok
break;
case 3, 4
: break; // violation, whitespace before ':' is not allowed here
case 4,
5: break; // ok
default
: // violation, whitespace before ':' is not allowed here
break;
}
````