Work with PMD for Apex in VS code

In this article, we’ll go over installing PMD and the PMD plugin for visual studio code, as well as adding some custom rulesets and finaly addressing some common issues.

Install PMD and PMD plugin for VS code

Please visit https://pmd.github.io/

Note: If you’re using MacOS, you need to make the alias permanent by adding it to ~/.zshrc

We can now install the Apex PMD plugin.

Select “Apex Static Analysis: On File” from the command palette.

Alternatively, right-click the editor and select “Static Analysis On File”

In the problems window tab, the PMD issues will be listed.

Using Custom Ruleset

  • On macOS - Code > Preferences > Settings
  • On Windows/Linux - File > Preferences > Settings

In Apex PMD: Ruleset settings, add the path to your CustomRuleSet.xml file.

Troubleshooting

  • If you don’t follow the steps in the correct order, try reinstalling the plugin.
  • If you get 0 problems and are using custom rulesets, double-check the path and, for further debugging, turn those settings off and look for errors in the output window tab.

Output window

updatedupdated2024-01-172024-01-17