@@ -36,6 +36,12 @@ export type OutputScanReportConfig = {
3636 short : boolean
3737}
3838
39+ function isFullScanReport (
40+ report : ScanReport | { healthy : boolean } ,
41+ ) : report is ScanReport {
42+ return 'alerts' in report
43+ }
44+
3945export type ReportAlertRow = {
4046 alertType : string
4147 introducedBy : string
@@ -86,9 +92,12 @@ export function formatAlertTable(rows: ReportAlertRow[]): string[] {
8692 row . introducedBy ,
8793 row . manifest ,
8894 ] )
89- const widths = headers . map ( ( header , i ) =>
90- Math . max ( header . length , ...cells . map ( cell => ( cell [ i ] ?? '' ) . length ) ) ,
91- )
95+ const widths = headers . map ( header => header . length )
96+ for ( const cell of cells ) {
97+ for ( let i = 0 , { length } = cell ; i < length ; i += 1 ) {
98+ widths [ i ] = Math . max ( widths [ i ] ?? 0 , cell [ i ] ?. length ?? 0 )
99+ }
100+ }
92101 const toRow = ( values : string [ ] ) =>
93102 ` ${ values
94103 . map ( ( value , i ) => value . padEnd ( widths [ i ] ?? 0 ) )
@@ -159,10 +168,10 @@ export async function outputGeneratedScanReport(
159168
160169 if ( short ) {
161170 logger . log ( scanReport . data . healthy ? 'OK' : 'ERR' )
171+ } else if ( isFullScanReport ( scanReport . data ) ) {
172+ logger . log ( toPlainTextReport ( scanReport . data , includeLicensePolicy ) )
162173 } else {
163- logger . log (
164- toPlainTextReport ( scanReport . data as ScanReport , includeLicensePolicy ) ,
165- )
174+ logger . log ( scanReport . data . healthy ? 'OK' : 'ERR' )
166175 }
167176}
168177
@@ -401,8 +410,10 @@ export function toPlainTextReport(
401410 lines . push (
402411 ` ${ rows . length } ${ pluralize ( 'alert' , { count : rows . length } ) } with a policy set to at least "${ reportLevel } ".` ,
403412 '' ,
404- ...formatAlertTable ( rows ) ,
405- '' ,
406413 )
414+ for ( const line of formatAlertTable ( rows ) ) {
415+ lines . push ( line )
416+ }
417+ lines . push ( '' )
407418 return lines . join ( '\n' )
408419}
0 commit comments