Skip to content

Commit a8e2407

Browse files
authored
feat: add Salesforce Code Analyzer (#1038)
* feat: add Salesforce Code Analyzer * fix: sfc project path in CI
1 parent 99bdd9b commit a8e2407

File tree

4 files changed

+72
-34
lines changed

4 files changed

+72
-34
lines changed

.github/workflows/ci-pr.yml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,36 @@ jobs:
6161
- name: 'Code formatting verification with Prettier'
6262
run: npm run prettier:verify
6363

64-
# Lint LWC / Aura
65-
- name: 'Lint Lightning Web Components / Aura Components'
66-
run: npm run lint
64+
# Install Salesforce CLI
65+
- name: 'Install Salesforce CLI'
66+
run: |
67+
npm install @salesforce/cli --location=global
68+
nodeInstallPath=$(npm config get prefix)
69+
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
70+
cd "$nodeInstallPath/bin"
71+
./sf --version
72+
73+
# Install Salesforce CLI Code Analyzer plugin
74+
- name: 'Install Salesforce CLI Code Analyzer plugin'
75+
run: sf plugins install code-analyzer
76+
77+
# Run Code Analyzer
78+
- name: 'Run Code Analyzer'
79+
id: run-code-analyzer
80+
uses: forcedotcom/run-code-analyzer@v2
81+
with:
82+
run-arguments: --workspace "force-app/**" --view detail --output-file "sca-results.csv" --config-file "code-analyzer.yml"
83+
results-artifact-name: code-analyzer-results
84+
85+
# Check for Code Analyzer critical or high severity violations
86+
- name: 'Check for Code Analyzer critical or high severity violations'
87+
if: |
88+
steps.run-code-analyzer.outputs.exit-code > 0 ||
89+
steps.run-code-analyzer.outputs.num-sev1-violations > 0 ||
90+
steps.run-code-analyzer.outputs.num-sev2-violations > 0
91+
run: |
92+
echo One of more Code Analyzer critical or high severity violations found
93+
exit 1
6794
6895
# LWC unit tests
6996
- name: 'Unit test Lightning Web Components'
@@ -122,20 +149,6 @@ jobs:
122149
- name: 'Checkout source code'
123150
uses: actions/checkout@v4
124151

125-
# Run PMD scan
126-
- name: 'Run PMD scan'
127-
uses: pmd/pmd-github-action@v2.0.0
128-
id: pmd
129-
with:
130-
version: '6.55.0'
131-
sourcePath: 'force-app'
132-
rulesets: 'ruleset.xml'
133-
134-
# Check for PMD violations
135-
- name: 'Check for PMD violations'
136-
if: steps.pmd.outputs.violations != 0
137-
run: exit 1
138-
139152
# Install Salesforce CLI
140153
- name: 'Install Salesforce CLI'
141154
run: |

.github/workflows/ci.yml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,36 @@ jobs:
4444
- name: 'Code formatting verification with Prettier'
4545
run: npm run prettier:verify
4646

47-
# Lint LWC / Aura
48-
- name: 'Lint Lightning Web Components / Aura Components'
49-
run: npm run lint
47+
# Install Salesforce CLI
48+
- name: 'Install Salesforce CLI'
49+
run: |
50+
npm install @salesforce/cli --location=global
51+
nodeInstallPath=$(npm config get prefix)
52+
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
53+
cd "$nodeInstallPath/bin"
54+
./sf --version
55+
56+
# Install Salesforce CLI Code Analyzer plugin
57+
- name: 'Install Salesforce CLI Code Analyzer plugin'
58+
run: sf plugins install code-analyzer
59+
60+
# Run Code Analyzer
61+
- name: 'Run Code Analyzer'
62+
id: run-code-analyzer
63+
uses: forcedotcom/run-code-analyzer@v2
64+
with:
65+
run-arguments: --workspace "force-app/**" --view detail --output-file "sca-results.csv" --config-file "code-analyzer.yml"
66+
results-artifact-name: code-analyzer-results
67+
68+
# Check for Code Analyzer critical or high severity violations
69+
- name: 'Check for Code Analyzer critical or high severity violations'
70+
if: |
71+
steps.run-code-analyzer.outputs.exit-code > 0 ||
72+
steps.run-code-analyzer.outputs.num-sev1-violations > 0 ||
73+
steps.run-code-analyzer.outputs.num-sev2-violations > 0
74+
run: |
75+
echo One of more Code Analyzer critical or high severity violations found
76+
exit 1
5077
5178
# LWC unit tests
5279
- name: 'Unit test Lightning Web Components'
@@ -68,20 +95,6 @@ jobs:
6895
- name: 'Checkout source code'
6996
uses: actions/checkout@v4
7097

71-
# Run PMD scan
72-
- name: 'Run PMD scan'
73-
uses: pmd/pmd-github-action@v2.0.0
74-
id: pmd
75-
with:
76-
version: '6.55.0'
77-
sourcePath: 'force-app'
78-
rulesets: 'ruleset.xml'
79-
80-
# Check for PMD violations
81-
- name: 'Check for PMD violations'
82-
if: steps.pmd.outputs.violations != 0
83-
run: exit 1
84-
8598
# Install Salesforce CLI
8699
- name: 'Install Salesforce CLI'
87100
run: |

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ $RECYCLE.BIN/
4040
.vscode/*
4141
!.vscode/extensions.json
4242

43+
# Salesforce Code Analyzer results
44+
sca-results.csv
45+
sfca_results.json
46+
4347
# Local environment variables/config
4448
.env
4549
.config

code-analyzer.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
engines:
2+
flow:
3+
disable_engine: true
4+
eslint:
5+
auto_discover_eslint_config: true
6+
disable_javascript_base_config: true
7+
disable_lwc_base_config: true
8+
disable_typescript_base_config: true

0 commit comments

Comments
 (0)