33import path from "path" ;
44import fs from "fs" ;
55
6- const FLAT_CONFIG_FILENAME = "eslint.config.js" ;
6+ const FLAT_CONFIG_FILENAMES = [
7+ "eslint.config.js" ,
8+ "eslint.config.mjs" ,
9+ "eslint.config.cjs" ,
10+ ] ;
711/**
812 * Returns whether flat config should be used.
913 * @returns {Promise<boolean> } Whether flat config should be used.
@@ -29,25 +33,26 @@ export function shouldUseFlatConfig(cwd: string): boolean {
2933 * @returns {string|undefined } The filename if found or `undefined` if not.
3034 */
3135function findFlatConfigFile ( cwd : string ) {
32- return findUp ( FLAT_CONFIG_FILENAME , { cwd } ) ;
36+ return findUp ( FLAT_CONFIG_FILENAMES , { cwd } ) ;
3337}
3438
3539/** We used https://github.com/sindresorhus/find-up/blob/b733bb70d3aa21b22fa011be8089110d467c317f/index.js#L94 as a reference */
36- function findUp ( name : string , options : { cwd : string } ) {
40+ function findUp ( names : string [ ] , options : { cwd : string } ) {
3741 let directory = path . resolve ( options . cwd ) ;
3842 const { root } = path . parse ( directory ) ;
3943 const stopAt = path . resolve ( directory , root ) ;
40-
4144 // eslint-disable-next-line no-constant-condition -- ignore
4245 while ( true ) {
43- const target = path . resolve ( directory , name ) ;
44- const stat = fs . existsSync ( target )
45- ? fs . statSync ( target , {
46- throwIfNoEntry : false ,
47- } )
48- : null ;
49- if ( stat ?. isFile ( ) ) {
50- return target ;
46+ for ( const name of names ) {
47+ const target = path . resolve ( directory , name ) ;
48+ const stat = fs . existsSync ( target )
49+ ? fs . statSync ( target , {
50+ throwIfNoEntry : false ,
51+ } )
52+ : null ;
53+ if ( stat ?. isFile ( ) ) {
54+ return target ;
55+ }
5156 }
5257
5358 if ( directory === stopAt ) {
0 commit comments