sf-code-analyzer

Runs static code analysis on Salesforce projects using PMD, ESLint, RetireJS, and CPD engines.

Updated Dec 1, 2025
One-click install
npx skills add https://github.com/jterratsdev/smart-deployment --skill sf-code-analyzer-jterratsdev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sf-code-analyzer
Source: https://github.com/jterratsdev/smart-deployment/tree/main/.setup-agents/skills/sf-code-analyzer
Command: npx skills add https://github.com/jterratsdev/smart-deployment --skill sf-code-analyzer-jterratsdev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Salesforce teams need consistent, automated code quality checks across Apex and Lightning Web Components, but manually configuring and running multiple analysis engines (PMD, ESLint, RetireJS, CPD) is error-prone and time-consuming. This Skill standardizes static analysis so violations are caught before code review, PR merge, or release. ## Core Features & Use Cases - Multi-engine analysis: Run PMD rules for Apex, ESLint for LWC, RetireJS for vulnerable JavaScript libraries, and CPD for duplicate code detection with configurable rule selectors. - Severity gating: Set severity thresholds so CI pipelines fail only on HIGH or MEDIUM violations, with clear exit codes for automation. - Flexible reporting: Generate table, JSON, CSV, or HTML reports for terminal review, programmatic processing, or stakeholder sharing. - Use Case: Before merging a pull request, run a full project scan with security and performance rule selectors, then report the violation count by severity, top offending files, and critical findings like SOQL injection or missing CRUD/FLS checks. ## Quick Start Ask the assistant to run a full static code analysis on the force-app directory with security and recommended rules and report the violations by severity.

Frequently Asked Questions about sf-code-analyzer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run static code analysis on a Salesforce project?

Run sf code-analyzer run --target force-app to analyze the entire project. You can narrow the target to specific directories or comma-separated files, and add --rule-selector to choose engines like pmd:Security or eslint:Recommended.

How to scan only staged git files with Salesforce Code Analyzer?

Collect staged files with git diff --cached --name-only filtered to .cls, .js, and .html extensions, join them with commas, and pass the result to sf code-analyzer run --target. This pattern works well for pre-commit hooks and CI checks.

What rule selectors does Salesforce Code Analyzer support?

Supported selectors include pmd:Recommended, pmd:Security, pmd:Performance, and pmd:Design for Apex, eslint:Recommended and eslint:Security for LWC, retire-js:Recommended for vulnerable JavaScript libraries, and cpd:Recommended for duplicate code detection.

Does sf code-analyzer work in CI pipelines?

Yes, it returns exit code 0 when no violations exceed the threshold and exit code 2 when violations are found at or above the configured severity. Use --severity-threshold 1 to block merges only on HIGH severity findings.

Why does sf code-analyzer fail to run in my environment?

The most common cause is a missing plugin. Verify installation with sf plugins inspect @salesforce/plugin-code-analyzer and install it with sf plugins install @salesforce/plugin-code-analyzer if absent. Non-standard exit codes other than 0 or 2 indicate analyzer errors rather than violations.