ChuckJonas / vscode-apex-pmd

PMD static analysis for Apex in vscode
MIT License
82 stars 89 forks source link

vscode Apex Pmd

Visual Studio Marketplace Version Visual Studio Marketplace Installs - Azure DevOps Extension Open VSX Version Open VSX Downloads build Build Status

Allows you to run Apex Static Analysis directly in vscode on Apex, VisualForce & other XML metadata files.

Features

To start the command you can click in the menu on Help/Show All Commands or press the hotkey Ctrl+Shift+P and type Apex.

Apex PMD

Current actions Supported

System Requirements

Configuration

Defining your own "Ruleset"

I recommend you use the default ruleset as a starting point.

Set apexPMD.rulesets string array to reference your custom rulesets. You can either use the absolute paths, or a relative paths from your workspace (EG my-apex-rules.xml).

You can also mention the default ruleset in apexPMD.rulesets. To do this add default value to the array.

Apex Ruleset Reference

NOTE: If you move away from the default ruleset in an sfdx project, make sure to exclude the .sfdx generated classes by keeping this line:

<exclude-pattern>.*/.sfdx/.*</exclude-pattern>

Using custom rules written in Java

If you want to use your own custom rules from a jar file, then the jar file must be on the classpath. By default, the PMD folder and the workspace root folder are included in the classpath. You can add further folders using the additionalClassPaths setting. This "Hello world" example is a good starting place for beginners.

Troubleshooting

The plugin creates an own output channel "Apex PMD" in the output view. This shows the output of the PMD command that is executed in the background. In case of any problem, this output channel might contain the underlying error. When reporting an issue, please include any error messages from this output channel.

Developing/Contributing

Prerequisites

Setup & Run

  1. git clone
  2. npm install
  3. debug -> run extension

Creating a installable vsix package

npm run vscode:package

This will create a file "apex-pmd-.vsix", which can be directly installed in VS Code.

Executing automated tests

npm run test

Upgrading PMD

npm run update-pmd

This will check for the latest PMD version on github and update config.pmdVersion in package.json.

Legal Stuff

Copyright (c) 2020 Charles Jonas and Contributors

PMD License

Contains Distribution of PMD library.

Copyright (c) 2003-2009, InfoEther, LLC
All rights reserved.

This product includes software developed in part by support from
the Defense Advanced Research Project Agency (DARPA)

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The full license (BSD-style) can be found in the PMD repo