diff --git a/pmd-apex/src/main/resources/category/apex/bestpractices.xml b/pmd-apex/src/main/resources/category/apex/bestpractices.xml index 784b9f99b1..f69949af4a 100644 --- a/pmd-apex/src/main/resources/category/apex/bestpractices.xml +++ b/pmd-apex/src/main/resources/category/apex/bestpractices.xml @@ -1,20 +1,20 @@ + xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> Rules which enforce generally accepted best practices. + language="apex" + since="6.13.0" + message="Apex test assert statement should make use of the message parameter." + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexAssertionsShouldIncludeMessageRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexassertionsshouldincludemessage"> The second parameter of System.assert/third parameter of System.assertEquals/System.assertNotEquals is a message. Having a second/third parameter provides more information and makes it easier to debug the test failure and @@ -38,11 +38,11 @@ public class Foo { + language="apex" + since="5.5.1" + message="Apex unit tests should System.assert() or assertEquals() or assertNotEquals()" + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexUnitTestClassShouldHaveAssertsRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaveasserts"> Apex unit tests should include at least one assertion. This makes the tests more robust, and using assert with messages provide the developer a clearer idea of what the test does. Custom assert method invocation @@ -65,11 +65,11 @@ public class Foo { + language="apex" + since="6.51.0" + message="Apex unit test classes should have at least one System.runAs() call" + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexUnitTestClassShouldHaveRunAsRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaverunas"> Apex unit tests should include at least one runAs method. This makes the tests more robust, and independent from the user running it. @@ -103,11 +103,11 @@ private class TestRunAs { + since="6.13.0" + language="apex" + message="Apex test methods should have @isTest annotation." + class="net.sourceforge.pmd.lang.rule.xpath.XPathRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation"> Apex test methods should have `@isTest` annotation instead of the `testMethod` keyword, as `testMethod` is deprecated. @@ -148,11 +148,11 @@ private class ATest { + language="apex" + since="5.5.1" + message="Apex unit tests should not use @isTest(seeAllData = true)" + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexUnitTestShouldNotUseSeeAllDataTrueRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrue"> Apex unit tests should not use @isTest(seeAllData=true) because it opens up the existing database data for unexpected modification by tests. @@ -173,11 +173,11 @@ public class Foo { + language="apex" + since="5.5.0" + message="Avoid using global modifier" + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.AvoidGlobalModifierRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#avoidglobalmodifier"> Global classes should be avoided (especially in managed packages) as they can never be deleted or changed in signature. Always check twice if something needs to be global. Many interfaces (e.g. Batch) required global modifiers in the past but don't require this anymore. Don't lock yourself in. @@ -195,11 +195,11 @@ global class Unchangeable { + language="apex" + since="5.5.0" + message="Avoid logic in triggers" + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.AvoidLogicInTriggerRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#avoidlogicintrigger"> As triggers do not allow methods like regular classes they are less flexible and suited to apply good encapsulation style. Therefore delegate the triggers work to a regular class (often called Trigger handler class). @@ -227,30 +227,29 @@ trigger Accounts on Account (before insert, before update, before delete, after - + since="6.18.0" + language="apex" + message="Calls to System.debug should specify a logging level." + class="net.sourceforge.pmd.lang.rule.xpath.XPathRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#debugsshoulduselogginglevel"> + The first parameter of System.debug, when using the signature with two parameters, is a LoggingLevel enum. Having the Logging Level specified provides a cleaner log, and improves readability of it. - 3 - - - - + 3 + + + + - - - + + + + since="6.23.0" + language="apex" + message="Variable ''{0}'' defined but not used" + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.UnusedLocalVariableRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#unusedlocalvariable"> Detects when a local variable is declared and/or assigned but not used. - 5 + since="7.8.0" + language="apex" + message="It is best practice to call the `System.attachFinalizer(Finalizer f)` method within the `execute` method of a class which implements the `Queueable` interface." + class="net.sourceforge.pmd.lang.apex.rule.bestpractices.QueueableShouldAttachFinalizerRule" + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#queueableshouldattachfinalizer"> Detects when the Queueable interface is used but a Finalizer is not attached. + 5 - \ No newline at end of file +