Skip to content

forcedotcom/sf-skills / plugins/builder/salesforce-code-quality/skills/dx-code-analyzer-run

dx-code-analyzer-run

Verified

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. Also handles post-scan exploration: filtering results by engine/severity/category/file, and explaining what rules mean. TRIGGER when: user says 'scan my code', 'check security issues', 'run PMD/ESLint', 'find duplicates', 'analyze Flows', 'check vulnerable libraries', 'AppExchange review', 'lint my LWC', 'static analysis', 'code quality', 'show security violations', 'what is this rule', 'explain ApexCRUDViolation', 'filter results', or mentions engines/file types (.cls, .trigger, .js, .flow-meta.xml). Use this skill for scanning, exploring results, and listing rules. DO NOT TRIGGER when: user asks only about installation/configuration (use dx-code-analyzer-configure), or wants to create a custom rule (use dx-code-analyzer-custom-rule-create).

examples/fix-application-before-after.md

View on GitHub
# Fix Application: Before & After

This example demonstrates engine-provided auto-fix behavior on a small codebase.

## Initial Scan Results

**Command:**
```bash
sf code-analyzer run --rule-selector Recommended --output-file ./results.json --include-fixes
```

**Summary:**
- Total violations: 248
- Fixable violations: 67 (27%)

### Fixable Rules

| Rule | Engine | Severity | Count |
|------|--------|----------|-------|
| no-var | eslint | 3 | 42 |
| prefer-const | eslint | 3 | 18 |
| @salesforce-ux/slds/no-hardcoded-values-slds2 | eslint | 4 | 5 |
| no-extra-boolean-cast | eslint | 3 | 2 |

---

## Before Fix: Sample Violations

### Violation 1: no-var
**File:** `force-app/main/default/lwc/accountCard/accountCard.js:12`

```javascript
export default class AccountCard extends LightningElement {
    handleClick() {
        var accountId = this.recordId;  // ← violation
        var data = this.fetchData(accountId);  // ← violation
        this.processData(data);
    }
}
```

### Violation 2: prefer-const
**File:** `force-app/main/default/lwc/utils/dataProcessor.js:8`

```javascript
export function processRecords(records) {
    let result = [];  // ← violation (never reassigned)
    records.forEach(r => result.push(transform(r)));
    return result;
}
```

### Violation 3: @salesforce-ux/slds/no-hardcoded-values-slds2
**File:** `force-app/main/default/lwc/accountCard/accountCard.css:4`

```css
.account-card {
    border-radius: 4px;  /* ← violation */
    padding: 16px;  /* ← violation */
}
```

---

## Apply Fixes

**Command:**
```bash
node <skill_dir>/scripts/apply-fixes.js ./results.json
```

**Output:**
```json
{
  "success": true,
  "filesModified": 15,
  "fixesApplied": 67,
  "fixesSkipped": 0
}
```

---

## After Fix: Corrected Code

### Fix 1: no-var → let
**File:** `force-app/main/default/lwc/accountCard/accountCard.js:12`

```javascript
export default class AccountCard extends LightningElement {
    handleClick() {
        let accountId = this.recordId;  // ✓ fixed
        let data = this.fetchData(accountId);  // ✓ fixed
        this.processData(data);
    }
}
```

### Fix 2: let → const
**File:** `force-app/main/default/lwc/utils/dataProcessor.js:8`

```javascript
export function processRecords(records) {
    const result = [];  // ✓ fixed
    records.forEach(r => result.push(transform(r)));
    return result;
}
```

### Fix 3: Hardcoded values → SLDS tokens
**File:** `force-app/main/default/lwc/accountCard/accountCard.css:4`

```css
.account-card {
    border-radius: var(--slds-c-card-radius-border);  /* ✓ fixed */
    padding: var(--slds-c-card-spacing-block);  /* ✓ fixed */
}
```

---

## Verification Scan

**Command:**
```bash
sf code-analyzer run --rule-selector Recommended --output-file ./results-after.json --include-fixes
```

**Summary:**
- Total violations: 181 (↓ 67 from 248)
- Fixable violations: 0

**Result:** All 67 fixable violations resolved. Remaining 181 violations require manual fixes (e.g., ApexDoc comments, CRUD checks).

---

## Key Takeaways

1. **Engine-provided fixes are safe**: They're deterministic transformations, not AI-generated code.
2. **Apply, then verify**: Always re-scan after applying fixes to confirm no regressions.
3. **Not all violations are fixable**: Security issues like CRUD violations require manual code review.
4. **Files modified count ≠ fixes count**: Multiple violations in one file count as one file modification.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall