@@ -86,9 +86,24 @@ export function formatAlertTable(rows: ReportAlertRow[]): string[] {
8686 row . introducedBy ,
8787 row . manifest ,
8888 ] )
89- const widths = headers . map ( ( header , i ) =>
90- Math . max ( header . length , ...cells . map ( cell => ( cell [ i ] ?? '' ) . length ) ) ,
91- )
89+ const widths = headers . map ( header => header . length )
90+ for (
91+ let rowIndex = 0 , { length : rowCount } = cells ;
92+ rowIndex < rowCount ;
93+ rowIndex += 1
94+ ) {
95+ const cell = cells [ rowIndex ] !
96+ for (
97+ let cellIndex = 0 , { length : cellLength } = cell ;
98+ cellIndex < cellLength ;
99+ cellIndex += 1
100+ ) {
101+ widths [ cellIndex ] = Math . max (
102+ widths [ cellIndex ] ?? 0 ,
103+ cell [ cellIndex ] ?. length ?? 0 ,
104+ )
105+ }
106+ }
92107 const toRow = ( values : string [ ] ) =>
93108 ` ${ values
94109 . map ( ( value , i ) => value . padEnd ( widths [ i ] ?? 0 ) )
@@ -116,6 +131,12 @@ export function formatLabelledPairs(pairs: Array<[string, string]>): string[] {
116131 )
117132}
118133
134+ export function isFullScanReport (
135+ report : ScanReport | { healthy : boolean } ,
136+ ) : report is ScanReport {
137+ return 'alerts' in report
138+ }
139+
119140export async function outputGeneratedScanReport (
120141 scanReport : Extract < ReturnType < typeof generateReport > , { ok : true } > ,
121142 config : Pick <
@@ -159,10 +180,10 @@ export async function outputGeneratedScanReport(
159180
160181 if ( short ) {
161182 logger . log ( scanReport . data . healthy ? 'OK' : 'ERR' )
183+ } else if ( isFullScanReport ( scanReport . data ) ) {
184+ logger . log ( toPlainTextReport ( scanReport . data , includeLicensePolicy ) )
162185 } else {
163- logger . log (
164- toPlainTextReport ( scanReport . data as ScanReport , includeLicensePolicy ) ,
165- )
186+ logger . log ( scanReport . data . healthy ? 'OK' : 'ERR' )
166187 }
167188}
168189
@@ -401,8 +422,10 @@ export function toPlainTextReport(
401422 lines . push (
402423 ` ${ rows . length } ${ pluralize ( 'alert' , { count : rows . length } ) } with a policy set to at least "${ reportLevel } ".` ,
403424 '' ,
404- ...formatAlertTable ( rows ) ,
405- '' ,
406425 )
426+ for ( const line of formatAlertTable ( rows ) ) {
427+ lines . push ( line )
428+ }
429+ lines . push ( '' )
407430 return lines . join ( '\n' )
408431}
0 commit comments