rule | Description | url | kpi | example |
---|---|---|---|---|
ApexUnitTestClassShouldHaveAsserts | Apex unit tests should System.assert() or assertEquals() or assertNotEquals() | https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaveasserts | Maintainability | |
ApexUnitTestMethodShouldHaveIsTestAnnotation | Apex test methods should have @isTest annotation. | https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation | Maintainability | |
ApexUnitTestShouldNotUseSeeAllDataTrue | Apex unit tests should not use @isTest(seeAllData = true) | https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrue | Maintainability | |
AvoidGlobalModifier | Avoid using global modifier | https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#avoidglobalmodifier | Maintainability | |
AvoidLogicInTrigger | Avoid logic in triggers | https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#avoidlogicintrigger | Maintainability | |
DebugsShouldUseLoggingLevel | Calls to System.debug should specify a logging level. | https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel | Maintainability | |
UnusedLocalVariable | Variable ''{0}'' defined but not used | https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#unusedlocalvariable | Maintainability | |
AvoidDeeplyNestedIfStmts | Avoid creating deeply nested if-then statements since they are harder to read and error-prone to maintain. | https://pmd.github.io/latest/pmd_rules_apex_design.html#avoiddeeplynestedifstmts | Maintainability | _x000D_ public class Foo {_x000D_ public void bar(Integer x, Integer y, Integer z) {_x000D_ if (x>y) {_x000D_ if (y>z) {_x000D_ if (z==x) {_x000D_ // !! too deep_x000D_ }_x000D_ }_x000D_ }_x000D_ }_x000D_ }_x000D_ |
AvoidDirectAccessTriggerMap | Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be bulkified and iterate through the map to handle the actions for each item separately. | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermap | Maintainability | |
AvoidNonExistentAnnotations | Apex supported non existent annotations for legacy reasons._x000D_ In the future, use of such non-existent annotations could result in broken apex code that will not compile._x000D_ This will prevent users of garbage annotations from being able to use legitimate annotations added to Apex in the future._x000D_ A full list of supported annotations can be found at https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation.htm | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#avoidnonexistentannotations | Maintainability | |
EmptyCatchBlock | Empty Catch Block finds instances where an exception is caught, but nothing is done._x000D_ In most circumstances, this swallows an exception which should either be acted on_x000D_ or reported. | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptycatchblock | Maintainability | |
EmptyIfStmt | Empty If Statement finds instances where a condition is checked but nothing is done about it. | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptyifstmt | Maintainability | |
EmptyStatementBlock | Empty block statements serve no purpose and should be removed. | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptystatementblock | Maintainability | |
EmptyWhileStmt | Empty While Statement finds all instances where a while statement does nothing._x000D_ If it is a timing loop, then you should use Thread.sleep() for it; if it is_x000D_ a while loop that does a lot in the exit expression, rewrite it to make it clearer. | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#emptywhilestmt | Maintainability | |
MethodWithSameNameAsEnclosingClass | Non-constructor methods should not have the same name as the enclosing class. | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#methodwithsamenameasenclosingclass | Maintainability | |
TestMethodsMustBeInTestClasses | Test methods marked as a testMethod or annotated with @IsTest,_x000D_ but not residing in a test class should be moved to a proper_x000D_ class or have the @IsTest annotation added to the class._x000D_ _x000D_ Support for tests inside functional classes was removed in Spring-13 (API Version 27.0),_x000D_ making classes that violate this rule fail compile-time. This rule is mostly usable when_x000D_ dealing with legacy code. | https://pmd.github.io/latest/pmd_rules_apex_errorprone.html#testmethodsmustbeintestclasses | Maintainability |