3
3
import path from "path" ;
4
4
import fs from "fs" ;
5
5
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
+ ] ;
7
11
/**
8
12
* Returns whether flat config should be used.
9
13
* @returns {Promise<boolean> } Whether flat config should be used.
@@ -29,25 +33,26 @@ export function shouldUseFlatConfig(cwd: string): boolean {
29
33
* @returns {string|undefined } The filename if found or `undefined` if not.
30
34
*/
31
35
function findFlatConfigFile ( cwd : string ) {
32
- return findUp ( FLAT_CONFIG_FILENAME , { cwd } ) ;
36
+ return findUp ( FLAT_CONFIG_FILENAMES , { cwd } ) ;
33
37
}
34
38
35
39
/** 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 } ) {
37
41
let directory = path . resolve ( options . cwd ) ;
38
42
const { root } = path . parse ( directory ) ;
39
43
const stopAt = path . resolve ( directory , root ) ;
40
-
41
44
// eslint-disable-next-line no-constant-condition -- ignore
42
45
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
+ }
51
56
}
52
57
53
58
if ( directory === stopAt ) {
0 commit comments