agent-docs 1.0.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.
Files changed (44) hide show
  1. package/.cursor/plans/OPTIMISE.md +379 -0
  2. package/.cursor/plans/VERSIONING.md +207 -0
  3. package/.cursor/rules/IMPORTANT.mdc +97 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +13 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  6. package/.github/dependabot.yml +38 -0
  7. package/.github/pull_request_template.md +10 -0
  8. package/.github/workflows/format.yml +35 -0
  9. package/CODE_OF_CONDUCT.md +64 -0
  10. package/CONTRIBUTING.md +52 -0
  11. package/LICENSE.md +20 -0
  12. package/PLAN.md +707 -0
  13. package/README.md +133 -0
  14. package/SECURITY.md +21 -0
  15. package/docs/APEXANNOTATIONS.md +472 -0
  16. package/docs/APEXDOC.md +198 -0
  17. package/docs/CML.md +877 -0
  18. package/docs/CODEANALYZER.md +435 -0
  19. package/docs/CONTEXTDEFINITIONS.md +617 -0
  20. package/docs/ESLINT.md +827 -0
  21. package/docs/ESLINTJSDOC.md +520 -0
  22. package/docs/FIELDSERVICE.md +4452 -0
  23. package/docs/GRAPHBINARY.md +208 -0
  24. package/docs/GRAPHENGINE.md +616 -0
  25. package/docs/GRAPHML.md +337 -0
  26. package/docs/GRAPHSON.md +302 -0
  27. package/docs/GREMLIN.md +490 -0
  28. package/docs/GRYO.md +232 -0
  29. package/docs/HUSKY.md +106 -0
  30. package/docs/JEST.md +387 -0
  31. package/docs/JORJE.md +537 -0
  32. package/docs/JSDOC.md +621 -0
  33. package/docs/PMD.md +910 -0
  34. package/docs/PNPM.md +409 -0
  35. package/docs/PRETTIER.md +716 -0
  36. package/docs/PRETTIERAPEX.md +874 -0
  37. package/docs/REVENUETRANSACTIONMANAGEMENT.md +887 -0
  38. package/docs/TINKERPOP.md +252 -0
  39. package/docs/VITEST.md +706 -0
  40. package/docs/VSCODE.md +231 -0
  41. package/docs/XPATH31.md +213 -0
  42. package/package.json +32 -0
  43. package/postinstall.mjs +51 -0
  44. package/prettier.config.js +18 -0
