-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Following the discussion at #17265 (comment)
I have read check documentation: https://checkstyle.org/checks/whitespace/whitespaceafter.html
I have read check documentation: https://checkstyle.org/checks/whitespace/whitespacearound.html
I have downloaded the latest cli from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
How it works Now:
cat > /tmp/DuplicateError.java << 'EOF'
/** some data. */
class DuplicateError {
/** method. */
void test(Object o) {
switch (o) {
case String s when (
s.equals("a"))->{
}
default -> {}
}
}
}
EOF
java -jar target/checkstyle-*-all.jar -c src/main/resources/sun_checks.xml /tmp/DuplicateError.java
Starting audit...
[ERROR] /tmp/DuplicateError.java:7:25: '->' is not followed by whitespace. [WhitespaceAfter]
[ERROR] /tmp/DuplicateError.java:7:25: '->' is not followed by whitespace. [WhitespaceAround]
[ERROR] /tmp/DuplicateError.java:7:25: '->' is not preceded with whitespace. [WhitespaceAround]
Audit done.
The first and second violations are duplicates (same message from different checks).
Is your feature request related to a problem? Please describe.
sun_checks.xml uses default tokens for both WhitespaceAfter and WhitespaceAround checks. These default tokens overlap, causing duplicate violations for the same issue at the same code location.
In the example above, line 7 column 25 shows:
'->' is not followed by whitespace. [WhitespaceAfter]
'->' is not followed by whitespace. [WhitespaceAround]
This is the same violation reported twice by two different checks.
Describe the solution you'd like
Add explicit tokens to WhitespaceAfter in sun_checks.xml to remove overlapping tokens that are already covered by WhitespaceAround.
# Expected output (no duplicate):
[ERROR] DuplicateError.java:7:25: '->' is not followed by whitespace. [WhitespaceAround]
[ERROR] DuplicateError.java:7:25: '->' is not preceded with whitespace. [WhitespaceAround]