@@ -43,19 +43,20 @@ export function format(
43
43
44
44
return results
45
45
. filter ( r => Array . isArray ( r . warnings ) || Array . isArray ( r . errors ) )
46
- . map ( result => [ fi ( result ) , ...fr ( result ) ] . join ( '\n' ) )
46
+ . map ( result => [ ...fi ( result ) , ...fr ( result ) ] )
47
+ . reduce ( ( acc , item ) => Array . isArray ( item ) ? [ ...acc , ...item ] : [ ...acc , item ] , [ ] )
47
48
. join ( '\n' ) ;
48
49
}
49
50
50
51
function formatInput (
51
52
result : FormattableResult & WithInput ,
52
53
options : FormatOptions = { }
53
- ) : string {
54
+ ) : string [ ] {
54
55
const { color : enabled = true } = options ;
55
56
const { errors = [ ] , warnings = [ ] , input = '' } = result ;
56
57
57
58
if ( ! input ) {
58
- return '' ;
59
+ return [ '' ] ;
59
60
}
60
61
61
62
const sign = '⧗' ;
@@ -66,8 +67,8 @@ function formatInput(
66
67
const hasProblems = errors . length > 0 || warnings . length > 0 ;
67
68
68
69
return options . verbose || hasProblems
69
- ? `${ decoration } input: ${ decoratedInput } `
70
- : '' ;
70
+ ? [ `${ decoration } input: ${ decoratedInput } ` ]
71
+ : [ ] ;
71
72
}
72
73
73
74
export function formatResult (
@@ -97,13 +98,25 @@ export function formatResult(
97
98
const deco = enabled ? ( chalk [ color ] as any ) ( sign ) : sign ;
98
99
const el = errors . length ;
99
100
const wl = warnings . length ;
100
- const hasProblems = errors . length > 0 || warnings . length > 0 ;
101
+ const hasProblems = problems . length > 0 ;
102
+
103
+ const summary =
104
+ options . verbose || hasProblems
105
+ ? `${ deco } found ${ el } problems, ${ wl } warnings`
106
+ : undefined ;
107
+
108
+ const fmtSummary =
109
+ enabled && typeof summary === 'string' ? chalk . bold ( summary ) : summary ;
101
110
102
- const summary = ( options . verbose || hasProblems ) ? `${ deco } found ${ el } problems, ${ wl } warnings` : undefined ;
103
- const fmtSummary = enabled && typeof summary === 'string' ? chalk . bold ( summary ) : summary ;
104
111
const help = hasProblems ? `ⓘ Get help: ${ options . helpUrl } ` : undefined ;
105
112
106
- return [ ...problems , '' , fmtSummary , help ] . filter ( ( line ) : line is string => typeof line === 'string' ) ;
113
+ return [
114
+ ...problems ,
115
+ hasProblems ? '' : undefined ,
116
+ fmtSummary ,
117
+ help ,
118
+ help ? '' : undefined
119
+ ] . filter ( ( line ) : line is string => typeof line === 'string' ) ;
107
120
}
108
121
109
122
export default format ;
0 commit comments