@@ -2,7 +2,7 @@ import type { Linter, Rule } from 'eslint';
2
2
// eslint-disable-next-line import/no-deprecated
3
3
import { builtinRules } from 'eslint/use-at-your-own-risk' ;
4
4
import { isAbsolute , join } from 'node:path' ;
5
- import { exists , fileExists , toArray , ui } from '@code-pushup/utils' ;
5
+ import { exists , findNearestFile , toArray , ui } from '@code-pushup/utils' ;
6
6
import type { ESLintTarget } from '../../config' ;
7
7
import { jsonHash } from '../hash' ;
8
8
import {
@@ -41,14 +41,16 @@ async function loadConfigByDefaultLocation(): Promise<FlatConfig> {
41
41
'eslint.config.mjs' ,
42
42
'eslint.config.cjs' ,
43
43
] ;
44
- // eslint-disable-next-line functional/no-loop-statements
45
- for ( const name of flatConfigFileNames ) {
46
- if ( await fileExists ( name ) ) {
47
- return loadConfigByPath ( name ) ;
48
- }
44
+ const configPath = await findNearestFile ( flatConfigFileNames ) ;
45
+ if ( configPath ) {
46
+ return loadConfigByPath ( configPath ) ;
49
47
}
50
- // TODO: walk up directories
51
- throw new Error ( 'ESLint config file not found' ) ;
48
+ throw new Error (
49
+ [
50
+ `ESLint config file not found - expected ${ flatConfigFileNames . join ( '/' ) } in ${ process . cwd ( ) } or some parent directory` ,
51
+ 'If your ESLint config is a non-standard location, use the `eslintrc` parameter to specify the path.' ,
52
+ ] . join ( '\n' ) ,
53
+ ) ;
52
54
}
53
55
54
56
async function loadConfigByPath ( path : string ) : Promise < FlatConfig > {
0 commit comments