@@ -0,0 +1,435 @@
1
+ # Salesforce Code Analyzer Reference
2
+
3
+ > **Version**: 1.0.0
4
+
5
+ > **Purpose**: Static code analysis for Salesforce (PMD, ESLint, CPD, Regex,
6
+ > Flow Scanner, RetireJS, SFGE) **Install**:
7
+ > `sf plugins install @salesforce/sfdx-scanner`
8
+
9
+ ---
10
+
11
+ ## CLI Commands
12
+
13
+ ### Basic Usage
14
+
15
+ ```bash
16
+ sf scanner:run --target "path/to/source" # Analyze directory
17
+ sf scanner:run --target "file.cls" # Analyze file
18
+ sf scanner:run --target "path" --engine pmd # Specific engine
19
+ sf scanner:run dfa --target "path" --rule-selector sfge # Data-flow analysis
20
+ ```
21
+
22
+ ### Rule Management
23
+
24
+ ```bash
25
+ sf scanner:rule:list # All rules
26
+ sf scanner:rule:list --engine pmd # Engine-specific
27
+ sf scanner:rule:list --rule-selector RuleName --view detail # Rule details
28
+ ```
29
+
30
+ ### Output Formats
31
+
32
+ | Format | Command |
33
+ | ------ | ----------------------------------------------------------------------- |
34
+ | JSON | `sf scanner:run --target "path" --format json --outfile results.json` |
35
+ | HTML | `sf scanner:run --target "path" --format html --outfile results.html` |
36
+ | CSV | `sf scanner:run --target "path" --format csv --outfile results.csv` |
37
+ | XML | `sf scanner:run --target "path" --format xml --outfile results.xml` |
38
+ | SARIF | `sf scanner:run --target "path" --format sarif --outfile results.sarif` |
39
+
40
+ ### Filtering
41
+
42
+ | Option | Description | Example |
43
+ | ---------------------- | ------------------- | -------------------------------------- |
44
+ | `--engine` | Filter by engine | `--engine pmd,eslint` |
45
+ | `--category` | Filter by category | `--category "Security,Best Practices"` |
46
+ | `--rule-selector` | Filter by rule name | `--rule-selector "Rule1,Rule2"` |
47
+ | `--severity-threshold` | Min severity level | `--severity-threshold 2` |
48
+ | `--tag` | Filter by tag | `--tag "Recommended"` |
49
+
50
+ **Severity Levels**: `1`/Critical, `2`/High, `3`/Moderate, `4`/Low, `5`/Info
51
+
52
+ ### Options
53
+
54
+ | Option | Description |
55
+ | -------------------------- | ------------------------------- |
56
+ | `--config-file` | Custom config path |
57
+ | `--project-dir` | Project root for relative paths |
58
+ | `--verbose` | Verbose output |
59
+ | `--violations-cause-error` | Exit 1 on violations |
60
+ | `--normalize-severity` | Include test classes |
61
+
62
+ **Exit Codes**: `0` = Success | `1` = Violations or error
63
+
64
+ ---
65
+
66
+ ## Configuration File
67
+
68
+ Auto-discovered: `code-analyzer.yml` or `code-analyzer.yaml` in project root
69
+
70
+ ### Top-Level Properties
71
+
72
+ | Property | Type | Default | Description |
73
+ | ------------- | ------ | ------- | --------------------------------------------------------- |
74
+ | `config_root` | string | null | Base path for relative paths (auto: config parent or CWD) |
75
+ | `log_folder` | string | null | Log directory (auto: system temp) |
76
+ | `log_level` | number | 4 | `1`/Error, `2`/Warn, `3`/Info, `4`/Debug, `5`/Fine |
77
+ | `rules` | object | {} | Rule overrides: `rules.{engine}.{rule}.{property}` |
78
+ | `engines` | object | {} | Engine config: `engines.{engine}.{property}` |
79
+
80
+ ### Rule Overrides
81
+
82
+ ```yaml
83
+ rules:
84
+ pmd:
85
+ RuleName:
86
+ severity: 'High' # or 1-5
87
+ tags: ['Recommended', 'Custom']
88
+ eslint:
89
+ sort-vars:
90
+ severity: 'Info'
91
+ tags: ['Suggestion']
92
+ ```
93
+
94
+ **Note**: Only `severity` and `tags` supported for PMD. Property overrides
95
+ require custom ruleset XML with `ref=` syntax.
96
+
97
+ ---
98
+
99
+ ## Engine Configuration
100
+
101
+ ### PMD Engine
102
+
103
+ | Property | Type | Default | Description |
104
+ | ----------------- | ------- | ------- | ------------------------- |
105
+ | `disable_engine` | boolean | false | Disable PMD |
106
+ | `custom_rulesets` | array | [] | Ruleset XML paths |
107
+ | `java_command` | string | null | Java path (auto-discover) |
108
+
109
+ ```yaml
110
+ engines:
111
+ pmd:
112
+ custom_rulesets:
113
+ - rulesets/design/MyRule.xml
114
+ ```
115
+
116
+ ### Regex Engine
117
+
118
+ | Property | Type | Default | Description |
119
+ | ---------------- | ------- | ------- | ------------------ |
120
+ | `disable_engine` | boolean | false | Disable Regex |
121
+ | `custom_rules` | object | {} | Custom regex rules |
122
+
123
+ ```yaml
124
+ engines:
125
+ regex:
126
+ custom_rules:
127
+ NoTodoComments:
128
+ regex: /\/\/[ \t]*TODO/gi # Must include 'g' flag
129
+ file_extensions: ['.cls', '.trigger']
130
+ description: 'Prevents TODO comments'
131
+ violation_message: 'TODO found'
132
+ severity: 'Info' # or 1-5
133
+ tags: ['TechDebt']
134
+ ```
135
+
136
+ **Rule Properties**:
137
+
138
+ | Property | Required | Default | Description |
139
+ | ------------------- | -------- | --------------- | ------------------------------------- |
140
+ | `regex` | Yes | — | Pattern with flags (must include `g`) |
141
+ | `file_extensions` | Yes | — | File extensions to match |
142
+ | `description` | Yes | — | Rule description |
143
+ | `violation_message` | No | Auto | Custom message |
144
+ | `severity` | No | 3/Moderate | Severity level |
145
+ | `tags` | No | ["Recommended"] | Tags (auto-adds "Custom") |
146
+
147
+ **Common Patterns**:
148
+
149
+ ```yaml
150
+ /\/\/[ \t]*(TODO|FIXME|HACK)/gi # TODO/FIXME comments
151
+ /(console\.(log|debug)|System\.debug)/gi # Debug statements
152
+ /['"](00[0-9A-Za-z]{15,18})['"]/g # Hardcoded Salesforce IDs
153
+ /catch\s*\([^)]+\)\s*\{\s*\}/g # Empty catch blocks
154
+ ```
155
+
156
+ ### ESLint Engine
157
+
158
+ | Property | Type | Default | Description |
159
+ | -------------------------------- | ------- | --------- | ----------------------- |
160
+ | `disable_engine` | boolean | false | Disable ESLint |
161
+ | `eslint_config_file` | string | null | ESLint config path |
162
+ | `auto_discover_eslint_config` | boolean | false | Auto-find config |
163
+ | `disable_javascript_base_config` | boolean | false | Disable JS rules |
164
+ | `disable_lwc_base_config` | boolean | false | Disable LWC rules |
165
+ | `disable_typescript_base_config` | boolean | false | Disable TS rules |
166
+ | `file_extensions` | object | See below | Extensions per language |
167
+
168
+ **Default file_extensions**: `javascript: ['.js', '.cjs', '.mjs']`,
169
+ `typescript: ['.ts']`, `html: ['.html', '.htm', '.cmp']`,
170
+ `css: ['.css', '.scss']`
171
+
172
+ ### CPD Engine (Copy/Paste Detector)
173
+
174
+ | Property | Type | Default | Description |
175
+ | ---------------------- | ------- | --------- | ---------------------------- |
176
+ | `disable_engine` | boolean | false | Disable CPD |
177
+ | `java_command` | string | null | Java path (auto-discover) |
178
+ | `file_extensions` | object | See below | Extensions per language |
179
+ | `minimum_tokens` | object | 100 | Token threshold per language |
180
+ | `skip_duplicate_files` | boolean | false | Skip same-name/length files |
181
+
182
+ **Supported Languages**: Apex (`.cls`, `.trigger`), HTML, JavaScript,
183
+ TypeScript, Visualforce (`.page`, `.component`), XML
184
+
185
+ ```yaml
186
+ engines:
187
+ cpd:
188
+ minimum_tokens:
189
+ apex: 100
190
+ javascript: 75
191
+ ```
192
+
193
+ ### Flow Scanner Engine
194
+
195
+ | Property | Type | Default | Description |
196
+ | ---------------- | ------- | ------- | --------------------------- |
197
+ | `disable_engine` | boolean | false | Disable Flow Scanner |
198
+ | `python_command` | string | null | Python path (auto-discover) |
199
+
200
+ **Rules**: `SystemContextWithoutSharing` (High) — CRUD bypassing sharing |
201
+ `SystemContextWithSharing` (Low) — CRUD with sharing
202
+
203
+ | Context | Permissions | Risk |
204
+ | ---------------------- | ------------------------------ | ------------------------- |
205
+ | User Context | User's perms/sharing/FLS | Default—use this |
206
+ | System Without Sharing | Bypasses all | High—privilege escalation |
207
+ | System With Sharing | System perms, respects sharing | Moderate |
208
+
209
+ **Fix**: Flow Builder → Flow Properties → Advanced → "Run the flow in" → "User
210
+ Context"
211
+
212
+ ### RetireJS Engine
213
+
214
+ Security vulnerability detection in JavaScript dependencies using
215
+ community-maintained database.
216
+
217
+ | Property | Type | Default | Description |
218
+ | ---------------- | ------- | ------- | ---------------- |
219
+ | `disable_engine` | boolean | false | Disable RetireJS |
220
+
221
+ ```yaml
222
+ engines:
223
+ retire-js:
224
+ disable_engine: false
225
+
226
+ rules:
227
+ retire-js:
228
+ RuleName:
229
+ severity: 'High'
230
+ tags: ['Security']
231
+ ```
232
+
233
+ **Usage**: `sf scanner:rule:list --engine retire-js`
234
+
235
+ ---
236
+
237
+ ## Complete Example
238
+
239
+ ```yaml
240
+ config_root: null
241
+ log_folder: null
242
+ log_level: 4
243
+
244
+ rules:
245
+ pmd:
246
+ NoSingleLetterVariableNames:
247
+ severity: 'High'
248
+ tags: ['Recommended']
249
+
250
+ engines:
251
+ pmd:
252
+ custom_rulesets:
253
+ - rulesets/design/MyRules.xml
254
+
255
+ regex:
256
+ custom_rules:
257
+ NoConsecutiveBlankLines:
258
+ regex: /\n\s*\n\s*\n/g
259
+ file_extensions: ['.cls', '.trigger']
260
+ description: 'Prevents consecutive blank lines'
261
+ severity: 'Moderate'
262
+ tags: ['CodeStyle']
263
+
264
+ eslint:
265
+ auto_discover_eslint_config: true
266
+
267
+ cpd:
268
+ minimum_tokens:
269
+ apex: 100
270
+ ```
271
+
272
+ ---
273
+
274
+ ## MCP Tools
275
+
276
+ > **Status**: Developer Preview
277
+
278
+ Natural language interaction with Code Analyzer via Model Context Protocol.
279
+
280
+ | Tool | Equivalent CLI | Description |
281
+ | ----------------------------- | ------------------------------------ | --------------------------------------------------- |
282
+ | `run_code_analyzer` | `sf scanner:run` | Analyze code (max 10 files, Recommended rules only) |
283
+ | `describe_code_analyzer_rule` | `sf scanner:rule:list --view detail` | Get rule metadata and examples |
284
+
285
+ **Setup — Agentforce Vibes Extension**: Pre-configured, no setup needed
286
+
287
+ **Setup — Other MCP Clients**:
288
+
289
+ ```bash
290
+ npm install -g @salesforce/mcp-server-dx
291
+ ```
292
+
293
+ ```json
294
+ {
295
+ "mcpServers": {
296
+ "salesforce-dx": {
297
+ "command": "sf",
298
+ "args": ["mcp", "start", "--allow-non-ga-tools"]
299
+ }
300
+ }
301
+ }
302
+ ```
303
+
304
+ **Limitations**: Max 10 files | Recommended rules only | LLM costs may apply |
305
+ Requires network
306
+
307
+ **Use CLI/VS Code for**: Batch analysis, CI/CD, custom rules, offline work
308
+
309
+ ---
310
+
311
+ ## CI/CD Integration
312
+
313
+ ### GitHub Actions
314
+
315
+ ```yaml
316
+ name: Code Analysis
317
+ on: { pull_request: { branches: [main] } }
318
+
319
+ jobs:
320
+ analyze:
321
+ runs-on: ubuntu-latest
322
+ steps:
323
+ - uses: actions/checkout@v4
324
+ - uses: actions/setup-node@v4
325
+ with: { node-version: '18' }
326
+ - run: npm install -g @salesforce/cli
327
+ - run: sf plugins install @salesforce/sfdx-scanner
328
+ - run:
329
+ sf scanner:run --target "force-app/main/default" --format json
330
+ --outfile results.json --violations-cause-error
331
+ --severity-threshold 2
332
+ - uses: actions/upload-artifact@v4
333
+ if: always()
334
+ with: { name: scanner-results, path: results.json }
335
+ ```
336
+
337
+ ### GitLab CI
338
+
339
+ ```yaml
340
+ code-analyzer:
341
+ stage: analyze
342
+ image: node:18
343
+ before_script:
344
+ - npm install -g @salesforce/cli
345
+ - sf plugins install @salesforce/sfdx-scanner
346
+ script:
347
+ - sf scanner:run --target "force-app/main/default" --format json
348
+ --outfile results.json --violations-cause-error
349
+ artifacts:
350
+ when: always
351
+ paths: [results.json]
352
+ reports: { codequality: results.json }
353
+ ```
354
+
355
+ ### Jenkins
356
+
357
+ ```groovy
358
+ pipeline {
359
+ agent any
360
+ stages {
361
+ stage('Code Analysis') {
362
+ steps {
363
+ sh 'npm install -g @salesforce/cli && sf plugins install @salesforce/sfdx-scanner'
364
+ sh 'sf scanner:run --target "force-app/main/default" --format json --outfile results.json --violations-cause-error'
365
+ }
366
+ }
367
+ }
368
+ post { always { archiveArtifacts artifacts: 'results.json' } }
369
+ }
370
+ ```
371
+
372
+ ### Azure DevOps
373
+
374
+ ```yaml
375
+ pool: { vmImage: 'ubuntu-latest' }
376
+ steps:
377
+ - task: NodeTool@0
378
+ inputs: { versionSpec: '18.x' }
379
+ - script:
380
+ npm install -g @salesforce/cli && sf plugins install
381
+ @salesforce/sfdx-scanner
382
+ - script:
383
+ sf scanner:run --target "force-app/main/default" --format json
384
+ --outfile results.json --violations-cause-error
385
+ ```
386
+
387
+ ### Advanced Patterns
388
+
389
+ **Changed Files Only** (GitHub):
390
+
391
+ ```yaml
392
+ - uses: tj-actions/changed-files@v40
393
+ id: changed-files
394
+ with: { files: "**/*.cls\n**/*.trigger" }
395
+ - if: steps.changed-files.outputs.any_changed == 'true'
396
+ run:
397
+ sf scanner:run --target "${{ steps.changed-files.outputs.all_changed_files
398
+ }}" --violations-cause-error
399
+ ```
400
+
401
+ **Baseline**: `sf scanner:run --format json --outfile current.json` → compare
402
+ with baseline.json
403
+
404
+ **SARIF**:
405
+ `sf scanner:run --format sarif --outfile security.sarif --category Security`
406
+
407
+ ### Best Practices
408
+
409
+ 1. `--violations-cause-error` to fail fast
410
+ 2. `--severity-threshold 2` for High/Critical only
411
+ 3. Cache SF CLI and plugins
412
+ 4. Store results as artifacts
413
+
414
+ ---
415
+
416
+ ## Common Workflows
417
+
418
+ ```bash
419
+ sf scanner:run --target force-app/main/default/classes --tag "Recommended" # Quick
420
+ sf scanner:run --target force-app/main/default --category Security --severity-threshold 2 # Security
421
+ sf scanner:run --target force-app/main/default --format json --outfile results.json --violations-cause-error # CI/CD
422
+ sf scanner:run --target $(git diff --cached --name-only | grep -E '\.(cls|trigger|js)$' | tr '\n' ',') # Pre-commit
423
+ ```
424
+
425
+ ---
426
+
427
+ ## Related Documentation
428
+
429
+ | Category | Reference |
430
+ | ---------------- | --------------------------------------------------------------------------------------------------------------------- |
431
+ | PMD | [PMD.md](PMD.md) — Rulesets, CLI, CPD, configuration |
432
+ | ESLint | [ESLINT.md](ESLINT.md) — JS/TS/LWC configuration |
433
+ | Graph Engine | [GRAPHENGINE.md](GRAPHENGINE.md) — SFGE data-flow analysis |
434
+ | Rule Development | [XPATH31.md](XPATH31.md), [PMD.md#apex-ast-reference](PMD.md#apex-ast-reference) |
435
+ | Official Docs | [Code Analyzer Guide](https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/code-analyzer.md) |