File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -243,9 +243,11 @@ const runFmtCLI = async (args: string[]): Promise<void> => {
243243 } ) ;
244244
245245 if ( files . length === 0 ) {
246- if ( mode !== 'list-different' ) {
247- logger . info ( 'No files matched.' ) ;
248- }
246+ const targets = ( patterns . length ? patterns : [ '.' ] )
247+ . map ( ( pattern ) => color . cyan ( JSON . stringify ( pattern ) ) )
248+ . join ( ', ' ) ;
249+ logger . error ( `No supported files matched ${ targets } , or all matching files were ignored.` ) ;
250+ process . exitCode = 2 ;
249251 return ;
250252 }
251253
Original file line number Diff line number Diff line change @@ -585,16 +585,15 @@ test('writes nothing for empty stdin', () => {
585585 expect ( result . stderr ) . toBe ( '' ) ;
586586} ) ;
587587
588- test ( 'reports when no files match' , ( ) => {
589- const writeResult = runFmt ( [ 'missing/**/*.ts' ] ) ;
588+ test ( 'returns exit code 2 when no files match' , ( ) => {
589+ for ( const modeArgs of [ [ ] , [ '--check' ] , [ '--list-different' ] ] ) {
590+ const result = runFmt ( [ ...modeArgs , 'missing/**/*.ts' ] ) ;
590591
591- expect ( writeResult . status ) . toBe ( 0 ) ;
592- expect ( writeResult . stdout ) . toBe ( 'info No files matched.\n' ) ;
593- expect ( writeResult . stderr ) . toBe ( '' ) ;
594-
595- const checkResult = runFmt ( [ '--check' , 'missing/**/*.ts' ] ) ;
596-
597- expect ( checkResult . status ) . toBe ( 0 ) ;
598- expect ( checkResult . stdout ) . toBe ( 'info No files matched.\n' ) ;
599- expect ( checkResult . stderr ) . toBe ( '' ) ;
592+ expect ( result . status ) . toBe ( 2 ) ;
593+ expect ( result . stdout ) . toBe ( '' ) ;
594+ expect ( result . stderr ) . toContain (
595+ 'No supported files matched "missing/**/*.ts", or all matching files were ignored.' ,
596+ ) ;
597+ expect ( result . stderr ) . not . toContain ( '\n at ' ) ;
598+ }
600599} ) ;
You can’t perform that action at this time.
0 commit comments