Skip to content

Commit 0c3c520

Browse files
graememorganError Prone Team
authored andcommitted
Expand SuppressWarningsWithoutExplanation to cover more warning types.
I am confused why this initially only applied to deprecation, while the markdown mentions _other_ types. Of course, all should have a comment based on the style guide, so I've genericised the documentation too. Fixes external #5218 PiperOrigin-RevId: 826084579
1 parent 114356c commit 0c3c520

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/SuppressWarningsWithoutExplanation.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
2121
import static com.google.errorprone.matchers.Description.NO_MATCH;
2222
import static com.google.errorprone.matchers.Matchers.allOf;
23+
import static com.google.errorprone.matchers.Matchers.anyOf;
2324
import static com.google.errorprone.matchers.Matchers.hasArgumentWithValue;
2425
import static com.google.errorprone.matchers.Matchers.isSameType;
2526
import static com.google.errorprone.matchers.Matchers.stringLiteral;
@@ -48,8 +49,8 @@
4849
* Finds occurrences of {@code @SuppressWarnings} where there is definitely no explanation for why
4950
* it is safe.
5051
*
51-
* <p>The Google style guide mandates this for <em>all</em> suppressions; this is only matching on
52-
* {@code deprecation} as a trial.
52+
* <p>The Google style guide mandates this for <em>all</em> suppressions; we're matching on a subset
53+
* to start which seem important.
5354
*/
5455
@BugPattern(
5556
summary =
@@ -64,7 +65,12 @@ public final class SuppressWarningsWithoutExplanation extends BugChecker
6465
private static final Matcher<AnnotationTree> SUPPRESS_WARNINGS =
6566
allOf(
6667
isSameType(SuppressWarnings.class),
67-
hasArgumentWithValue("value", stringLiteral("deprecation")));
68+
hasArgumentWithValue(
69+
"value",
70+
anyOf(
71+
stringLiteral("deprecation"),
72+
stringLiteral("rawtypes"),
73+
stringLiteral("unchecked"))));
6874

6975
private final boolean emitDummyFixes;
7076

docs/bugpattern/SuppressWarningsWithoutExplanation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Suppressions for `unchecked` or `rawtypes` warnings should have an accompanying
2-
comment to explain why the javac warning is safe to ignore.
1+
`@SuppressWarnings` should have an accompanying comment to explain why the javac
2+
warning is safe to ignore.
33

44
Rather than just suppressing the warning:
55

0 commit comments

Comments
 (0)