Skip to content

Commit 3e45ac0

Browse files
committed
feat(plugin-eslint): search for flat config files in parent directories
1 parent 2acdb2d commit 3e45ac0

File tree

1 file changed

+10
-8
lines changed
  • packages/plugin-eslint/src/lib/meta/versions

1 file changed

+10
-8
lines changed

packages/plugin-eslint/src/lib/meta/versions/flat.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Linter, Rule } from 'eslint';
22
// eslint-disable-next-line import/no-deprecated
33
import { builtinRules } from 'eslint/use-at-your-own-risk';
44
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';
66
import type { ESLintTarget } from '../../config';
77
import { jsonHash } from '../hash';
88
import {
@@ -41,14 +41,16 @@ async function loadConfigByDefaultLocation(): Promise<FlatConfig> {
4141
'eslint.config.mjs',
4242
'eslint.config.cjs',
4343
];
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);
4947
}
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+
);
5254
}
5355

5456
async function loadConfigByPath(path: string): Promise<FlatConfig> {

0 commit comments

Comments
 (0)