@salesforce/afv-skills 1.9.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/applying-cms-brand/SKILL.md +170 -0
- package/skills/generating-permission-set/SKILL.md +1 -1
- package/skills/integrating-b2b-commerce-open-code-components/SKILL.md +166 -0
- package/skills/running-code-analyzer/SKILL.md +499 -0
- package/skills/running-code-analyzer/examples/README.md +38 -0
- package/skills/running-code-analyzer/examples/basic-scan-output.json +92 -0
- package/skills/running-code-analyzer/examples/command-variations.md +333 -0
- package/skills/running-code-analyzer/examples/fix-application-before-after.md +142 -0
- package/skills/running-code-analyzer/examples/large-scan-output.json +67 -0
- package/skills/running-code-analyzer/examples/security-focused-output.json +95 -0
- package/skills/running-code-analyzer/references/command-examples.md +27 -0
- package/skills/running-code-analyzer/references/engine-reference.md +34 -0
- package/skills/running-code-analyzer/references/error-handling.md +29 -0
- package/skills/running-code-analyzer/references/flag-reference.md +96 -0
- package/skills/running-code-analyzer/references/quick-start.md +28 -0
- package/skills/running-code-analyzer/references/special-behaviors.md +83 -0
- package/skills/running-code-analyzer/references/vendor-file-handling.md +239 -0
- package/skills/running-code-analyzer/scripts/apply-fixes.js +86 -0
- package/skills/running-code-analyzer/scripts/discover-fixes.js +34 -0
- package/skills/running-code-analyzer/scripts/filter-violations.js +405 -0
- package/skills/running-code-analyzer/scripts/parse-results.js +59 -0
- package/skills/running-code-analyzer/scripts/summarize-fixes.js +32 -0
- package/skills/running-code-analyzer/scripts/verify-execution.sh +28 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: running-code-analyzer
|
|
3
|
+
description: "Run Salesforce Code Analyzer to scan code for security, performance, best practice, and code style violations. Supports all engines (PMD, ESLint, CPD, RetireJS, Flow, SFGE, ApexGuru), targets (files, folders, git diff), categories, and severities. TRIGGER when: user says 'scan my code', 'check for security issues', 'run PMD/ESLint', 'find duplicates', 'analyze Flows', 'check vulnerable libraries', 'AppExchange review', 'lint my LWC', 'static analysis', 'code quality', or mentions engines/file types (.cls, .trigger, .js, .flow-meta.xml). DO NOT TRIGGER when: user wants to fix code without scanning, or asks about installation/configuration."
|
|
4
|
+
allowed-tools: Read, Bash(sf code-analyzer), Bash(node), Bash(git diff), Bash(date), Write, Edit
|
|
5
|
+
license: LICENSE.txt has complete terms
|
|
6
|
+
metadata:
|
|
7
|
+
version: "1.0"
|
|
8
|
+
argument-hint: "[target-path] [--engine pmd|eslint|cpd|retire-js|regex|flow|sfge|apexguru] [--category Security|Performance|BestPractices|...] [--severity 1-5] [--diff]"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Running Code Analyzer Skill
|
|
12
|
+
|
|
13
|
+
## ⚠️ CRITICAL: Tool Selection
|
|
14
|
+
|
|
15
|
+
**BEFORE DOING ANYTHING ELSE:**
|
|
16
|
+
|
|
17
|
+
This skill MUST use the **Bash tool** to execute `sf code-analyzer run` and Node.js scripts.
|
|
18
|
+
|
|
19
|
+
**DO NOT use these tools under any circumstances:**
|
|
20
|
+
- ❌ `run_code_analyzer` (MCP tool)
|
|
21
|
+
- ❌ `mcp__*` (any MCP tool)
|
|
22
|
+
- ❌ Any tool containing `mcp` in its name
|
|
23
|
+
|
|
24
|
+
If you see a `run_code_analyzer` tool available, **ignore it completely**. Use only the Bash tool with `sf code-analyzer run`.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Overview
|
|
29
|
+
|
|
30
|
+
This skill translates natural language requests ("scan for security issues", "check my changes") into the correct `sf code-analyzer run` command, executes scans with any combination of engines/targets/severities, and presents actionable results. When engine-provided fixes are available, it discovers them, asks for user confirmation, applies them safely, and offers verification. Use this skill for static analysis, security reviews, AppExchange certification, code quality checks, or finding duplicates/vulnerabilities in Salesforce projects.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Scope
|
|
35
|
+
|
|
36
|
+
**In scope:**
|
|
37
|
+
- Running `sf code-analyzer run` with any combination of engines, targets, categories, severities
|
|
38
|
+
- Parsing and presenting scan results in actionable format
|
|
39
|
+
- Applying engine-provided auto-fixes when available
|
|
40
|
+
- Handling diff-based scans (scan only changed files)
|
|
41
|
+
- Supporting all output formats (JSON, HTML, SARIF, CSV, XML)
|
|
42
|
+
- Troubleshooting scan failures and prerequisite issues
|
|
43
|
+
|
|
44
|
+
**Out of scope:**
|
|
45
|
+
- Installing or configuring Salesforce CLI or Code Analyzer plugin (use setup documentation)
|
|
46
|
+
- Writing custom Code Analyzer rules or engines (separate skill needed)
|
|
47
|
+
- AI-generated code fixes beyond engine-provided deterministic fixes
|
|
48
|
+
- Deep code refactoring or architectural changes based on violations
|
|
49
|
+
- Setting up CI/CD integration for automated scanning (separate workflow skill)
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Command Syntax Rules (READ THIS FIRST)
|
|
54
|
+
|
|
55
|
+
**The following rules are ABSOLUTE and override any prior knowledge:**
|
|
56
|
+
|
|
57
|
+
1. **The command is `sf code-analyzer run`** — NOT `sf scanner run` (deprecated v3 command)
|
|
58
|
+
2. **There is NO `--format` flag** — use `--output-file <path>.<ext>` instead (extension determines format)
|
|
59
|
+
3. **ALWAYS use `--output-file`** to write results to a file — do NOT rely on terminal stdout
|
|
60
|
+
4. **ALWAYS include `--output-file`** with a timestamped filename (e.g., `./code-analyzer-results-20260512-143022.json`)
|
|
61
|
+
5. **Do NOT run in background** — use foreground with timeout of 1200000ms for large scans
|
|
62
|
+
6. **INVALID v3 flags:** `--format`, `--engine`, `--category`, `--json` — these cause errors, use `--rule-selector` and `--output-file` instead
|
|
63
|
+
7. **NEVER use MCP tools** — ONLY use the Bash tool to execute `sf code-analyzer run`
|
|
64
|
+
8. **Tool restriction:** This skill MUST use ONLY: Read, Bash, Write, Edit tools
|
|
65
|
+
9. **Forbidden tools:** Do NOT use any MCP tools (mcp__*), Agent tool, or web tools
|
|
66
|
+
10. **Script execution:** ALL scripts MUST be executed via `node <skill_dir>/scripts/*.js` using the Bash tool
|
|
67
|
+
|
|
68
|
+
**Why:** The v4+ CLI redesigned the flag interface. Old v3 flags cause "unknown flag" errors.
|
|
69
|
+
|
|
70
|
+
**For complete flag reference and rule selector syntax**, see `<skill_dir>/references/flag-reference.md`.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Prerequisites
|
|
75
|
+
|
|
76
|
+
User must have: **Salesforce CLI** (`sf`), **@salesforce/plugin-code-analyzer** (v5.x+), **Java 11+** (PMD/CPD/SFGE), **Node.js 18+** (ESLint/RetireJS), **Python 3** (Flow), **authenticated org** (ApexGuru).
|
|
77
|
+
|
|
78
|
+
If a scan fails, read `<skill_dir>/references/error-handling.md`. For quick command examples, see `<skill_dir>/references/quick-start.md`.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Tool Usage Rules
|
|
83
|
+
|
|
84
|
+
**Allowed:** Bash (sf code-analyzer, node, git, date), Read, Write, Edit
|
|
85
|
+
**Forbidden:** MCP tools, Agent tool, Web tools, other skills
|
|
86
|
+
|
|
87
|
+
This skill owns the complete scan-fix-verify workflow. Using MCP tools bypasses the validated script workflow.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Quick Start: Common Patterns
|
|
92
|
+
|
|
93
|
+
Use this decision tree for fast pattern matching before going to Step 1 detailed parsing:
|
|
94
|
+
|
|
95
|
+
| User Says | Action | Rule Selector | Notes |
|
|
96
|
+
|-----------|--------|---------------|-------|
|
|
97
|
+
| "scan my code" / "run code analyzer" | Default scan | `Recommended` | Curated rule set, all file types |
|
|
98
|
+
| "check for security issues" / "security review" | Security scan | `all:Security:(1,2)` | All engines, Critical+High only |
|
|
99
|
+
| "scan my changes" / "check the diff" | Diff-based scan | Get changed files via `git diff`, filter to scannable types, use `--target` | See Step 1.5 for filtering logic |
|
|
100
|
+
| "run PMD" / "check my Apex" | PMD only | `pmd` | Apex classes and triggers |
|
|
101
|
+
| "lint my LWC" / "check my JavaScript" | ESLint only | `eslint` | JavaScript/TypeScript/LWC |
|
|
102
|
+
| "find duplicates" / "check for copy-paste" | CPD (Copy-Paste Detector) | `cpd` | Detects code clones |
|
|
103
|
+
| "check for vulnerabilities" / "scan libraries" | RetireJS | `retire-js` | JavaScript library CVEs |
|
|
104
|
+
| "deep analysis" / "data flow analysis" | SFGE (Graph Engine) | `sfge` | Requires Java 11+, 10-20min, use `--workspace "force-app"` |
|
|
105
|
+
| "performance analysis" / "governor limits" | ApexGuru | `apexguru` | Requires authenticated org |
|
|
106
|
+
| "analyze my Flows" | Flow engine | `flow` | Target: `**/*.flow-meta.xml`, requires Python 3 |
|
|
107
|
+
| "AppExchange security review" | AppExchange scan | `all:Security:(1,2)` | Read `<skill_dir>/references/special-behaviors.md` → AppExchange section |
|
|
108
|
+
|
|
109
|
+
**If the pattern matches above**, proceed directly to Step 3 (Build Command). Otherwise, continue to Step 1 for detailed parsing.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Step 1: Parse the User's Intent
|
|
114
|
+
|
|
115
|
+
Analyze the user's request along these 7 dimensions. Any can be combined freely:
|
|
116
|
+
|
|
117
|
+
### 1.1 ENGINE — Which analysis engine(s)?
|
|
118
|
+
|
|
119
|
+
Map user keywords to `--rule-selector` values:
|
|
120
|
+
- PMD / Apex rules → `pmd`
|
|
121
|
+
- ESLint / JS/TS rules / lint → `eslint`
|
|
122
|
+
- Flows / Flow analysis → `flow`
|
|
123
|
+
- duplicates / copy-paste / CPD → `cpd`
|
|
124
|
+
- vulnerabilities / CVE / libraries / RetireJS → `retire-js`
|
|
125
|
+
- SFGE / data flow / deep analysis → `sfge`
|
|
126
|
+
- performance / ApexGuru → `apexguru`
|
|
127
|
+
- regex / pattern rules → `regex`
|
|
128
|
+
- all engines / everything → `all`
|
|
129
|
+
- Not specified / general "scan" → `Recommended` (default)
|
|
130
|
+
|
|
131
|
+
### 1.2 CATEGORY — What kind of issues?
|
|
132
|
+
|
|
133
|
+
Map user keywords to category tags:
|
|
134
|
+
- security / vulnerabilities / OWASP → `Security`
|
|
135
|
+
- performance / speed / optimization → `Performance`
|
|
136
|
+
- best practices / quality → `BestPractices`
|
|
137
|
+
- code style / formatting → `CodeStyle`
|
|
138
|
+
- design / complexity → `Design`
|
|
139
|
+
- error prone / bugs → `ErrorProne`
|
|
140
|
+
- documentation / comments → `Documentation`
|
|
141
|
+
|
|
142
|
+
### 1.3 SEVERITY — How critical?
|
|
143
|
+
|
|
144
|
+
**Severity levels:** 1=Critical (must fix), 2=High (should fix), 3=Moderate (recommended), 4=Low (nice to fix), 5=Info (FYI)
|
|
145
|
+
|
|
146
|
+
Map user keywords:
|
|
147
|
+
- "critical only" / "sev 1" → `1`
|
|
148
|
+
- "critical and high" / "sev 1-2" → `(1,2)`
|
|
149
|
+
- "moderate and above" / "sev 1-3" → `(1,2,3)`
|
|
150
|
+
|
|
151
|
+
### 1.4 SPECIFIC RULE — Named rule?
|
|
152
|
+
|
|
153
|
+
If the user mentions a specific rule by name (e.g., "ApexCRUDViolation", "no-unused-vars"):
|
|
154
|
+
- Map to: `--rule-selector <engine>:<ruleName>`
|
|
155
|
+
- If engine is ambiguous, use just the rule name: `--rule-selector <ruleName>`
|
|
156
|
+
|
|
157
|
+
**⚠️ IMPORTANT — Partial Rule Names:** The `--rule-selector` flag requires the EXACT full rule name (e.g., `@salesforce-ux/slds/no-hardcoded-values-slds2`, not `no-hardcoded-values`). It does NOT support wildcards or partial matches.
|
|
158
|
+
|
|
159
|
+
**When you are NOT 100% certain of the full rule name:**
|
|
160
|
+
- **Do NOT guess** — a wrong name returns 0 results and wastes a scan cycle
|
|
161
|
+
- Instead, **look up the rule first** using the `sf code-analyzer rules` command with grep:
|
|
162
|
+
```bash
|
|
163
|
+
sf code-analyzer rules --rule-selector all 2>&1 | grep -i "USER_KEYWORD"
|
|
164
|
+
```
|
|
165
|
+
- Extract the full rule name from the output, then use it in your scan command
|
|
166
|
+
- If grep returns multiple matches, present them to the user and ask which one they meant
|
|
167
|
+
- If grep returns 0 matches, tell the user no rule matched their keyword
|
|
168
|
+
|
|
169
|
+
### 1.5 TARGET — What files to scan?
|
|
170
|
+
|
|
171
|
+
Map user keywords:
|
|
172
|
+
- Specific file/folder → `--target <path>`
|
|
173
|
+
- Glob pattern / "all Apex classes" → `--target **/*.cls,**/*.trigger`
|
|
174
|
+
- "my changes" / "diff" → Run `git diff --name-only [base]...HEAD`, filter to scannable types, pass as `--target`
|
|
175
|
+
- "LWC" → `--target **/lwc/**`
|
|
176
|
+
- "Flows" → `--target **/*.flow-meta.xml`
|
|
177
|
+
- Not specified → Entire workspace (omit `--target`)
|
|
178
|
+
|
|
179
|
+
**For diff filtering details:** See `<skill_dir>/references/special-behaviors.md`.
|
|
180
|
+
|
|
181
|
+
### 1.6 OUTPUT — What format?
|
|
182
|
+
|
|
183
|
+
**DEFAULT:** Always JSON. Only change if user EXPLICITLY requests another format.
|
|
184
|
+
|
|
185
|
+
**Naming:** `./code-analyzer-results-<YYYYMMDD-HHmmss>.<ext>` (timestamp via `TIMESTAMP=$(date +%Y%m%d-%H%M%S)`)
|
|
186
|
+
|
|
187
|
+
Formats: `.json` (default), `.html` (report), `.sarif` (GitHub/IDE), `.csv` (spreadsheet), `.xml`
|
|
188
|
+
|
|
189
|
+
### 1.7 COMPARISON — Delta/trend analysis?
|
|
190
|
+
|
|
191
|
+
Map user keywords:
|
|
192
|
+
- "new since main" → `git diff --name-only main...HEAD` → scan those files
|
|
193
|
+
- "new since last commit" → `git diff --name-only HEAD~1`
|
|
194
|
+
- "compared to develop" → `git diff --name-only develop...HEAD`
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Step 2: Build the Rule Selector
|
|
199
|
+
|
|
200
|
+
**Syntax:** `:` = AND, `,` = OR, `()` = grouping
|
|
201
|
+
|
|
202
|
+
**Examples:**
|
|
203
|
+
- Engine only: `pmd`
|
|
204
|
+
- Engine + category: `pmd:Security`
|
|
205
|
+
- Engine + severity: `pmd:2`
|
|
206
|
+
- Complex: `(pmd,eslint):Security:(1,2)` = (PMD or ESLint) AND Security AND (sev 1 or 2)
|
|
207
|
+
- Specific rule: `pmd:ApexCRUDViolation`
|
|
208
|
+
- All rules: `all`
|
|
209
|
+
|
|
210
|
+
**More examples:** `<skill_dir>/references/command-examples.md`
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Step 3: Build the Full Command
|
|
215
|
+
|
|
216
|
+
Generate timestamp: `TIMESTAMP=$(date +%Y%m%d-%H%M%S)`
|
|
217
|
+
|
|
218
|
+
Build command:
|
|
219
|
+
```bash
|
|
220
|
+
sf code-analyzer run \
|
|
221
|
+
--rule-selector <selector> \
|
|
222
|
+
--target <targets> \ # optional
|
|
223
|
+
--output-file "./code-analyzer-results-${TIMESTAMP}.json" \ # DEFAULT: JSON
|
|
224
|
+
--include-fixes \ # always
|
|
225
|
+
--workspace <path> # optional
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Key decisions:**
|
|
229
|
+
- DEFAULT: timestamped JSON (`.json`). Only change format if user explicitly requests HTML/SARIF/CSV/XML.
|
|
230
|
+
- Always include `--include-fixes` (enables Step 6 auto-fix)
|
|
231
|
+
- Omit `--target` to scan entire workspace
|
|
232
|
+
- For diff-based scans: get files via `git diff --name-only`, filter to scannable types, pass as `--target`
|
|
233
|
+
|
|
234
|
+
**Special cases:** See `<skill_dir>/references/special-behaviors.md` for SFGE/ApexGuru/AppExchange/diff filtering.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Step 4: Execute the Scan
|
|
239
|
+
|
|
240
|
+
**⚠️ TOOL REQUIREMENT: Use Bash tool ONLY. DO NOT use run_code_analyzer (MCP tool) or any MCP tool.**
|
|
241
|
+
|
|
242
|
+
**Rules:** Foreground only (no `run_in_background`), hardcoded filename (not `$TIMESTAMP`), timeout 1200000ms, no `sleep`, log output to timestamped file.
|
|
243
|
+
|
|
244
|
+
**Steps:**
|
|
245
|
+
|
|
246
|
+
1. Generate timestamp: `date +%Y%m%d-%H%M%S` → capture output (e.g., `20260512-143022`) **using Bash tool**
|
|
247
|
+
2. Tell user:
|
|
248
|
+
```
|
|
249
|
+
Starting scan...
|
|
250
|
+
Results: ./code-analyzer-results-20260512-143022.json
|
|
251
|
+
Log: ./code-analyzer-results-20260512-143022.log
|
|
252
|
+
May take several minutes for large codebases.
|
|
253
|
+
```
|
|
254
|
+
3. Run command with literal timestamp in filename and `tee` to capture log (timeout: 1200000):
|
|
255
|
+
|
|
256
|
+
⚠️ **IMPORTANT:** Use the Bash tool, NOT the run_code_analyzer MCP tool.
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
sf code-analyzer run --rule-selector Recommended --output-file "./code-analyzer-results-20260512-143022.json" --include-fixes 2>&1 | tee "./code-analyzer-results-20260512-143022.log"
|
|
260
|
+
```
|
|
261
|
+
4. After completion: Exit 0 = success. Error output → check both the log file and `<skill_dir>/references/error-handling.md`.
|
|
262
|
+
5. IMMEDIATELY parse results (Step 5). Do NOT ask user what they want.
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Step 5: Parse and Present Results
|
|
267
|
+
|
|
268
|
+
### Parsing Rules:
|
|
269
|
+
|
|
270
|
+
1. **Execute the parse script using `<skill_dir>`** — see below
|
|
271
|
+
2. **NEVER use `jq` to parse results** — jq one-liners WILL fail due to shell quoting issues
|
|
272
|
+
3. **Run it IMMEDIATELY after the scan** — do NOT ask the user "what would you like next?"
|
|
273
|
+
|
|
274
|
+
### Script Execution
|
|
275
|
+
|
|
276
|
+
All scripts are bundled in the `scripts/` subdirectory of the same directory that contains this SKILL.md file. Use the absolute path to that directory — do NOT use `./scripts/` as that resolves relative to the current working directory, not the skill directory.
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
node <skill_dir>/scripts/parse-results.js "./code-analyzer-results-TIMESTAMP.json"
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
⚠️ **DO NOT:**
|
|
283
|
+
- ❌ Invent or generate script code yourself
|
|
284
|
+
- ❌ Use bare relative paths like `node scripts/parse-results.js` (won't resolve from user's CWD)
|
|
285
|
+
- ❌ Use heredocs or inline script content
|
|
286
|
+
- ❌ Use `jq` as a substitute for the parse script
|
|
287
|
+
|
|
288
|
+
### How to Present Results:
|
|
289
|
+
|
|
290
|
+
**ALWAYS present a concise summary, then point to the output file for full details.**
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
## Scan Complete
|
|
294
|
+
|
|
295
|
+
**Found X violations** across Y files.
|
|
296
|
+
|
|
297
|
+
| Severity | Count |
|
|
298
|
+
|----------|-------|
|
|
299
|
+
| Critical (1) | X |
|
|
300
|
+
| High (2) | X |
|
|
301
|
+
| Moderate (3) | X |
|
|
302
|
+
| Low (4) | X |
|
|
303
|
+
| Info (5) | X |
|
|
304
|
+
|
|
305
|
+
### Top Issues
|
|
306
|
+
| # | Rule | Engine | Sev | File | Line |
|
|
307
|
+
|---|------|--------|-----|------|------|
|
|
308
|
+
| 1 | ApexCRUDViolation | pmd | 2 | AccountService.cls | 42 |
|
|
309
|
+
| 2 | ApexSOQLInjection | pmd | 1 | QueryHelper.cls | 18 |
|
|
310
|
+
| ... (show up to 10 most critical) |
|
|
311
|
+
|
|
312
|
+
### Top Rules by Frequency
|
|
313
|
+
| Rule | Engine | Count |
|
|
314
|
+
|------|--------|-------|
|
|
315
|
+
| no-var | eslint | 170 |
|
|
316
|
+
| ApexDoc | pmd | 165 |
|
|
317
|
+
| ... |
|
|
318
|
+
|
|
319
|
+
Full results: `./code-analyzer-results-20260512-143022.json`
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Result Presentation Rules:
|
|
323
|
+
|
|
324
|
+
- **0 violations**: "Scan complete — no violations found! Output: `<path>`"
|
|
325
|
+
- **1-10**: Show all violations in table
|
|
326
|
+
- **11-50**: Show severity counts + top 10 violations
|
|
327
|
+
- **50-5000**: Show counts + top 10 violations + top 10 rules + top 5 files
|
|
328
|
+
- **5000+**: Same as 50-5000, plus suggest narrowing scope (severity/category/folder)
|
|
329
|
+
|
|
330
|
+
**Always end with:** Output file path + next-action offers (explain rules / apply fixes)
|
|
331
|
+
|
|
332
|
+
**For large result sets:** See `<skill_dir>/references/special-behaviors.md`.
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## Step 6: Apply Engine-Provided Fixes (Post-Scan)
|
|
337
|
+
|
|
338
|
+
After presenting results, check if violations have **engine-provided fixes** (deterministic, not AI-generated).
|
|
339
|
+
|
|
340
|
+
**Rules:** NEVER apply without confirmation. Use EXACT scripts from `<skill_dir>/scripts/`. Filter vendor files if needed, then: Discover → Apply → Summarize.
|
|
341
|
+
|
|
342
|
+
**Flow:** Filter vendor (6.1 if needed) → discover (6.2) → present (6.3) → ASK user → apply (6.4) → summarize (6.5) → present results.
|
|
343
|
+
|
|
344
|
+
### 6.1 — Check for vendor files (if needed)
|
|
345
|
+
|
|
346
|
+
If user said "fix my code" or "project source", or if top files by violation count are vendor libraries (jQuery, Bootstrap, *.min.js), run:
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
node "<skill_dir>/scripts/filter-violations.js" \
|
|
350
|
+
"./code-analyzer-results-TIMESTAMP.json" \
|
|
351
|
+
"./code-analyzer-results-TIMESTAMP-filtered.json" \
|
|
352
|
+
--report
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Present: "Excluded X vendor files (Y violations) - jQuery, Bootstrap, etc. Applying fixes to Z project files only."
|
|
356
|
+
|
|
357
|
+
Use filtered file for Step 6.3+. **See:** `<skill_dir>/references/vendor-file-handling.md` for detailed logic.
|
|
358
|
+
|
|
359
|
+
### 6.2 — Discover fixable violations
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
node "<skill_dir>/scripts/discover-fixes.js" "./code-analyzer-results-TIMESTAMP.json"
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
(Use filtered file from Step 6.1 if created.)
|
|
366
|
+
|
|
367
|
+
### 6.3 — Present fixable violations and ASK for confirmation
|
|
368
|
+
|
|
369
|
+
After running the discovery script, present results:
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
### Engine-Provided Fixes Available
|
|
373
|
+
|
|
374
|
+
**X of Y violations** have auto-fixes provided by the analysis engine:
|
|
375
|
+
|
|
376
|
+
| Rule | Engine | Sev | Fixable Count |
|
|
377
|
+
|------|--------|-----|---------------|
|
|
378
|
+
| no-var | eslint | 3 | 170 |
|
|
379
|
+
| no-hardcoded-values-slds2 | eslint | 4 | 76 |
|
|
380
|
+
| ... |
|
|
381
|
+
|
|
382
|
+
These are safe, deterministic fixes generated by the engines (not AI-generated).
|
|
383
|
+
|
|
384
|
+
Would you like me to apply these fixes? (yes / no / select specific rules)
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### ⚠️ STOP HERE AND WAIT FOR USER RESPONSE.
|
|
388
|
+
|
|
389
|
+
**Even if the user originally said "scan and fix everything", you MUST still stop here and wait.** Present the table, ask the question, and WAIT for a response in the NEXT turn.
|
|
390
|
+
|
|
391
|
+
### 6.4 — Apply fixes ONLY after user confirms
|
|
392
|
+
|
|
393
|
+
**Only proceed after user says "yes", "apply", "go ahead" IN A SEPARATE RESPONSE.**
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
node "<skill_dir>/scripts/apply-fixes.js" "./code-analyzer-results-TIMESTAMP.json"
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
(Use filtered file if Step 6.1 created one.)
|
|
400
|
+
|
|
401
|
+
### 6.5 — After applying, ALWAYS run the summary script
|
|
402
|
+
|
|
403
|
+
⚠️ **MANDATORY**: After the apply script completes, you MUST run the summary script as your VERY NEXT action.
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
node "<skill_dir>/scripts/summarize-fixes.js" "./code-analyzer-results-TIMESTAMP.json"
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Then present to the user:
|
|
410
|
+
|
|
411
|
+
```
|
|
412
|
+
### Engine-Provided Fixes Applied Successfully ✓
|
|
413
|
+
|
|
414
|
+
**Applied X auto-fixes across Y files.**
|
|
415
|
+
|
|
416
|
+
| Severity | Fixes Applied |
|
|
417
|
+
|----------|---------------|
|
|
418
|
+
| Critical (1) | X |
|
|
419
|
+
| High (2) | X |
|
|
420
|
+
| ... |
|
|
421
|
+
|
|
422
|
+
| Rule | Fixes Applied |
|
|
423
|
+
|------|---------------|
|
|
424
|
+
| no-var | 169 |
|
|
425
|
+
| ... |
|
|
426
|
+
|
|
427
|
+
Want me to re-run the scan to verify the fixes resolved the violations?
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### 6.6 — If user declines: Skip. If selects rules: filter. If "all": run as-is.
|
|
431
|
+
|
|
432
|
+
### 6.7 — Re-scan (optional): Re-run with new timestamp, compare before/after counts.
|
|
433
|
+
---
|
|
434
|
+
## Rules / Constraints
|
|
435
|
+
|
|
436
|
+
| Constraint | Rationale |
|
|
437
|
+
|-----------|-----------|
|
|
438
|
+
| Timestamped output (JSON + log) | Prevents overwrite; enables history tracking |
|
|
439
|
+
| Use `tee` for logs | Keeps logs in working dir with matching timestamp |
|
|
440
|
+
| Never use `--format` flag | Removed in v4+; use `--output-file <path>.<ext>` instead |
|
|
441
|
+
| Foreground scans, 1200000ms timeout | SFGE takes 10-20min; backgrounding loses output |
|
|
442
|
+
| Execute scripts from `<skill_dir>/scripts/` | Never write inline scripts or heredocs |
|
|
443
|
+
| Never apply fixes without confirmation | User must explicitly approve code modifications |
|
|
444
|
+
| Check for vendor files before fixes | If 50%+ vendor (jQuery, Bootstrap), filter first |
|
|
445
|
+
| Run fix scripts in order | Filter (if needed) → Discover → Apply → Summarize |
|
|
446
|
+
| SFGE needs explicit `--workspace` | Prevents template file compilation errors |
|
|
447
|
+
| Look up partial rule names first | Guessing fails; use `sf code-analyzer rules` to find exact name |
|
|
448
|
+
| ONLY Bash tool, never MCP | run_code_analyzer MCP tool bypasses script workflow |
|
|
449
|
+
| Never invoke other skills for fixes | This skill owns complete workflow end-to-end |
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
## Gotchas
|
|
454
|
+
|
|
455
|
+
| Issue | Why It Happens | Solution |
|
|
456
|
+
|-------|---------------|----------|
|
|
457
|
+
| `--format` flag error | Removed in v4+ | Use `--output-file <path>.<ext>` |
|
|
458
|
+
| Scan returns 0 results | Invalid rule selector | Run `sf code-analyzer rules --rule-selector <selector>` to verify |
|
|
459
|
+
| SFGE compilation error | Template files in workspace | Set `--workspace "force-app"` |
|
|
460
|
+
| jq parsing fails | Shell quoting issues | Use `node "<skill_dir>/scripts/parse-results.js"` |
|
|
461
|
+
| Inline scripts written | LLM generates custom code | NEVER write scripts — use existing from <skill_dir>/scripts/ |
|
|
462
|
+
| Scan times out | Large SFGE | Increase timeout to 1200000ms |
|
|
463
|
+
| run_code_analyzer MCP used | LLM prefers MCP over Bash | Use Bash tool ONLY |
|
|
464
|
+
| Other skills invoked | LLM delegates to other skills | Use apply-fixes.js from this skill only |
|
|
465
|
+
| Most violations are vendor | Includes jQuery, Bootstrap, *.min.js | Run filter-violations.js before applying fixes |
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## Output Expectations
|
|
470
|
+
|
|
471
|
+
Every scan produces: timestamped JSON file, concise summary (severity/top violations/rules/files), next-action offers. If fixes applied: summary by severity/rule, offer verification.
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
## Reference File Index
|
|
476
|
+
|
|
477
|
+
`<skill_dir>` is the absolute path to the directory containing this SKILL.md file.
|
|
478
|
+
|
|
479
|
+
### Scripts (Always execute, never read)
|
|
480
|
+
| File | When to use |
|
|
481
|
+
|------|-------------|
|
|
482
|
+
| `<skill_dir>/scripts/parse-results.js` | Step 5 — extract summary from scan JSON |
|
|
483
|
+
| `<skill_dir>/scripts/filter-violations.js` | Step 6.1 — exclude vendor files (jQuery, Bootstrap) from fixes |
|
|
484
|
+
| `<skill_dir>/scripts/discover-fixes.js` | Step 6.2 — identify fixable violations |
|
|
485
|
+
| `<skill_dir>/scripts/apply-fixes.js` | Step 6.4 — apply engine fixes after user confirms |
|
|
486
|
+
| `<skill_dir>/scripts/summarize-fixes.js` | Step 6.5 — summarize applied changes |
|
|
487
|
+
|
|
488
|
+
### References (Read when needed)
|
|
489
|
+
| File | When to read |
|
|
490
|
+
|------|-------------|
|
|
491
|
+
| `<skill_dir>/references/quick-start.md` | Command syntax templates |
|
|
492
|
+
| `<skill_dir>/references/flag-reference.md` | Flag docs, rule selector syntax |
|
|
493
|
+
| `<skill_dir>/references/error-handling.md` | Scan failure diagnosis |
|
|
494
|
+
| `<skill_dir>/references/engine-reference.md` | Engine capabilities, file types, rule tags |
|
|
495
|
+
| `<skill_dir>/references/command-examples.md` | Uncommon command scenarios |
|
|
496
|
+
| `<skill_dir>/references/special-behaviors.md` | SFGE/ApexGuru/AppExchange/diff/large scans |
|
|
497
|
+
| `<skill_dir>/references/vendor-file-handling.md` | Vendor file detection and filtering logic |
|
|
498
|
+
|
|
499
|
+
Examples in `<skill_dir>/examples/` show output structure validation and command patterns (basic/large/security scans, fix workflows).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Examples Directory
|
|
2
|
+
|
|
3
|
+
Sample outputs and command patterns for the running-code-analyzer skill.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
| File | Purpose |
|
|
8
|
+
|------|---------|
|
|
9
|
+
| [`basic-scan-output.json`](basic-scan-output.json) | Small scan (~127 violations) showing typical structure for personal projects |
|
|
10
|
+
| [`large-scan-output.json`](large-scan-output.json) | Large scan (~69k violations) from real NPSP project, demonstrates scale handling |
|
|
11
|
+
| [`security-focused-output.json`](security-focused-output.json) | Security-only scan with `all:Security:(1,2)` selector, shows critical issues |
|
|
12
|
+
| [`fix-application-before-after.md`](fix-application-before-after.md) | Before/after comparison showing engine-provided fixes in action |
|
|
13
|
+
| [`command-variations.md`](command-variations.md) | 20+ real command patterns with explanations and anti-patterns |
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
|
|
17
|
+
### As a User/Developer
|
|
18
|
+
- **Validate your scan output** matches expected format
|
|
19
|
+
- **See real-world command examples** for common scenarios
|
|
20
|
+
- **Understand fix application** before running it on your code
|
|
21
|
+
|
|
22
|
+
### As the Agent
|
|
23
|
+
- **Compare output structure** when parsing scan results
|
|
24
|
+
- **Verify fix format** when applying auto-fixes
|
|
25
|
+
- **Reference command patterns** when building complex rule selectors
|
|
26
|
+
- **Use as templates** when explaining results to users
|
|
27
|
+
|
|
28
|
+
## Usage from SKILL.md
|
|
29
|
+
|
|
30
|
+
These files are **reference examples**, not loaded by default. Reference them in specific scenarios:
|
|
31
|
+
|
|
32
|
+
```markdown
|
|
33
|
+
**For large result sets (5000+ violations)**, compare against `examples/large-scan-output.json` to verify your summary format matches the expected structure.
|
|
34
|
+
|
|
35
|
+
**Before applying fixes**, show the user the before/after comparison from `examples/fix-application-before-after.md` to set expectations.
|
|
36
|
+
|
|
37
|
+
**For complex command construction**, reference `examples/command-variations.md` to find the pattern that matches the user's intent.
|
|
38
|
+
```
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"metadata": {
|
|
3
|
+
"engine": "Recommended",
|
|
4
|
+
"executedAt": "2026-05-19T10:15:30.123Z",
|
|
5
|
+
"filesAnalyzed": 45,
|
|
6
|
+
"violationCount": 127
|
|
7
|
+
},
|
|
8
|
+
"violations": [
|
|
9
|
+
{
|
|
10
|
+
"rule": "ApexCRUDViolation",
|
|
11
|
+
"engine": "pmd",
|
|
12
|
+
"severity": 2,
|
|
13
|
+
"message": "Validate CRUD permission before SOQL/DML operation",
|
|
14
|
+
"file": "force-app/main/default/classes/AccountService.cls",
|
|
15
|
+
"line": 42,
|
|
16
|
+
"column": 9,
|
|
17
|
+
"fix": null
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"rule": "no-var",
|
|
21
|
+
"engine": "eslint",
|
|
22
|
+
"severity": 3,
|
|
23
|
+
"message": "Unexpected var, use let or const instead.",
|
|
24
|
+
"file": "force-app/main/default/lwc/accountCard/accountCard.js",
|
|
25
|
+
"line": 12,
|
|
26
|
+
"column": 5,
|
|
27
|
+
"fix": {
|
|
28
|
+
"range": [180, 183],
|
|
29
|
+
"text": "let"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"rule": "ApexDoc",
|
|
34
|
+
"engine": "pmd",
|
|
35
|
+
"severity": 3,
|
|
36
|
+
"message": "Missing ApexDoc comment",
|
|
37
|
+
"file": "force-app/main/default/classes/AccountService.cls",
|
|
38
|
+
"line": 15,
|
|
39
|
+
"column": 1,
|
|
40
|
+
"fix": null
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"rule": "@lwc/lwc/no-inner-html",
|
|
44
|
+
"engine": "eslint",
|
|
45
|
+
"severity": 2,
|
|
46
|
+
"message": "Disallow use of innerHTML",
|
|
47
|
+
"file": "force-app/main/default/lwc/riskComponent/riskComponent.js",
|
|
48
|
+
"line": 28,
|
|
49
|
+
"column": 9,
|
|
50
|
+
"fix": null
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"rule": "prefer-const",
|
|
54
|
+
"engine": "eslint",
|
|
55
|
+
"severity": 3,
|
|
56
|
+
"message": "'data' is never reassigned. Use 'const' instead.",
|
|
57
|
+
"file": "force-app/main/default/lwc/accountCard/accountCard.js",
|
|
58
|
+
"line": 18,
|
|
59
|
+
"column": 5,
|
|
60
|
+
"fix": {
|
|
61
|
+
"range": [245, 248],
|
|
62
|
+
"text": "const"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"summary": {
|
|
67
|
+
"bySeverity": {
|
|
68
|
+
"1": 0,
|
|
69
|
+
"2": 32,
|
|
70
|
+
"3": 78,
|
|
71
|
+
"4": 15,
|
|
72
|
+
"5": 2
|
|
73
|
+
},
|
|
74
|
+
"byEngine": {
|
|
75
|
+
"pmd": 65,
|
|
76
|
+
"eslint": 58,
|
|
77
|
+
"regex": 4
|
|
78
|
+
},
|
|
79
|
+
"topRules": [
|
|
80
|
+
{"rule": "ApexDoc", "count": 45},
|
|
81
|
+
{"rule": "no-var", "count": 28},
|
|
82
|
+
{"rule": "prefer-const", "count": 19},
|
|
83
|
+
{"rule": "ApexCRUDViolation", "count": 12},
|
|
84
|
+
{"rule": "@lwc/lwc/no-inner-html", "count": 8}
|
|
85
|
+
],
|
|
86
|
+
"topFiles": [
|
|
87
|
+
{"file": "force-app/main/default/classes/AccountService.cls", "count": 23},
|
|
88
|
+
{"file": "force-app/main/default/lwc/accountCard/accountCard.js", "count": 18},
|
|
89
|
+
{"file": "force-app/main/default/classes/ContactTriggerHandler.cls", "count": 15}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|