Search code examples
apexapex-codepmd

Use of Deprecated PMD rules


We've recently picked up PMD on our Salesforce project to help with our Apex code quality analysis. We've implemented a couple of rules, but have seen that most of the really valuable-looking rules (around performance, complexity, etc) are marked as deprecated.

Do people generally use continue to use deprecated rules (as they still work, even if they are no longer actively supported)? Or does deprecated in this sense mean that these may be broken/unreliable.

Does the prevalence of deprecated PMD rules mean that we should be looking for an alternative tool?

I'd really welcome your thoughts


Solution

  • There are very few deprecated rules in the Apex module: https://pmd.github.io/latest/pmd_rules_apex.html

    PMD rules are usually not deprecated without a replacement. For instance AvoidDmlStatementsInLoops is replaced by OperationWithLimitsInLoops, as documented. Sometimes several rules are consolidated into a single one, which is the case for those 3 performance rules. You might get the impression that many rules are deprecated, but no functionality is lost, and the newer rules are generally more easily extensible.

    If you are seeing many deprecation warnings, it may be because you are referencing those rules through deprecated rulesets. For instance, if you write

      <rule ref="rulesets/apex/complexity.xml/AvoidDeeplyNestedIfStmts" />
    

    you will get a deprecation warning, as the ruleset will be removed in PMD 7. However, the rule is not deprecated, and is still accessible at

      <rule ref="category/apex/design.xml/AvoidDeeplyNestedIfStmts" />
    

    I'm suggesting this because you mention deprecated complexity rules, and no complexity rules of PMD Apex are deprecated (the ruleset complexity.xml is though).

    In PMD 6, PMD's rule library has been reorganized into "categories", in contrast with the previous approach of publishing rulesets directly. Consequently, most built-in rulesets have been deprecated until PMD 7, which does not mean the rules themselves are deprecated.