Skip to content

Commit 5c9a692

Browse files
committed
feature: @putout/eslint: improve support of FlatConfig
1 parent 888b338 commit 5c9a692

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

packages/eslint/eslint.config.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/eslint/eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {recommended} from 'eslint-plugin-putout';
2+
3+
export default recommended;

packages/eslint/lib/get-eslint.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import process from 'node:process';
33
import {loadESLint} from 'eslint';
44
import {findUp} from 'find-up';
55

6+
const {isArray} = Array;
7+
const maybeArray = (a) => isArray(a) ? a : [a];
68
const CWD = process.cwd();
79

810
export const getESLint = async ({name, fix, config, overrideConfigFile, loadESLintOverride, find = findUp, findFlat = find, findRC = find}) => {
@@ -61,18 +63,19 @@ async function getOldESLint({cwd, fix, config, overrideConfigFile, loadESLintOve
6163
return eslint;
6264
}
6365

64-
async function getFlatESLint({cwd, fix, config, overrideConfigFile, loadESLintOverride = loadESLint}) {
66+
async function getFlatESLint({cwd, fix, config = [], overrideConfigFile, loadESLintOverride = loadESLint}) {
6567
const FlatESLint = await loadESLintOverride({
6668
useFlatConfig: true,
6769
});
6870

6971
const eslint = new FlatESLint({
7072
cwd,
7173
fix,
72-
overrideConfig: {
73-
ignores: ['!.*'],
74-
...config,
75-
},
74+
overrideConfig: [
75+
...maybeArray(config), {
76+
ignores: ['!.*'],
77+
},
78+
],
7679
...overrideConfigFile && {
7780
overrideConfigFile,
7881
},

packages/eslint/lib/get-eslint.spec.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ test('putout: eslint: get-eslint: config: putout', async (t) => {
3333
const expected = [{
3434
cwd: __dirname,
3535
fix: false,
36-
overrideConfig: {
36+
overrideConfig: [{
3737
ignores: ['!.*'],
38-
},
38+
}],
3939
}];
4040

4141
t.calledWith(ESLintOverride, expected);
@@ -133,9 +133,9 @@ test('putout: eslint: get-eslint: flat: overrideConfigFile', async (t) => {
133133
const expected = [{
134134
cwd: CWD,
135135
fix: false,
136-
overrideConfig: {
136+
overrideConfig: [{
137137
ignores: ['!.*'],
138-
},
138+
}],
139139
overrideConfigFile: 'other.config.js',
140140
}];
141141

@@ -166,9 +166,9 @@ test('putout: eslint: get-eslint: flat: no overrides', async (t) => {
166166
const expected = [{
167167
cwd: CWD,
168168
fix: false,
169-
overrideConfig: {
169+
overrideConfig: [{
170170
ignores: ['!.*'],
171-
},
171+
}],
172172
}];
173173

174174
t.calledWith(ESLintOverride, expected);

0 commit comments

Comments
 (0)