Better Targeted Static Code Analysis Feedback Surpression
Currently, if I want to suppress errors from static analysis, the suppression seems to be all-or-none at the class level.
I would prefer to suppress only the specific errors when they happen.
(e.g. in the method or in the line.)
Hi!
Our static code analysis is built on PMD. Currently, the only error suppression that works with Apex code in PMD is the `@SuppressWarnings` annotation. (This was introduced for Apex in PMD version 6.0.0). As you say, you can suppress all rules, or specific rules, at the class level, but can’t make more fine grained suppressions, unfortunately.
There are other methods of suppressing errors within PMD for other languages, but these don’t currently work with Apex. We’ll keep an eye on future versions of PMD to see if they introduce new methods of suppressing warnings for Apex code.
-
David Schach commented
PMD can now suppress warnings at a more granular level in a class.
1. Use //NOPMD on a line
2. Use @SuppressWarnings('PMD.AvoidGlobalModifier') for example above the class declaration line
3. @SuppressWarnings('PMD.FieldNamingConventions') above an inner class
etc
You basically find the PMD class API name and add that to whatever classes or methods you'd like.
https://pmd.github.io/latest/pmd_userdocs_suppressing_warnings.html (note the specific formatting for Apex)