You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
➜ src /usr/lib/jvm/java-14-openjdk/bin/javac --enable-preview --source 14 TestClass.java
➜ src cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="WhitespaceAround"/>
</module>
</module>
➜ src cat TestClass.java
public class TestClass {
int howMany1(int k) {
int x = 2;
int number = 42;
boolean bool = false;
switch (k) {
case 1:
int y= (2); // violation
break;
case 2:{ // violation
int otherNumber = 42;
int z = x + 2;
x = z;
break;
}
case (3 ):{ // violation
if(bool = true) { // violation
}
int a = x + 3;
x = a;
break;
}
default:
int b = 4;
x = b;
}
return x;
}
int howMany2(int k) {
int x = 2;
int number = 42;
boolean bool = false;
return switch (k) {
case 1 ->{ // violation x2
int y= (2); // violation
yield y;
}
case ( 2) ->{ // violation x2
int otherNumber = 42;
int z = ( x + 2);
yield ( otherNumber);
}
case (3 ) ->{ // violation x2
if(bool = true ) { // violation
}
int a = x + 3;
x = a;
yield a;
}
default -> {
int b = (2 );
yield b;
}
};
}
int howMany3(int x) {
int inner = 8;
boolean bool = false;
return switch (x) {
case 1:
int y= (2); // violation
yield y;
case 2:{ // violation
int otherNumber = 42;
int z = inner = x + 2;
x = z;
yield (otherNumber);
}
case (3 ): //violation
if(bool = true ) { // violation
}
int a = x + 3;
x = a;
yield a;
default:
int b = (2 );
yield b;
};
}
}
➜ src java -jar /home/nick/IdeaProjects/checkstyle/target/checkstyle-8.36-SNAPSHOT-all.jar -c config.xml TestClass.java
Starting audit...
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:9:22: '=' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:11:20: '{' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:17:23: '{' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:18:17: 'if' is not followed by whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:36:20: '->' is not followed by whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:36:22: '{' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:37:22: '=' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:40:23: '->' is not followed by whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:40:25: '{' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:45:23: '->' is not followed by whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:45:25: '{' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:46:17: 'if' is not followed by whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:64:22: '=' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:66:20: '{' is not preceded with whitespace. [WhitespaceAround]
[ERROR] /home/nick/Desktop/enhanced-switch/src/TestClass.java:73:17: 'if' is not followed by whitespace. [WhitespaceAround]
Audit done.
Checkstyle ends with 15 errors.
This check works as intended, so I think that we can close this issue. The switch rule with a LAMBDA should count as two, since unlike the COLON in a regular switch, it should have whitespace around it.
The text was updated successfully, but these errors were encountered:
Child of #8658
Check documentation: https://checkstyle.sourceforge.io/config_whitespace.html#WhitespaceAround
Checks that a token is surrounded by whitespace.
This check works as intended, so I think that we can close this issue. The switch rule with a LAMBDA should count as two, since unlike the COLON in a regular switch, it should have whitespace around it.
The text was updated successfully, but these errors were encountered: