VSCode Apex PMD

logo

From Visual Studio MarketPlace

Install it from Visual Studio MarketPlace

VSCode Extension for PMD code scan for Salesforce Apex

Allows you to run Apex Static Code Analysis directly in VSCode.

ANT task based PMD

If you are looking for ANT task based PMD for Apex, here it is.

Features Demo

Demo for the Extension

Current actions Supported

Run analysis on:

  • file open
  • file save
  • entire workspace
  • single file

Installation

  1. Must have JDK >=1.4 installed and in path
  2. Download a PMD "bin" release (>= 5.6)
  3. unzip the zip file from step #2 to location of choice and make a note of that location. This is the value for : apexPMD.pmdPath
  4. In VSCode, Open Preferences: User Settings and set apexPMD.pmdPath to folder where pmd was unzipped in step 3 along with other config items as shown below:

Sample Configuration -> VSCode::Preferences: User Settings


{
     // ...

    // absolute path to where PMD was installed
    // following example in my case
    "apexPMD.pmdPath":"/Users/mchinnappan/code-scan-tools/pmd/pmd-bin-5.8.1",
    // Set to false to use you own ruleset (set path)
     "apexPMD.useDefaultRuleset": "true",

     // Absolute path to ruleset xml file.  Must also set `useDefaultRuleset:false`.
    "apexPMD.rulesetPath": "",
    
    // Will run static analysis every time a file is opened
    "apexPMD.runOnFileOpen": "true",

    // Will run static analysis every time a file is saved
    "apexPMD.runOnFileSave": "true",

    // Determines at what priority level 'errors' will be added. Anything less will be a warning or hint
    "apexPMD.priorityErrorThreshold": "1",

    // Determines at what priority level 'warnings' will be added. Anything less will be a hint
    "apexPMD.priorityWarnThreshold": "3"

}


Ruleset

Here is the sample ruleset used in this extension

From Visual Studio MarketPlace

Install it from Visual Studio MarketPlace