New PMD Rules

Updated 2 weeks ago by Copado Solutions

Copado now supports PMD version 6.31. As part of this upgrade, new rules have been added to the default RuleSet:

  • OverrideBothEqualsAndHashcode. The new Apex rule OverrideBothEqualsAndHashcode brings the well-known Java rule to Apex. In Apex the same principle applies: equals and hashCode should always be overridden together to ensure collection classes such as Maps and Sets work as expected.
  • VfHtmlStyleTagXss. The new Visualforce rule VfHtmlStyleTagXss checks for potential XSS problems when using <style> tags on Visualforce pages.

In order to ensure the rules are updated, follow the steps below.

To add the new rule:

  1. Navigate to Setup > Object Manager > Static Code Analysis Rule.
  2. Go to Fields & Relationships and click on Rule Name.
  3. Scroll down to Values and click on New to add the new rule.
  4. Add the new rule name as a picklist value (note that this name is case sensitive).
  5. Once you have added the new picklist value, go to the Static Code Analysis Setting record and create static code analysis rules for the new value added:
    1. Go to the Static Code Analysis Settings record.
    2. Navigate to the Static Code Analysis Rules related list and click on New to create a new rule:
    3. Select the name of the rule you have added in the Rule Name field.
    4. Add a priority. You can use the one defined by PMD in their documentation or define a custom priority that suits you better.
    5. Enter a message.
    6. Click on Save.

New and Deprecated Rules From Previous PMD Versions 

Version

Rules

6.30

  • New rule: OperationWithLimitsInLoop.
  • Deprecated rules: AvoidDmlStatementsInLoops, AvoidSoqlInLoops and AvoidSoslInLoops.


How did we do?