From: #17236
Duplicate violations are getting logged for WhitespaceAround and WhitespaceAfter Checks in google_style
$ cat DuplicateError.java
/** some data. */
class DuplicateError {
/** method. */
void test(Object o) {
switch (o) {
case String s when (
s.equals("a"))->{
}
default -> {}
}
}
}
$ java -jar checkstyle-10.25.0-all.jar -c google_checks.xml DuplicateError.java
Starting audit...
[WARN] /mnt/5D92528E6B945467/test/testing/DuplicateError.java:8:25: '->' is not followed by whitespace. [WhitespaceAfter]
[WARN] /mnt/5D92528E6B945467/test/testing/DuplicateError.java:8:25: WhitespaceAround: '->' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3) [WhitespaceAround]
[WARN] /mnt/5D92528E6B945467/test/testing/DuplicateError.java:8:25: WhitespaceAround: '->' is not preceded with whitespace. [WhitespaceAround]
Audit done.
The first two violations are from different checks but they are saying the same thing so these violations are duplicate.
Following are some more examples from inputs:
|
} |
|
// 2 violations 3 lines above: |
|
// ''when' is not followed by whitespace.' |
|
// ''when' is not followed by whitespace.' |
|
public static class IntEnumValueType2<E extends Enum<E>& IntEnum> { |
|
// 2 violations above: |
|
// ''&' is not preceded with whitespace.' |
|
// ''&' is not preceded with whitespace.' |
|
while(x == 0) { |
|
// 2 violations above: |
|
// ''while' is not followed by whitespace.' |
|
// ''while' is not followed by whitespace.' |
|
} while(x == 0 || y == 2); |
|
// 2 violations above: |
|
// ''while' is not followed by whitespace.' |
|
// ''while' is not followed by whitespace.' |
|
try{ |
|
// 3 violations above: |
|
// ''try' is not followed by whitespace.' |
|
// ''try' is not followed by whitespace.' |
|
// ''{' is not preceded with whitespace.' |
In some case, the both violations in the config for WhitespaceAroundCheck's are getting triggered.
|
<message key="ws.notFollowed" |
|
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks |
|
may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/> |
As part of the fix, we need to find out for which Tokens in config this overlapping is happening and fix it.
From: #17236
Duplicate violations are getting logged for WhitespaceAround and WhitespaceAfter Checks in google_style
The first two violations are from different checks but they are saying the same thing so these violations are duplicate.
Following are some more examples from inputs:
checkstyle/src/it/resources-noncompilable/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundWhen.java
Lines 12 to 15 in 512dfb4
checkstyle/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputGenericWhitespace.java
Lines 78 to 81 in 679439e
checkstyle/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java
Lines 17 to 20 in 679439e
checkstyle/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java
Lines 32 to 35 in 679439e
checkstyle/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundBasic.java
Lines 49 to 53 in 679439e
In some case, the both violations in the config for
WhitespaceAroundCheck's are getting triggered.checkstyle/src/main/resources/google_checks.xml
Lines 159 to 161 in 679439e
As part of the fix, we need to find out for which Tokens in config this overlapping is happening and fix it.