@@ -36,6 +36,7 @@ export default class Scan extends SfCommand<Output> {
3636 public static requiresProject = false ;
3737 protected static supportsUsername = true ;
3838 protected failOn = "error" ;
39+ protected static supportsRawOutput = true ;
3940 protected errorCounters : Map < string , number > = new Map < string , number > ( ) ;
4041 public static readonly flags = {
4142 config : Flags . file ( {
@@ -104,7 +105,7 @@ export default class Scan extends SfCommand<Output> {
104105 const parsedFlows : ParsedFlow [ ] = await parseFlows ( flowFiles ) ;
105106 this . debug ( `parsed flows ${ parsedFlows . length } ` , ...parsedFlows ) ;
106107 // ---- 5. Run the scan ----------------------------------------------------
107- let scanResults : ScanResult [ ] ;
108+ let scanResults : ScanResult [ ] ;
108109 try {
109110 const scanConfig = {
110111 rules : mergedConfig . rules ?? { } ,
@@ -114,65 +115,53 @@ export default class Scan extends SfCommand<Output> {
114115 } catch ( err ) {
115116 this . error ( `Scan failed: ${ ( err as Error ) . message } ` ) ;
116117 }
117-
118- // BUILD RESULTS
118+ this . debug ( "Does every scanResult have fsPath?" , scanResults . some ( r => ! r . flow ?. fsPath ) ) ;
119+ // BUILD RESULTS ALWAYS (for status and errorCounters)
119120 const results = this . buildResults ( scanResults ) ;
120-
121- // SARIF: output
121+ // SARIF: if sarif, no human output
122122 if ( flags . sarif ) {
123123 const sarif = await exportSarif ( scanResults ) ;
124- this . log ( sarif ) ; // ← ONLY THIS WORKS reliably
125- const status = this . getStatus ( ) ;
126- if ( status > 0 ) {
127- process . exitCode = status ;
128- }
129- return {
130- summary : {
131- flowsNumber : scanResults . length ,
132- results : results . length ,
133- message : "SARIF output generated" ,
134- } ,
135- status,
136- results : [ ] ,
137- } ;
124+ this . spinner . stop ( ) ;
125+ console . log ( sarif ) ;
138126 }
139-
140127 this . debug ( `scan results: ${ scanResults . length } ` , ...scanResults ) ;
141- this . spinner . stop ( `Scan complete` ) ;
142- // ---- 6. Build / display results -----------------------------------------
143- if ( results . length > 0 ) {
144- const resultsByFlow : Record < string , any [ ] > = { } ;
145- for ( const r of results ) {
146- resultsByFlow [ r . flowName ] = resultsByFlow [ r . flowName ] ?? [ ] ;
147- resultsByFlow [ r . flowName ] . push ( r ) ;
128+ if ( ! flags . sarif ) this . spinner . stop ( `Scan SARIF Mode` ) ;
129+ // ---- 6. Human readable only if not sarif -----------------------------------------
130+ if ( ! flags . sarif ) {
131+ if ( results . length > 0 ) {
132+ const resultsByFlow : Record < string , any [ ] > = { } ;
133+ for ( const r of results ) {
134+ resultsByFlow [ r . flowName ] = resultsByFlow [ r . flowName ] ?? [ ] ;
135+ resultsByFlow [ r . flowName ] . push ( r ) ;
136+ }
137+ for ( const flowName in resultsByFlow ) {
138+ const match = scanResults . find ( ( s ) => s . flow . label === flowName ) ! ;
139+ this . styledHeader (
140+ `Flow: ${ chalk . yellow ( flowName ) } ${ chalk . bgYellow (
141+ `(${ match . flow . name } .flow-meta.xml)`
142+ ) } ${ chalk . red ( `(${ resultsByFlow [ flowName ] . length } results)` ) } `
143+ ) ;
144+ this . log ( chalk . italic ( "Type: " + match . flow . type ) ) ;
145+ this . log ( "" ) ;
146+ this . table ( {
147+ data : resultsByFlow [ flowName ] ,
148+ columns : [ "rule" , "type" , "name" , "severity" ] ,
149+ } ) ;
150+ this . debug ( `Results By Flow: ${ inspect ( resultsByFlow [ flowName ] ) } ` ) ;
151+ this . log ( "" ) ;
152+ }
148153 }
149- for ( const flowName in resultsByFlow ) {
150- const match = scanResults . find ( ( s ) => s . flow . label === flowName ) ! ;
151- this . styledHeader (
152- `Flow: ${ chalk . yellow ( flowName ) } ${ chalk . bgYellow (
153- `(${ match . flow . name } .flow-meta.xml)`
154- ) } ${ chalk . red ( `(${ resultsByFlow [ flowName ] . length } results)` ) } `
155- ) ;
156- this . log ( chalk . italic ( "Type: " + match . flow . type ) ) ;
157- this . log ( "" ) ;
158- this . table ( {
159- data : resultsByFlow [ flowName ] ,
160- columns : [ "rule" , "type" , "name" , "severity" ] ,
161- } ) ;
162- this . debug ( `Results By Flow: ${ inspect ( resultsByFlow [ flowName ] ) } ` ) ;
163- this . log ( "" ) ;
154+ this . styledHeader (
155+ `Total: ${ chalk . red ( results . length + " Results" ) } in ${ chalk . yellow (
156+ scanResults . length + " Flows"
157+ ) } .`
158+ ) ;
159+ for ( const sev of [ "error" , "warning" , "note" ] ) {
160+ const cnt = this . errorCounters . get ( sev ) ?? 0 ;
161+ this . log ( `- ${ sev } : ${ cnt } ` ) ;
164162 }
163+ this . log ( "" ) ;
165164 }
166- this . styledHeader (
167- `Total: ${ chalk . red ( results . length + " Results" ) } in ${ chalk . yellow (
168- scanResults . length + " Flows"
169- ) } .`
170- ) ;
171- for ( const sev of [ "error" , "warning" , "note" ] ) {
172- const cnt = this . errorCounters . get ( sev ) ?? 0 ;
173- this . log ( `- ${ sev } : ${ cnt } ` ) ;
174- }
175- this . log ( "" ) ;
176165 // ---- 7. Exit code -------------------------------------------------------
177166 const status = this . getStatus ( ) ;
178167 if ( status > 0 ) process . exitCode = status ;
0 commit comments