Skip to content

Commit 0eef385

Browse files
committed
adds sarif support
1 parent cb5a9e0 commit 0eef385

File tree

9 files changed

+68
-210
lines changed

9 files changed

+68
-210
lines changed

.github/workflows/deploy-BETA.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

.github/workflows/deploy-RELEASE.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/generate-RELEASE.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*" # Trigger on version tags like v6.0.0
7+
8+
permissions:
9+
contents: read
10+
id-token: write # Required for OIDC (Trusted Publishing)
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
# environment: production # Uncomment for approval gates
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: "20"
21+
registry-url: "https://registry.npmjs.org"
22+
- name: Update npm
23+
run: npm install -g npm@latest
24+
- run: npm ci
25+
- run: npm run build
26+
- run: npm publish --access public

.github/workflows/test.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,19 @@ sf flow:scan [options]
3333
Customize the scan behavior using the following options:
3434

3535
```sh-session
36-
-c, --config <path> provide a path to the configuration file.
36+
-c, --config <path> set a path to the configuration file.
3737

38-
-f, --failon provide a threshold level for returning status 1
38+
-d, --directory <C:\..\force-app\main\default\flows> set a directory to scan.
3939

40-
-p, --files <C:\..\flow1.flow, C:\..\flow2.flow> provide a space-separated list of flow paths to scan.
40+
-f, --failon set a threshold level for failure by error
4141

42-
-d, --directory <C:\..\force-app\main\default\flows> provide a directory to scan.
42+
-p, --files <C:\..\flow1.flow, C:\..\flow2.flow> set a space-separated list of flow paths to scan.
4343

44-
--json set output format as json.
44+
-s, --sarif get SARIF output to the stdout directly
45+
46+
-z, --betamode a runtime toggle to enable beta rules(experimental)
4547

46-
-z, --betamode a runtime toggle to enable beta rules(experimental)
48+
--json set output format as json.
4749

4850
--loglevel=(trace|debug|info|warn|error|fatal) [default: warn] logging level.
4951
```
@@ -139,12 +141,12 @@ Note: if you prefer JSON format, you can create a `.flow-scanner.json` file usin
139141
```
140142

141143
5. **Linking SF CLI Plugin**
142-
to test changes in your local CLI run:
144+
to test changes in your local CLI run:
143145

144146
```bash
145147
sf plugins link .
146148
```
147-
149+
148150
6. **Linking** **Core Module (Optional)**
149151

150152
If you’re developing or testing updates to the core module, you can link it locally:

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"bugs": "https://github.com/Flow-Scanner/lightning-flow-scanner-cli/issues",
55
"description": "A Salesforce CLI plugin for static analysis and optimization of Flows. Scans metadata for 20+ issues such as hardcoded IDs, unsafe contexts, inefficient SOQL/DML operations, recursion risks, and missing fault handling. Supports auto-fixes, rule configurations, and CI/CD integration to help users maintain secure and reliable Flow automations.",
66
"dependencies": {
7-
"@flow-scanner/lightning-flow-scanner-core": "^6.0.4",
7+
"@flow-scanner/lightning-flow-scanner-core": "^6.1.2",
88
"@oclif/core": "^4.5.4",
99
"@salesforce/core": "^8.18.7",
1010
"@salesforce/sf-plugins-core": "^12.2.3",

src/commands/flow/scan.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { inspect } from "util";
1515
const {
1616
parse: parseFlows,
1717
scan: scanFlows,
18+
exportSarif: exportSarif,
1819
} = pkg;
1920

2021
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -42,18 +43,18 @@ export default class Scan extends SfCommand<Output> {
4243
protected errorCounters: Map<string, number> = new Map<string, number>();
4344

4445
public static readonly flags = {
46+
config: Flags.file({
47+
char: "c",
48+
description: "Path to configuration file",
49+
required: false,
50+
}),
4551
directory: Flags.directory({
4652
char: "d",
4753
description: messages.getMessage("directoryToScan"),
4854
required: false,
4955
exists: true,
5056
exclusive: ["files"],
5157
}),
52-
config: Flags.file({
53-
char: "c",
54-
description: "Path to configuration file",
55-
required: false,
56-
}),
5758
failon: Flags.option({
5859
char: "f",
5960
description:
@@ -68,6 +69,11 @@ export default class Scan extends SfCommand<Output> {
6869
charAliases: ["p"],
6970
exclusive: ["directory"],
7071
}),
72+
sarif: Flags.boolean({
73+
char: "s",
74+
description: "Get SARIF output in the stdout directly",
75+
default: false,
76+
}),
7177
betamode: Flags.boolean({
7278
char: "z",
7379
description: "Enable beta rules at run-time (experimental)",
@@ -99,20 +105,23 @@ export default class Scan extends SfCommand<Output> {
99105
this.debug(`parsed flows ${parsedFlows.length}`, ...parsedFlows);
100106

101107
// ---- 5. Run the scan ----------------------------------------------------
102-
const tryScan = (): [ScanResult[], Error | null] => {
103-
try {
104-
const scanConfig: any = {
105-
rules: mergedConfig.rules ?? {},
106-
betamode: !!mergedConfig.betamode,
107-
};
108-
return [scanFlows(parsedFlows, scanConfig), null];
109-
} catch (err) {
110-
return [null, err as Error];
111-
}
112-
};
113-
const [scanResults, scanError] = tryScan();
108+
let scanResults: ScanResult[];
109+
try {
110+
const scanConfig = {
111+
rules: mergedConfig.rules ?? {},
112+
betamode: !!mergedConfig.betamode,
113+
};
114+
scanResults = scanFlows(parsedFlows, scanConfig);
115+
} catch (err) {
116+
this.error(`Scan failed: ${(err as Error).message}`);
117+
}
118+
119+
if (flags.sarif) {
120+
const sarif = await exportSarif(scanResults);
121+
process.stdout.write(sarif + '\n');
122+
process.exit(this.getStatus());
123+
}
114124

115-
this.debug(`error:`, inspect(scanError));
116125
this.debug(`scan results: ${scanResults.length}`, ...scanResults);
117126
this.spinner.stop(`Scan complete`);
118127

0 commit comments

Comments
 (0)