Is there a way to prevent or discourage the use of SuppressWarnings? #4223
-
Instead of manually removing all the suppressions in a codebase I would like to run PMD and ignore them. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Depends on what usage of If it's the overall usage of Alternatively, you specifically target PMD suppressions through |
Beta Was this translation helpful? Give feedback.
-
Note, there are the following two feature requests on this topic: |
Beta Was this translation helpful? Give feedback.
Depends on what usage of
@SuppressWarnings
you are interested in… if it's for using it to suppress PMD warnings, and you are using the CLI, you can use--show-suppressed
to ignore all suppressions and show all warnings (this will even report those suppressed by comments such as// NOPMD
).If it's the overall usage of
@SuppressWarnings
, even for compiler warnings, you can write a custom rule to flag it, such as//Annotation[pmd-java:typeIs("java.lang.SuppressWarnings")]
.Alternatively, you specifically target PMD suppressions through
//Annotation[pmd-java:typeIs("java.lang.SuppressWarnings")][descendant::MemberValuePair/StringLiteral[@ConstValue = "PMD"]]
, but beware, PMD honors some stand…