Skip to content

Is there a way to prevent or discourage the use of SuppressWarnings? #4223

Answered by jsotuyod
rsoesemann asked this question in Q&A
Discussion options

You must be logged in to vote

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…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rsoesemann
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants