Skip to content

Commit c6fb044

Browse files
committed
featur: @putout/test: eslint: improve support of FlatConfig
1 parent 5c9a692 commit c6fb044

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

packages/test/.eslintrc.json

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

packages/test/eslint.config.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {
2+
createESLintConfig,
3+
matchToFlat,
4+
} from '@putout/eslint-flat';
5+
import {safeAlign} from 'eslint-plugin-putout';
6+
7+
export const match = {
8+
'rules/**/*.js': {
9+
'import/no-extraneous-dependencies': 'off',
10+
},
11+
};
12+
13+
export default createESLintConfig([safeAlign, matchToFlat(match)]);

packages/test/lib/eslint/eslint.mjs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import tryToCatch from 'try-to-catch';
1515
import {extend} from 'supertape';
1616
import {lint} from '@putout/eslint/lint';
1717
import tryCatch from 'try-catch';
18+
import {recommended} from 'eslint-plugin-putout';
1819

1920
const {keys} = Object;
2021
const {isArray} = Array;
@@ -38,14 +39,6 @@ const remove = (name) => {
3839

3940
const getMessage = ({message}) => message;
4041

41-
const config = {
42-
extends: [
43-
'plugin:n/recommended',
44-
'plugin:eslint-plugin/recommended',
45-
'plugin:putout/recommended',
46-
],
47-
};
48-
4942
const readSync = (name) => {
5043
const [, data] = tryCatch(readFileSync, `${name}.js`, 'utf8');
5144

@@ -74,7 +67,7 @@ export const createTest = (url, plugins = {}) => {
7467
const fixtureDir = new URL('fixture', url).pathname;
7568

7669
return extend({
77-
process: (operator) => async (name, override) => {
70+
process: (operator) => async (name, overrides) => {
7871
const full = join(fixtureDir, basename(name));
7972
const [resolvedName, code] = await read(full);
8073
const fix = true;
@@ -84,10 +77,10 @@ export const createTest = (url, plugins = {}) => {
8477
code,
8578
fix,
8679
putout: true,
87-
config: {
88-
...config,
89-
...override,
90-
},
80+
config: [
81+
...recommended,
82+
...parseOverrides(overrides, '@putout/test: eslint: process: overrides'),
83+
],
9184
});
9285

9386
const fixtureName = `${full}-fix`;
@@ -110,10 +103,10 @@ export const createTest = (url, plugins = {}) => {
110103

111104
const [source] = await eslint({
112105
name: resolvedName,
113-
config: {
114-
...config,
115-
...overrides,
116-
},
106+
config: [
107+
...recommended,
108+
...parseOverrides(overrides, '@putout/test: eslint: no process: overrides'),
109+
],
117110
code,
118111
putout: true,
119112
fix,
@@ -126,18 +119,18 @@ export const createTest = (url, plugins = {}) => {
126119

127120
return operator.equal(source, code);
128121
},
129-
comparePlaces: (operator) => async (name, expected, override) => {
122+
comparePlaces: (operator) => async (name, expected, overrides) => {
130123
const full = join(fixtureDir, name);
131124
const [resolvedName, code] = await read(full);
132125

133126
const [, places] = await eslint({
134127
name: resolvedName,
135128
code,
136129
putout: true,
137-
config: {
138-
...config,
139-
...override,
140-
},
130+
config: [
131+
...recommended,
132+
...parseOverrides(overrides, '@putout/test: eslint: compare places: overrides'),
133+
],
141134
});
142135

143136
return operator.deepEqual(places, expected);
@@ -178,3 +171,20 @@ export const createTest = (url, plugins = {}) => {
178171
},
179172
});
180173
};
174+
175+
function parseOverrides(overrides, name) {
176+
const config = {
177+
name,
178+
};
179+
180+
if (!overrides)
181+
return [config];
182+
183+
if (isArray(overrides))
184+
return overrides;
185+
186+
return [{
187+
...config,
188+
...overrides,
189+
}];
190+
}

0 commit comments

Comments
 (0)