@@ -147,11 +147,19 @@ const formatFileCount = (count: number, isError = false): string => {
147147 return `${ isError ? color . red ( formattedCount ) : formattedCount } ${ count === 1 ? 'file' : 'files' } ` ;
148148} ;
149149
150+ const reportNoSupportedFiles = ( patterns : string [ ] ) : void => {
151+ const targets = ( patterns . length ? patterns : [ '.' ] )
152+ . map ( ( pattern ) => color . cyan ( JSON . stringify ( pattern ) ) )
153+ . join ( ', ' ) ;
154+ logger . error ( `No supported files matched ${ targets } , or all matching files were ignored.` ) ;
155+ process . exitCode = 2 ;
156+ } ;
157+
150158const logFmtResult = (
151159 result : FmtRunResult ,
152160 mode : FmtMode ,
153161 cwd : string ,
154- matchedFileCount : number ,
162+ processedFileCount : number ,
155163 durationSeconds : number ,
156164) : void => {
157165 let writtenCount = 0 ;
@@ -177,12 +185,12 @@ const logFmtResult = (
177185 return ;
178186 }
179187
180- const matchedFiles = formatFileCount ( matchedFileCount ) ;
188+ const processedFiles = formatFileCount ( processedFileCount ) ;
181189 const time = prettyTime ( durationSeconds ) ;
182190 const message =
183191 writtenCount > 0
184- ? `Formatted ${ formatCount ( writtenCount ) } of ${ matchedFiles } in ${ time } .`
185- : `Checked ${ matchedFiles } in ${ time } . No changes needed.` ;
192+ ? `Formatted ${ formatCount ( writtenCount ) } of ${ processedFiles } in ${ time } .`
193+ : `Checked ${ processedFiles } in ${ time } . No changes needed.` ;
186194 logger [ result . exitCode === 0 ? 'success' : 'info' ] ( message ) ;
187195 return ;
188196 }
@@ -193,15 +201,15 @@ const logFmtResult = (
193201
194202 if ( differentCount > 0 ) {
195203 const differentFiles = formatFileCount ( differentCount , true ) ;
196- const matchedFiles = formatFileCount ( matchedFileCount ) ;
204+ const processedFiles = formatFileCount ( processedFileCount ) ;
197205 const checkOption = color . cyan ( '--check' ) ;
198206 logger . error (
199207 `Formatting issues found in ${ differentFiles } . Run without ${ checkOption } to fix.` ,
200208 ) ;
201- logger . info ( `Checked ${ matchedFiles } in ${ prettyTime ( durationSeconds ) } .` ) ;
209+ logger . info ( `Checked ${ processedFiles } in ${ prettyTime ( durationSeconds ) } .` ) ;
202210 } else if ( result . exitCode === 0 ) {
203211 logger . success (
204- `Checked ${ formatFileCount ( matchedFileCount ) } in ${ prettyTime ( durationSeconds ) } . No issues found.` ,
212+ `Checked ${ formatFileCount ( processedFileCount ) } in ${ prettyTime ( durationSeconds ) } . No issues found.` ,
205213 ) ;
206214 }
207215} ;
@@ -263,11 +271,7 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
263271 if ( noErrorOnUnmatchedPattern ) {
264272 return ;
265273 }
266- const targets = ( patterns . length ? patterns : [ '.' ] )
267- . map ( ( pattern ) => color . cyan ( JSON . stringify ( pattern ) ) )
268- . join ( ', ' ) ;
269- logger . error ( `No supported files matched ${ targets } , or all matching files were ignored.` ) ;
270- process . exitCode = 2 ;
274+ reportNoSupportedFiles ( patterns ) ;
271275 return ;
272276 }
273277
@@ -281,8 +285,13 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
281285 maxWorkers,
282286 } ) ;
283287
288+ if ( result . processedFileCount === 0 ) {
289+ reportNoSupportedFiles ( patterns ) ;
290+ return ;
291+ }
292+
284293 const durationSeconds = ( performance . now ( ) - startTime ) / 1000 ;
285- logFmtResult ( result , mode , cwd , files . length , durationSeconds ) ;
294+ logFmtResult ( result , mode , cwd , result . processedFileCount , durationSeconds ) ;
286295 process . exitCode = result . exitCode ;
287296 } catch ( error ) {
288297 logger . error ( error ) ;
0 commit comments