@@ -109,8 +109,11 @@ const prettyTime = (seconds: number): string => {
109109 return `${ minutesLabel } ${ secondsLabel } ` ;
110110} ;
111111
112- const getFileLabel = ( count : number ) : string => ( count === 1 ? 'file' : 'files' ) ;
113- const formatFileCount = ( count : number ) : string => color . bold ( count ) ;
112+ const formatCount = ( count : number ) : string => color . bold ( count ) ;
113+ const formatFileCount = ( count : number , isError = false ) : string => {
114+ const formattedCount = formatCount ( count ) ;
115+ return `${ isError ? color . red ( formattedCount ) : formattedCount } ${ count === 1 ? 'file' : 'files' } ` ;
116+ } ;
114117
115118const logFmtResult = (
116119 result : FmtRunResult ,
@@ -119,38 +122,34 @@ const logFmtResult = (
119122 matchedFileCount : number ,
120123 durationSeconds : number ,
121124) : void => {
122- let writtenCount = 0 ;
123125 let differentCount = 0 ;
124- let errorCount = 0 ;
125126
126127 for ( const file of result . files ) {
127- const displayPath = getDisplayPath ( cwd , file . path ) ;
128-
129128 if ( file . status === 'written' ) {
130- writtenCount ++ ;
131- } else if ( file . status === 'different' ) {
129+ continue ;
130+ }
131+
132+ const displayPath = getDisplayPath ( cwd , file . path ) ;
133+ if ( file . status === 'different' ) {
132134 differentCount ++ ;
133135 logger [ mode === 'check' ? 'error' : 'log' ] ( displayPath ) ;
134136 } else if ( file . status === 'error' ) {
135- errorCount ++ ;
136137 logger . error ( `${ displayPath } : ${ String ( file . error ) } ` ) ;
137138 }
138139 }
139140
140141 if ( mode === 'write' ) {
141- if ( errorCount > 0 ) {
142+ if ( result . exitCode !== 0 ) {
142143 return ;
143144 }
144145
145- const files = getFileLabel ( matchedFileCount ) ;
146- const matchedCount = formatFileCount ( matchedFileCount ) ;
146+ const writtenCount = result . files . length ;
147+ const matchedFiles = formatFileCount ( matchedFileCount ) ;
147148 const time = prettyTime ( durationSeconds ) ;
148149 if ( writtenCount > 0 ) {
149- logger . success (
150- `Formatted ${ formatFileCount ( writtenCount ) } of ${ matchedCount } ${ files } in ${ time } .` ,
151- ) ;
150+ logger . success ( `Formatted ${ formatCount ( writtenCount ) } of ${ matchedFiles } in ${ time } .` ) ;
152151 } else {
153- logger . success ( `Checked ${ matchedCount } ${ files } in ${ time } . No changes needed.` ) ;
152+ logger . success ( `Checked ${ matchedFiles } in ${ time } . No changes needed.` ) ;
154153 }
155154 return ;
156155 }
@@ -160,19 +159,16 @@ const logFmtResult = (
160159 }
161160
162161 if ( differentCount > 0 ) {
163- const differentFiles = getFileLabel ( differentCount ) ;
164- const matchedFiles = getFileLabel ( matchedFileCount ) ;
165- const count = color . red ( formatFileCount ( differentCount ) ) ;
166- const matchedCount = formatFileCount ( matchedFileCount ) ;
162+ const differentFiles = formatFileCount ( differentCount , true ) ;
163+ const matchedFiles = formatFileCount ( matchedFileCount ) ;
167164 const checkOption = color . cyan ( '--check' ) ;
168165 logger . error (
169- `Formatting issues found in ${ count } ${ differentFiles } . Run without ${ checkOption } to fix.` ,
166+ `Formatting issues found in ${ differentFiles } . Run without ${ checkOption } to fix.` ,
170167 ) ;
171- logger . info ( `Checked ${ matchedCount } ${ matchedFiles } in ${ prettyTime ( durationSeconds ) } .` ) ;
172- } else if ( errorCount === 0 ) {
173- const files = getFileLabel ( matchedFileCount ) ;
168+ logger . info ( `Checked ${ matchedFiles } in ${ prettyTime ( durationSeconds ) } .` ) ;
169+ } else if ( result . exitCode === 0 ) {
174170 logger . success (
175- `Checked ${ formatFileCount ( matchedFileCount ) } ${ files } in ${ prettyTime ( durationSeconds ) } . No issues found.` ,
171+ `Checked ${ formatFileCount ( matchedFileCount ) } in ${ prettyTime ( durationSeconds ) } . No issues found.` ,
176172 ) ;
177173 }
178174} ;
@@ -196,8 +192,10 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
196192 } ) ;
197193 const files = await discoverFmtFiles ( { cwd, patterns, config } ) ;
198194
199- if ( files . length === 0 && mode !== 'list-different' ) {
200- logger . info ( 'No files matched.' ) ;
195+ if ( files . length === 0 ) {
196+ if ( mode !== 'list-different' ) {
197+ logger . info ( 'No files matched.' ) ;
198+ }
201199 return ;
202200 }
203201
0 commit comments