Skip to content

Commit a0fc70e

Browse files
committed
feat: bubble up ESLint config errors
1 parent 287e89d commit a0fc70e

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

lib/handle-ts-files.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ export async function handleTsconfig({cwd, files}: {cwd: string; files: string[]
6868

6969
tsConfig.files = unincludedFiles;
7070

71-
try {
72-
await fs.mkdir(path.dirname(fallbackTsConfigPath), {recursive: true});
73-
await fs.writeFile(fallbackTsConfigPath, JSON.stringify(tsConfig, null, 2));
74-
} catch (error) {
75-
console.error(error);
71+
if (unincludedFiles.length > 0) {
72+
try {
73+
await fs.mkdir(path.dirname(fallbackTsConfigPath), {recursive: true});
74+
await fs.writeFile(fallbackTsConfigPath, JSON.stringify(tsConfig, null, 2));
75+
} catch (error) {
76+
console.error(error);
77+
}
7678
}
7779

7880
return {unincludedFiles, fallbackTsConfigPath};

lib/resolve-config.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from 'node:path';
22
import process from 'node:process';
33
import {cosmiconfig, defaultLoaders} from 'cosmiconfig';
4-
import pick from 'lodash.pick';
54
import arrify from 'arrify';
65
import {type FlatXoConfig, type LinterOptions, type XoConfigItem} from './types.js';
76
import {moduleName} from './constants.js';
@@ -49,22 +48,7 @@ export async function resolveXoConfig(options: LinterOptions): Promise<{
4948
filepath: flatConfigPath = '',
5049
} = await (flatConfigExplorer.search(searchPath) as Promise<{config: FlatXoConfig | undefined; filepath: string}>) ?? {};
5150

52-
const globalKeys = [
53-
'ignores',
54-
'settings',
55-
'parserOptions',
56-
'prettier',
57-
'semicolon',
58-
'space',
59-
'rules',
60-
'env',
61-
'extension',
62-
'files',
63-
'plugins',
64-
'react',
65-
];
66-
67-
flatOptions = arrify(flatOptions).map(config => pick(config, globalKeys));
51+
flatOptions = arrify(flatOptions);
6852

6953
return {
7054
flatOptions,

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"get-tsconfig": "^4.10.0",
9090
"globals": "^16.0.0",
9191
"globby": "^14.1.0",
92-
"lodash.pick": "^4.4.0",
9392
"meow": "^13.2.0",
9493
"micromatch": "^4.0.8",
9594
"open-editor": "^5.1.0",
@@ -102,7 +101,6 @@
102101
"@commitlint/cli": "^19.8.0",
103102
"@commitlint/config-conventional": "^19.8.0",
104103
"@types/eslint": "9.6.1",
105-
"@types/lodash.pick": "^4.4.9",
106104
"@types/micromatch": "^4.0.9",
107105
"@types/prettier": "^3.0.0",
108106
"ava": "^6.2.0",

test/cli.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,20 @@ test('gives helpful error message when config creates a circular dependency', as
335335
const error = await t.throwsAsync<ExecaError>($`node ./dist/cli --cwd ${t.context.cwd}`);
336336
t.true((error.stderr as string)?.includes('Error resolving XO config'));
337337
});
338+
339+
test('Config errors bubble up from ESLint when incorrect config options are set', async t => {
340+
const filePath = path.join(t.context.cwd, 'test.js');
341+
await fs.writeFile(filePath, dedent`console.log('hello');\n`, 'utf8');
342+
const xoConfigPath = path.join(t.context.cwd, 'xo.config.js');
343+
const xoConfig = dedent`
344+
export default [
345+
{
346+
invalidOption: 'some invalid value',
347+
space: true
348+
}
349+
]
350+
`;
351+
await fs.writeFile(xoConfigPath, xoConfig, 'utf8');
352+
const error = await t.throwsAsync<ExecaError>($`node ./dist/cli --cwd ${t.context.cwd}`);
353+
t.true((error.stderr as string)?.includes('ConfigError:') && (error.stderr as string)?.includes('Unexpected key "invalidOption" found'));
354+
});

0 commit comments

Comments
 (0)