For the complete documentation index, see llms.txt. This page is also available as Markdown.

Code Analyzer

The code analyzer linter runs Salesforce Code Analyzer against your project, providing static analysis through PMD, ESLint, and CPD engines. It identifies security issues, best practice violations, performance concerns, and duplicate code.

Overview

The code analyzer integrates Salesforce Code Analyzer into the project:analyze command and:

  1. Detects the configuration file (or uses engine defaults)

  2. Runs the configured engines (PMD, ESLint, CPD) against the target files

  3. Collects results in SARIF format

  4. Reports findings with file locations, line numbers, and rule details

  5. Creates GitHub Checks with annotations when running in CI

Supported Engines

Engine
Language
What It Checks

pmd

Apex

Security, best practices, performance, design

eslint

LWC JavaScript / Aura

JavaScript quality, security, best practices

cpd

Apex, JavaScript

Copy-paste / duplicate code detection

Configuration

The code analyzer is configured through a YAML file that follows the Salesforce Code Analyzer v5 configuration format. The file is checked in priority order until the first match is found:

  1. --code-analyzer-config <path> CLI flag

  2. config/code-analyzer.yml

  3. config/code-analyzer.yaml

  4. .code-analyzer.yml

  5. .code-analyzer.yaml

If no file is found, the default engine configuration is used (all engines with their built-in rule sets).

Schema

Examples

PMD-Only with Custom Rules

Tighter Duplicate Detection

Disable PMD Rules That Don't Apply

Integration with CI/CD

Integration is limited only to GitHub at the moment. The command needs GITHUB_APP_PRIVATE_KEY and GITHUB_APP_ID to be set in environment variables for results to be reported as GitHub checks.

Scoping Analysis

Use the same scoping options as other analysis commands:

For full engine configuration options, see the Salesforce Code Analyzer documentation.

Last updated

Was this helpful?