@salesforce/afv-skills 1.17.0 → 1.18.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/building-sf-integrations/SKILL.md +1 -1
- package/skills/configuring-code-analyzer/SKILL.md +482 -0
- package/skills/configuring-code-analyzer/examples/apex-project-config.yml +41 -0
- package/skills/configuring-code-analyzer/examples/ci-github-actions.yml +96 -0
- package/skills/configuring-code-analyzer/examples/fullstack-project-config.yml +46 -0
- package/skills/configuring-code-analyzer/examples/lwc-project-config.yml +26 -0
- package/skills/configuring-code-analyzer/references/ci-cd-templates.md +648 -0
- package/skills/configuring-code-analyzer/references/config-schema.md +257 -0
- package/skills/configuring-code-analyzer/references/diagnostic-flow.md +70 -0
- package/skills/configuring-code-analyzer/references/engine-prerequisites.md +276 -0
- package/skills/configuring-code-analyzer/references/rule-name-resolution.md +67 -0
- package/skills/configuring-code-analyzer/references/troubleshooting.md +298 -0
- package/skills/configuring-code-analyzer/scripts/check-prerequisites.sh +189 -0
- package/skills/configuring-code-analyzer/scripts/generate-config.sh +143 -0
- package/skills/configuring-code-analyzer/scripts/validate-config.sh +153 -0
- package/skills/managing-cdc-enablement/SKILL.md +164 -0
- package/skills/managing-cdc-enablement/assets/PlatformEventChannel-template.xml +5 -0
- package/skills/managing-cdc-enablement/assets/PlatformEventChannelMember-template.xml +11 -0
- package/skills/managing-cdc-enablement/references/deploy-troubleshooting.md +73 -0
- package/skills/managing-cdc-enablement/references/filter-expressions.md +93 -0
- package/skills/running-code-analyzer/SKILL.md +264 -267
- package/skills/running-code-analyzer/references/post-scan-workflows.md +286 -0
- package/skills/running-code-analyzer/scripts/describe-rule.js +382 -0
- package/skills/running-code-analyzer/scripts/list-rules.js +260 -0
- package/skills/running-code-analyzer/scripts/query-results.js +230 -0
- package/skills/using-salesforce-archive/SKILL.md +121 -0
- package/skills/using-salesforce-archive/examples/monitor-failed-jobs.md +47 -0
- package/skills/using-salesforce-archive/references/archive-activity-entity.md +59 -0
- package/skills/using-salesforce-archive/references/connect-api-operations.md +157 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# Troubleshooting Code Analyzer Setup
|
|
2
|
+
|
|
3
|
+
Common issues and solutions during installation and configuration.
|
|
4
|
+
|
|
5
|
+
## Installation Issues
|
|
6
|
+
|
|
7
|
+
### sf CLI Not Found
|
|
8
|
+
|
|
9
|
+
**Symptom:** `sf: command not found` or `'sf' is not recognized`
|
|
10
|
+
|
|
11
|
+
**Solutions:**
|
|
12
|
+
1. Check if installed: `which sf` or `where sf`
|
|
13
|
+
2. If not installed: `npm install -g @salesforce/cli`
|
|
14
|
+
3. If installed but not in PATH:
|
|
15
|
+
- macOS/Linux: Add `export PATH="$(npm prefix -g)/bin:$PATH"` to `~/.zshrc` or `~/.bashrc`
|
|
16
|
+
- Windows: Add npm global bin to System PATH
|
|
17
|
+
4. Restart terminal after PATH changes
|
|
18
|
+
|
|
19
|
+
### Plugin Install Fails
|
|
20
|
+
|
|
21
|
+
**Symptom:** `Error: EACCES permission denied` or timeout errors
|
|
22
|
+
|
|
23
|
+
**Solutions:**
|
|
24
|
+
| Error | Fix |
|
|
25
|
+
|-------|-----|
|
|
26
|
+
| Permission denied | `sudo sf plugins install @salesforce/plugin-code-analyzer` or fix npm permissions |
|
|
27
|
+
| Network timeout | Check proxy: `npm config set proxy http://proxy:port` |
|
|
28
|
+
| Node version error | Upgrade Node.js to 18+: `nvm install 20 && nvm use 20` |
|
|
29
|
+
| Corrupt install | `sf plugins uninstall @salesforce/plugin-code-analyzer && sf plugins install @salesforce/plugin-code-analyzer` |
|
|
30
|
+
|
|
31
|
+
### Plugin Version Mismatch
|
|
32
|
+
|
|
33
|
+
**Symptom:** Command flags don't work, unexpected behavior
|
|
34
|
+
|
|
35
|
+
**Check version:**
|
|
36
|
+
```bash
|
|
37
|
+
sf plugins --core | grep code-analyzer
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Expected:** `@salesforce/plugin-code-analyzer` v5.x+
|
|
41
|
+
|
|
42
|
+
**If on v3/v4 (legacy):**
|
|
43
|
+
```bash
|
|
44
|
+
sf plugins uninstall @salesforce/sfdx-scanner # Remove legacy v3
|
|
45
|
+
sf plugins install @salesforce/plugin-code-analyzer # Install v5+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Java Issues
|
|
49
|
+
|
|
50
|
+
### Java Not Found
|
|
51
|
+
|
|
52
|
+
**Symptom:** PMD/CPD/SFGE fails with `java: command not found` or `JAVA_HOME not set`
|
|
53
|
+
|
|
54
|
+
**Fix:**
|
|
55
|
+
```bash
|
|
56
|
+
# macOS
|
|
57
|
+
brew install openjdk@11
|
|
58
|
+
export JAVA_HOME="/opt/homebrew/opt/openjdk@11"
|
|
59
|
+
export PATH="$JAVA_HOME/bin:$PATH"
|
|
60
|
+
|
|
61
|
+
# Add to ~/.zshrc for persistence
|
|
62
|
+
echo 'export JAVA_HOME="/opt/homebrew/opt/openjdk@11"' >> ~/.zshrc
|
|
63
|
+
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.zshrc
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Wrong Java Version
|
|
67
|
+
|
|
68
|
+
**Symptom:** `UnsupportedClassVersionError` or `class file version X.Y`
|
|
69
|
+
|
|
70
|
+
**Fix:** Code Analyzer needs Java 11+. Check and switch:
|
|
71
|
+
```bash
|
|
72
|
+
java -version # Check current
|
|
73
|
+
|
|
74
|
+
# If using SDKMAN:
|
|
75
|
+
sdk install java 11.0.21-tem
|
|
76
|
+
sdk use java 11.0.21-tem
|
|
77
|
+
|
|
78
|
+
# If using Homebrew:
|
|
79
|
+
brew install openjdk@11
|
|
80
|
+
export JAVA_HOME="/opt/homebrew/opt/openjdk@11"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### SFGE Out of Memory
|
|
84
|
+
|
|
85
|
+
**Symptom:** `java.lang.OutOfMemoryError: Java heap space`
|
|
86
|
+
|
|
87
|
+
**Fix:** Increase heap in `code-analyzer.yml`:
|
|
88
|
+
```yaml
|
|
89
|
+
engines:
|
|
90
|
+
sfge:
|
|
91
|
+
java_max_heap_size: "4g" # Default is 1g, increase for large projects
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Guidelines:**
|
|
95
|
+
| Project Size | Heap Recommendation |
|
|
96
|
+
|-------------|-------------------|
|
|
97
|
+
| < 200 Apex classes | 2g |
|
|
98
|
+
| 200-500 Apex classes | 4g |
|
|
99
|
+
| 500-1000 Apex classes | 6g |
|
|
100
|
+
| 1000+ Apex classes | 8g |
|
|
101
|
+
|
|
102
|
+
## Node.js Issues
|
|
103
|
+
|
|
104
|
+
### Node.js Version Too Old
|
|
105
|
+
|
|
106
|
+
**Symptom:** `Error: Node.js v16 is not supported` or ESLint failures
|
|
107
|
+
|
|
108
|
+
**Fix:**
|
|
109
|
+
```bash
|
|
110
|
+
# Check version
|
|
111
|
+
node --version
|
|
112
|
+
|
|
113
|
+
# Upgrade via nvm
|
|
114
|
+
nvm install 20
|
|
115
|
+
nvm use 20
|
|
116
|
+
nvm alias default 20
|
|
117
|
+
|
|
118
|
+
# Or via Homebrew
|
|
119
|
+
brew upgrade node
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### ESLint Config Conflicts
|
|
123
|
+
|
|
124
|
+
**Symptom:** ESLint rules not loading, or unexpected rules appearing
|
|
125
|
+
|
|
126
|
+
**Possible causes:**
|
|
127
|
+
1. Project has its own `.eslintrc.*` conflicting with Code Analyzer's built-in config
|
|
128
|
+
2. `auto_discover_eslint_config` is enabled but project config is incompatible
|
|
129
|
+
|
|
130
|
+
**Fix options:**
|
|
131
|
+
```yaml
|
|
132
|
+
# Option A: Disable auto-discovery (use only Code Analyzer's built-in rules)
|
|
133
|
+
engines:
|
|
134
|
+
eslint:
|
|
135
|
+
auto_discover_eslint_config: false
|
|
136
|
+
|
|
137
|
+
# Option B: Use project's config exclusively
|
|
138
|
+
engines:
|
|
139
|
+
eslint:
|
|
140
|
+
auto_discover_eslint_config: true
|
|
141
|
+
disable_javascript_base_config: true
|
|
142
|
+
disable_typescript_base_config: true
|
|
143
|
+
disable_lwc_base_config: true
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Configuration Issues
|
|
147
|
+
|
|
148
|
+
### Config File Not Picked Up
|
|
149
|
+
|
|
150
|
+
**Symptom:** Custom settings not applied, default behavior persists
|
|
151
|
+
|
|
152
|
+
**Checklist:**
|
|
153
|
+
1. File must be named exactly `code-analyzer.yml` or `code-analyzer.yaml`
|
|
154
|
+
2. File must be in the current working directory when running commands
|
|
155
|
+
3. Or specify explicitly: `--config-file ./path/to/code-analyzer.yml`
|
|
156
|
+
4. Check for YAML syntax errors: `sf code-analyzer config --config-file code-analyzer.yml`
|
|
157
|
+
|
|
158
|
+
### YAML Syntax Errors
|
|
159
|
+
|
|
160
|
+
**Symptom:** `YAMLException: bad indentation` or `unexpected token`
|
|
161
|
+
|
|
162
|
+
**Common YAML mistakes:**
|
|
163
|
+
```yaml
|
|
164
|
+
# WRONG - tabs instead of spaces
|
|
165
|
+
engines:
|
|
166
|
+
pmd: # TAB character - YAML requires spaces!
|
|
167
|
+
|
|
168
|
+
# CORRECT - spaces only
|
|
169
|
+
engines:
|
|
170
|
+
pmd: # 2 spaces
|
|
171
|
+
|
|
172
|
+
# WRONG - missing quotes around special values
|
|
173
|
+
rules:
|
|
174
|
+
pmd:
|
|
175
|
+
MyRule:
|
|
176
|
+
severity: High # String values need quotes or use numbers
|
|
177
|
+
|
|
178
|
+
# CORRECT
|
|
179
|
+
rules:
|
|
180
|
+
pmd:
|
|
181
|
+
MyRule:
|
|
182
|
+
severity: 2 # Use numbers 1-5
|
|
183
|
+
# OR
|
|
184
|
+
severity: "High" # Or quoted strings
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Unknown Engine or Rule Name
|
|
188
|
+
|
|
189
|
+
**Symptom:** Rule selector returns 0 results
|
|
190
|
+
|
|
191
|
+
**Fix:** Verify the engine/rule name:
|
|
192
|
+
```bash
|
|
193
|
+
# List all available engines
|
|
194
|
+
sf code-analyzer rules --rule-selector all 2>&1 | head -50
|
|
195
|
+
|
|
196
|
+
# Search for a specific rule
|
|
197
|
+
sf code-analyzer rules --rule-selector all 2>&1 | grep -i "CRUD"
|
|
198
|
+
|
|
199
|
+
# List rules for specific engine
|
|
200
|
+
sf code-analyzer rules --rule-selector pmd 2>&1 | head -50
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Engine-Specific Issues
|
|
204
|
+
|
|
205
|
+
### PMD: Custom Rules Not Loading
|
|
206
|
+
|
|
207
|
+
**Symptom:** Custom PMD rules don't appear in `sf code-analyzer rules`
|
|
208
|
+
|
|
209
|
+
**Checklist:**
|
|
210
|
+
1. Ruleset XML must be valid PMD format
|
|
211
|
+
2. Path in `custom_rulesets` must be relative to `config_root`
|
|
212
|
+
3. For Java rules: JAR must be in `java_classpath_entries`
|
|
213
|
+
4. Validate: `sf code-analyzer rules --rule-selector pmd:<YourRuleName>`
|
|
214
|
+
|
|
215
|
+
### RetireJS: False Positives on Test Files
|
|
216
|
+
|
|
217
|
+
**Symptom:** RetireJS flags test fixtures or mock data
|
|
218
|
+
|
|
219
|
+
**Fix:** Add test paths to ignores:
|
|
220
|
+
```yaml
|
|
221
|
+
ignores:
|
|
222
|
+
files:
|
|
223
|
+
- "**/test/**"
|
|
224
|
+
- "**/__tests__/**"
|
|
225
|
+
- "**/jest-mocks/**"
|
|
226
|
+
- "**/*.test.js"
|
|
227
|
+
- "**/*.spec.js"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Flow Engine: Python Not Found
|
|
231
|
+
|
|
232
|
+
**Symptom:** `python3: command not found` when scanning Flows
|
|
233
|
+
|
|
234
|
+
**Fix:**
|
|
235
|
+
```bash
|
|
236
|
+
# Install Python 3
|
|
237
|
+
brew install python3 # macOS
|
|
238
|
+
# OR
|
|
239
|
+
sudo apt install python3 # Linux
|
|
240
|
+
|
|
241
|
+
# If python3 is at non-standard path:
|
|
242
|
+
# code-analyzer.yml
|
|
243
|
+
engines:
|
|
244
|
+
flow:
|
|
245
|
+
python_command: "/usr/local/bin/python3"
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### ApexGuru: Authentication Error
|
|
249
|
+
|
|
250
|
+
**Symptom:** `No authenticated org found` or `Session expired`
|
|
251
|
+
|
|
252
|
+
**Fix:**
|
|
253
|
+
```bash
|
|
254
|
+
# Login to org
|
|
255
|
+
sf org login web --alias my-org
|
|
256
|
+
|
|
257
|
+
# Set as default
|
|
258
|
+
sf config set target-org my-org
|
|
259
|
+
|
|
260
|
+
# Configure in code-analyzer.yml
|
|
261
|
+
engines:
|
|
262
|
+
apexguru:
|
|
263
|
+
target_org: "my-org"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Performance Issues
|
|
267
|
+
|
|
268
|
+
### Scan Takes Too Long
|
|
269
|
+
|
|
270
|
+
**Possible causes and solutions:**
|
|
271
|
+
|
|
272
|
+
| Cause | Solution |
|
|
273
|
+
|-------|----------|
|
|
274
|
+
| SFGE on large project | Increase heap, reduce thread timeout, or disable SFGE for routine scans |
|
|
275
|
+
| Scanning node_modules | Add `**/node_modules/**` to ignores |
|
|
276
|
+
| Too many engines enabled | Use `--rule-selector Recommended` instead of `all` for routine scans |
|
|
277
|
+
| Large static resources | Add `**/staticresources/**` to ignores |
|
|
278
|
+
| Many Flow files | Flow engine can be slow; scan Flows separately |
|
|
279
|
+
|
|
280
|
+
### Reduce Scan Time in CI
|
|
281
|
+
|
|
282
|
+
```yaml
|
|
283
|
+
# Fast CI scan: recommended rules only, severity gate at High
|
|
284
|
+
sf code-analyzer run \
|
|
285
|
+
--rule-selector Recommended \
|
|
286
|
+
--severity-threshold 2 \
|
|
287
|
+
--target force-app/main/default \
|
|
288
|
+
--output-file results.json
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Getting Help
|
|
292
|
+
|
|
293
|
+
If none of the above solves your issue:
|
|
294
|
+
|
|
295
|
+
1. **Check logs:** Look in the log folder (default: `/tmp` or configured `log_folder`)
|
|
296
|
+
2. **Increase log level:** Set `log_level: 5` in config for maximum detail
|
|
297
|
+
3. **Run with debug:** `SF_LOG_LEVEL=debug sf code-analyzer run ...`
|
|
298
|
+
4. **File an issue:** https://github.com/forcedotcom/code-analyzer-core/issues
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# check-prerequisites.sh
|
|
3
|
+
# Checks all Code Analyzer prerequisites and reports status.
|
|
4
|
+
# Usage: bash <skill_dir>/scripts/check-prerequisites.sh
|
|
5
|
+
#
|
|
6
|
+
# Exit codes:
|
|
7
|
+
# 0 = All prerequisites met
|
|
8
|
+
# 1 = Some prerequisites missing (details in output)
|
|
9
|
+
|
|
10
|
+
set -euo pipefail
|
|
11
|
+
|
|
12
|
+
# Colors for output
|
|
13
|
+
RED='\033[0;31m'
|
|
14
|
+
GREEN='\033[0;32m'
|
|
15
|
+
YELLOW='\033[0;33m'
|
|
16
|
+
NC='\033[0m' # No Color
|
|
17
|
+
|
|
18
|
+
PASS="${GREEN}PASS${NC}"
|
|
19
|
+
FAIL="${RED}FAIL${NC}"
|
|
20
|
+
WARN="${YELLOW}WARN${NC}"
|
|
21
|
+
|
|
22
|
+
MISSING_COUNT=0
|
|
23
|
+
WARNINGS_COUNT=0
|
|
24
|
+
|
|
25
|
+
echo "========================================="
|
|
26
|
+
echo " Code Analyzer Prerequisites Check"
|
|
27
|
+
echo "========================================="
|
|
28
|
+
echo ""
|
|
29
|
+
|
|
30
|
+
# --- Check sf CLI ---
|
|
31
|
+
echo -n "Salesforce CLI (sf): "
|
|
32
|
+
if command -v sf &> /dev/null; then
|
|
33
|
+
SF_VERSION=$(sf --version 2>&1 | head -1)
|
|
34
|
+
echo -e "${PASS} - ${SF_VERSION}"
|
|
35
|
+
else
|
|
36
|
+
echo -e "${FAIL} - Not installed"
|
|
37
|
+
echo " Install: npm install -g @salesforce/cli"
|
|
38
|
+
MISSING_COUNT=$((MISSING_COUNT + 1))
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# --- Check Code Analyzer Plugin ---
|
|
42
|
+
echo -n "Code Analyzer plugin: "
|
|
43
|
+
if command -v sf &> /dev/null; then
|
|
44
|
+
CA_VERSION=$(sf plugins --core 2>&1 | grep -i "code-analyzer" | head -1)
|
|
45
|
+
if [ -n "$CA_VERSION" ]; then
|
|
46
|
+
echo -e "${PASS} - ${CA_VERSION}"
|
|
47
|
+
else
|
|
48
|
+
echo -e "${FAIL} - Not installed"
|
|
49
|
+
echo " Install: sf plugins install @salesforce/plugin-code-analyzer"
|
|
50
|
+
MISSING_COUNT=$((MISSING_COUNT + 1))
|
|
51
|
+
fi
|
|
52
|
+
else
|
|
53
|
+
echo -e "${FAIL} - Cannot check (sf CLI missing)"
|
|
54
|
+
MISSING_COUNT=$((MISSING_COUNT + 1))
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# --- Check Java ---
|
|
58
|
+
echo -n "Java 11+ (PMD, CPD, SFGE): "
|
|
59
|
+
if command -v java &> /dev/null; then
|
|
60
|
+
JAVA_VERSION=$(java -version 2>&1 | head -1)
|
|
61
|
+
# Extract major version number
|
|
62
|
+
JAVA_MAJOR=$(java -version 2>&1 | head -1 | sed -E 's/.*"([0-9]+)\..*/\1/')
|
|
63
|
+
if [ "$JAVA_MAJOR" -ge 11 ] 2>/dev/null; then
|
|
64
|
+
echo -e "${PASS} - ${JAVA_VERSION}"
|
|
65
|
+
else
|
|
66
|
+
echo -e "${WARN} - ${JAVA_VERSION} (need 11+)"
|
|
67
|
+
echo " Upgrade: brew install openjdk@11"
|
|
68
|
+
WARNINGS_COUNT=$((WARNINGS_COUNT + 1))
|
|
69
|
+
fi
|
|
70
|
+
else
|
|
71
|
+
echo -e "${FAIL} - Not installed"
|
|
72
|
+
echo " Install: brew install openjdk@11 (macOS) / sdk install java 11.0.x-tem"
|
|
73
|
+
echo " Needed for: PMD, CPD, SFGE engines"
|
|
74
|
+
MISSING_COUNT=$((MISSING_COUNT + 1))
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
# --- Check JAVA_HOME ---
|
|
78
|
+
echo -n "JAVA_HOME: "
|
|
79
|
+
if [ -n "${JAVA_HOME:-}" ]; then
|
|
80
|
+
echo -e "${PASS} - ${JAVA_HOME}"
|
|
81
|
+
else
|
|
82
|
+
echo -e "${WARN} - Not set (may cause issues with some Java installations)"
|
|
83
|
+
WARNINGS_COUNT=$((WARNINGS_COUNT + 1))
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
# --- Check Node.js ---
|
|
87
|
+
echo -n "Node.js 18+ (ESLint, RetireJS): "
|
|
88
|
+
if command -v node &> /dev/null; then
|
|
89
|
+
NODE_VERSION=$(node --version 2>&1)
|
|
90
|
+
NODE_MAJOR=$(echo "$NODE_VERSION" | sed -E 's/v([0-9]+)\..*/\1/')
|
|
91
|
+
if [ "$NODE_MAJOR" -ge 18 ] 2>/dev/null; then
|
|
92
|
+
echo -e "${PASS} - ${NODE_VERSION}"
|
|
93
|
+
else
|
|
94
|
+
echo -e "${WARN} - ${NODE_VERSION} (need 18+)"
|
|
95
|
+
echo " Upgrade: nvm install 20 && nvm use 20"
|
|
96
|
+
WARNINGS_COUNT=$((WARNINGS_COUNT + 1))
|
|
97
|
+
fi
|
|
98
|
+
else
|
|
99
|
+
echo -e "${FAIL} - Not installed"
|
|
100
|
+
echo " Install: brew install node@20 (macOS) / nvm install 20"
|
|
101
|
+
echo " Needed for: ESLint, RetireJS engines"
|
|
102
|
+
MISSING_COUNT=$((MISSING_COUNT + 1))
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
# --- Check Python 3 ---
|
|
106
|
+
echo -n "Python 3 (Flow engine): "
|
|
107
|
+
if command -v python3 &> /dev/null; then
|
|
108
|
+
PY_VERSION=$(python3 --version 2>&1)
|
|
109
|
+
echo -e "${PASS} - ${PY_VERSION}"
|
|
110
|
+
else
|
|
111
|
+
echo -e "${WARN} - Not installed (only needed for Flow scanning)"
|
|
112
|
+
echo " Install: brew install python3 (macOS) / apt install python3 (Linux)"
|
|
113
|
+
echo " Needed for: Flow engine only"
|
|
114
|
+
WARNINGS_COUNT=$((WARNINGS_COUNT + 1))
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
# --- Check authenticated org ---
|
|
118
|
+
echo -n "Authenticated Org (ApexGuru): "
|
|
119
|
+
if command -v sf &> /dev/null; then
|
|
120
|
+
ORG_INFO=$(sf org display 2>&1)
|
|
121
|
+
if echo "$ORG_INFO" | grep -qi "username\|access token"; then
|
|
122
|
+
ORG_USER=$(echo "$ORG_INFO" | grep -i "username" | head -1 | awk '{print $NF}')
|
|
123
|
+
echo -e "${PASS} - ${ORG_USER}"
|
|
124
|
+
else
|
|
125
|
+
echo -e "${WARN} - No default org (only needed for ApexGuru)"
|
|
126
|
+
echo " Login: sf org login web --alias my-org"
|
|
127
|
+
WARNINGS_COUNT=$((WARNINGS_COUNT + 1))
|
|
128
|
+
fi
|
|
129
|
+
else
|
|
130
|
+
echo -e "${WARN} - Cannot check (sf CLI missing)"
|
|
131
|
+
WARNINGS_COUNT=$((WARNINGS_COUNT + 1))
|
|
132
|
+
fi
|
|
133
|
+
|
|
134
|
+
# --- Check for existing config ---
|
|
135
|
+
echo ""
|
|
136
|
+
echo "-----------------------------------------"
|
|
137
|
+
echo -n "Config file (code-analyzer.yml): "
|
|
138
|
+
if [ -f "code-analyzer.yml" ] || [ -f "code-analyzer.yaml" ]; then
|
|
139
|
+
CONFIG_FILE=$(ls code-analyzer.yml code-analyzer.yaml 2>/dev/null | head -1)
|
|
140
|
+
echo -e "${PASS} - Found: ${CONFIG_FILE}"
|
|
141
|
+
else
|
|
142
|
+
echo -e "${WARN} - Not found (will use defaults)"
|
|
143
|
+
echo " Generate: sf code-analyzer config --output-file code-analyzer.yml"
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
# --- Check project type ---
|
|
147
|
+
echo -n "Project type: "
|
|
148
|
+
HAS_APEX=false
|
|
149
|
+
HAS_LWC=false
|
|
150
|
+
HAS_FLOWS=false
|
|
151
|
+
HAS_SFDX=false
|
|
152
|
+
|
|
153
|
+
[ -d "force-app" ] && HAS_APEX=true
|
|
154
|
+
find . -maxdepth 4 -path "*/lwc/*" -name "*.js" 2>/dev/null | head -1 | grep -q . && HAS_LWC=true
|
|
155
|
+
find . -maxdepth 4 -name "*.flow-meta.xml" 2>/dev/null | head -1 | grep -q . && HAS_FLOWS=true
|
|
156
|
+
[ -f "sfdx-project.json" ] || [ -f "sf-project.json" ] && HAS_SFDX=true
|
|
157
|
+
|
|
158
|
+
PROJECT_TYPES=""
|
|
159
|
+
[ "$HAS_APEX" = true ] && PROJECT_TYPES="${PROJECT_TYPES}Apex, "
|
|
160
|
+
[ "$HAS_LWC" = true ] && PROJECT_TYPES="${PROJECT_TYPES}LWC, "
|
|
161
|
+
[ "$HAS_FLOWS" = true ] && PROJECT_TYPES="${PROJECT_TYPES}Flows, "
|
|
162
|
+
[ "$HAS_SFDX" = true ] && PROJECT_TYPES="${PROJECT_TYPES}SFDX Project, "
|
|
163
|
+
|
|
164
|
+
if [ -n "$PROJECT_TYPES" ]; then
|
|
165
|
+
echo "${PROJECT_TYPES%, }"
|
|
166
|
+
else
|
|
167
|
+
echo "Unknown (no Salesforce project markers found)"
|
|
168
|
+
fi
|
|
169
|
+
|
|
170
|
+
# --- Summary ---
|
|
171
|
+
echo ""
|
|
172
|
+
echo "========================================="
|
|
173
|
+
echo " Summary"
|
|
174
|
+
echo "========================================="
|
|
175
|
+
|
|
176
|
+
if [ $MISSING_COUNT -eq 0 ] && [ $WARNINGS_COUNT -eq 0 ]; then
|
|
177
|
+
echo -e "${GREEN}All prerequisites met! Ready to scan.${NC}"
|
|
178
|
+
exit 0
|
|
179
|
+
elif [ $MISSING_COUNT -eq 0 ]; then
|
|
180
|
+
echo -e "${YELLOW}${WARNINGS_COUNT} warning(s) - some engines may not work.${NC}"
|
|
181
|
+
echo "Core functionality (PMD, ESLint) should work if Java and Node.js are available."
|
|
182
|
+
exit 0
|
|
183
|
+
else
|
|
184
|
+
echo -e "${RED}${MISSING_COUNT} required prerequisite(s) missing.${NC}"
|
|
185
|
+
[ $WARNINGS_COUNT -gt 0 ] && echo -e "${YELLOW}${WARNINGS_COUNT} additional warning(s).${NC}"
|
|
186
|
+
echo ""
|
|
187
|
+
echo "Install missing prerequisites before running Code Analyzer."
|
|
188
|
+
exit 1
|
|
189
|
+
fi
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# generate-config.sh
|
|
3
|
+
# Generates a code-analyzer.yml with ONLY project-specific overrides.
|
|
4
|
+
# Does NOT duplicate built-in defaults — only writes what intentionally differs.
|
|
5
|
+
#
|
|
6
|
+
# Usage: bash <skill_dir>/scripts/generate-config.sh [--type apex|lwc|fullstack]
|
|
7
|
+
#
|
|
8
|
+
# If --type is not specified, auto-detects from workspace contents.
|
|
9
|
+
|
|
10
|
+
set -euo pipefail
|
|
11
|
+
|
|
12
|
+
CONFIG_FILE="code-analyzer.yml"
|
|
13
|
+
PROJECT_TYPE="${1:-auto}"
|
|
14
|
+
|
|
15
|
+
# Remove --type prefix if present
|
|
16
|
+
PROJECT_TYPE="${PROJECT_TYPE#--type=}"
|
|
17
|
+
PROJECT_TYPE="${PROJECT_TYPE#--type }"
|
|
18
|
+
|
|
19
|
+
# Auto-detect project type
|
|
20
|
+
if [ "$PROJECT_TYPE" = "auto" ] || [ "$PROJECT_TYPE" = "" ]; then
|
|
21
|
+
HAS_APEX=false
|
|
22
|
+
HAS_LWC=false
|
|
23
|
+
HAS_NODE_MODULES=false
|
|
24
|
+
|
|
25
|
+
[ -d "force-app" ] && HAS_APEX=true
|
|
26
|
+
find . -maxdepth 4 -path "*/lwc/*" -name "*.js" 2>/dev/null | head -1 | grep -q . && HAS_LWC=true
|
|
27
|
+
[ -d "node_modules" ] && HAS_NODE_MODULES=true
|
|
28
|
+
|
|
29
|
+
if [ "$HAS_APEX" = true ] && [ "$HAS_LWC" = true ]; then
|
|
30
|
+
PROJECT_TYPE="fullstack"
|
|
31
|
+
elif [ "$HAS_LWC" = true ]; then
|
|
32
|
+
PROJECT_TYPE="lwc"
|
|
33
|
+
elif [ "$HAS_APEX" = true ]; then
|
|
34
|
+
PROJECT_TYPE="apex"
|
|
35
|
+
else
|
|
36
|
+
PROJECT_TYPE="minimal"
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
echo "Auto-detected project type: ${PROJECT_TYPE}"
|
|
40
|
+
|
|
41
|
+
# Warn if no Salesforce project markers found
|
|
42
|
+
if [ "$PROJECT_TYPE" = "minimal" ] && [ ! -f "sfdx-project.json" ] && [ ! -f "sf-project.json" ]; then
|
|
43
|
+
echo "WARNING: No Salesforce project markers found (no sfdx-project.json, sf-project.json, or force-app/)."
|
|
44
|
+
echo " Are you running this from your project root?"
|
|
45
|
+
echo " Generating minimal config — re-run from project root for better detection."
|
|
46
|
+
fi
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# Check if config already exists
|
|
50
|
+
if [ -f "$CONFIG_FILE" ] || [ -f "code-analyzer.yaml" ]; then
|
|
51
|
+
echo "WARNING: Config file already exists."
|
|
52
|
+
echo "Edit the existing file instead of regenerating."
|
|
53
|
+
exit 1
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
echo "Generating ${CONFIG_FILE} (overrides only)..."
|
|
57
|
+
|
|
58
|
+
case "$PROJECT_TYPE" in
|
|
59
|
+
apex)
|
|
60
|
+
cat > "$CONFIG_FILE" << 'YAML'
|
|
61
|
+
# Code Analyzer overrides for Apex project
|
|
62
|
+
# Only entries that differ from built-in defaults
|
|
63
|
+
|
|
64
|
+
ignores:
|
|
65
|
+
files:
|
|
66
|
+
- "**/node_modules/**"
|
|
67
|
+
- "**/.sfdx/**"
|
|
68
|
+
- "**/.sf/**"
|
|
69
|
+
|
|
70
|
+
engines:
|
|
71
|
+
sfge:
|
|
72
|
+
java_max_heap_size: "4g"
|
|
73
|
+
YAML
|
|
74
|
+
;;
|
|
75
|
+
|
|
76
|
+
lwc)
|
|
77
|
+
cat > "$CONFIG_FILE" << 'YAML'
|
|
78
|
+
# Code Analyzer overrides for LWC project
|
|
79
|
+
# Only entries that differ from built-in defaults
|
|
80
|
+
|
|
81
|
+
ignores:
|
|
82
|
+
files:
|
|
83
|
+
- "**/node_modules/**"
|
|
84
|
+
- "**/.sfdx/**"
|
|
85
|
+
- "**/.sf/**"
|
|
86
|
+
- "**/jest-mocks/**"
|
|
87
|
+
- "**/__tests__/**"
|
|
88
|
+
|
|
89
|
+
engines:
|
|
90
|
+
eslint:
|
|
91
|
+
auto_discover_eslint_config: true
|
|
92
|
+
YAML
|
|
93
|
+
;;
|
|
94
|
+
|
|
95
|
+
fullstack)
|
|
96
|
+
cat > "$CONFIG_FILE" << 'YAML'
|
|
97
|
+
# Code Analyzer overrides for full-stack Salesforce project
|
|
98
|
+
# Only entries that differ from built-in defaults
|
|
99
|
+
|
|
100
|
+
ignores:
|
|
101
|
+
files:
|
|
102
|
+
- "**/node_modules/**"
|
|
103
|
+
- "**/.sfdx/**"
|
|
104
|
+
- "**/.sf/**"
|
|
105
|
+
- "**/jest-mocks/**"
|
|
106
|
+
- "**/__tests__/**"
|
|
107
|
+
|
|
108
|
+
engines:
|
|
109
|
+
sfge:
|
|
110
|
+
java_max_heap_size: "4g"
|
|
111
|
+
eslint:
|
|
112
|
+
auto_discover_eslint_config: true
|
|
113
|
+
YAML
|
|
114
|
+
;;
|
|
115
|
+
|
|
116
|
+
minimal)
|
|
117
|
+
cat > "$CONFIG_FILE" << 'YAML'
|
|
118
|
+
# Code Analyzer overrides
|
|
119
|
+
# Only entries that differ from built-in defaults
|
|
120
|
+
|
|
121
|
+
ignores:
|
|
122
|
+
files:
|
|
123
|
+
- "**/node_modules/**"
|
|
124
|
+
YAML
|
|
125
|
+
;;
|
|
126
|
+
|
|
127
|
+
*)
|
|
128
|
+
echo "ERROR: Unknown project type: ${PROJECT_TYPE}"
|
|
129
|
+
echo "Valid types: apex, lwc, fullstack, minimal"
|
|
130
|
+
exit 1
|
|
131
|
+
;;
|
|
132
|
+
esac
|
|
133
|
+
|
|
134
|
+
echo ""
|
|
135
|
+
echo "Created: ${CONFIG_FILE}"
|
|
136
|
+
echo ""
|
|
137
|
+
echo "This file contains ONLY overrides — built-in defaults still apply for"
|
|
138
|
+
echo "everything not listed here. Add more overrides as needed."
|
|
139
|
+
echo ""
|
|
140
|
+
echo "Next steps:"
|
|
141
|
+
echo " 1. Review: cat ${CONFIG_FILE}"
|
|
142
|
+
echo " 2. Validate: sf code-analyzer config --config-file ${CONFIG_FILE}"
|
|
143
|
+
echo " 3. Run scan: sf code-analyzer run --output-file results.json --include-fixes"
|