Skip to content

Commit ad6b118

Browse files
authored
fix: check nested files array size before skipping the config (#396)
* fix: check nested `files` array size before skipping the config * test * update snapshot * test test rule to warn to make it easier to spot
1 parent 04e4893 commit ad6b118

File tree

5 files changed

+358
-5
lines changed

5 files changed

+358
-5
lines changed
Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`config-with-extends.eslint.spec.ts > config-with-extends.eslint.spec.ts 1`] = `
4+
{
5+
"config": {
6+
"$schema": "./node_modules/oxlint/configuration_schema.json",
7+
"categories": {
8+
"correctness": "off",
9+
},
10+
"env": {
11+
"builtin": true,
12+
},
13+
"overrides": [
14+
{
15+
"files": [
16+
"**/*.ts",
17+
],
18+
"plugins": [
19+
"typescript",
20+
],
21+
"rules": {
22+
"@typescript-eslint/ban-ts-comment": "error",
23+
"@typescript-eslint/no-duplicate-enum-values": "error",
24+
"@typescript-eslint/no-empty-object-type": "error",
25+
"@typescript-eslint/no-explicit-any": "warn",
26+
"@typescript-eslint/no-extra-non-null-assertion": "error",
27+
"@typescript-eslint/no-misused-new": "error",
28+
"@typescript-eslint/no-namespace": "error",
29+
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
30+
"@typescript-eslint/no-require-imports": "error",
31+
"@typescript-eslint/no-this-alias": "error",
32+
"@typescript-eslint/no-unnecessary-type-constraint": "error",
33+
"@typescript-eslint/no-unsafe-declaration-merging": "error",
34+
"@typescript-eslint/no-unsafe-function-type": "error",
35+
"@typescript-eslint/no-wrapper-object-types": "error",
36+
"@typescript-eslint/prefer-as-const": "error",
37+
"@typescript-eslint/prefer-namespace-keyword": "error",
38+
"@typescript-eslint/triple-slash-reference": "error",
39+
"constructor-super": "off",
40+
"no-array-constructor": "error",
41+
"no-class-assign": "off",
42+
"no-const-assign": "off",
43+
"no-dupe-class-members": "off",
44+
"no-dupe-keys": "off",
45+
"no-func-assign": "off",
46+
"no-import-assign": "off",
47+
"no-new-native-nonconstructor": "off",
48+
"no-obj-calls": "off",
49+
"no-redeclare": "off",
50+
"no-setter-return": "off",
51+
"no-this-before-super": "off",
52+
"no-unsafe-negation": "off",
53+
"no-unused-expressions": "error",
54+
"no-unused-vars": "error",
55+
"no-var": "error",
56+
"no-with": "off",
57+
"prefer-const": "error",
58+
"prefer-rest-params": "error",
59+
"prefer-spread": "error",
60+
},
61+
},
62+
],
63+
"plugins": [],
64+
},
65+
"skipped": {
66+
"js-plugins": [],
67+
"not-implemented": [],
68+
"nursery": [
69+
"getter-return",
70+
"no-undef",
71+
"no-unreachable",
72+
],
73+
"type-aware": [],
74+
"unsupported": [],
75+
},
76+
"warnings": [
77+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.tsx"]",
78+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.mts"]",
79+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.cts"]",
80+
],
81+
}
82+
`;
83+
84+
exports[`config-with-extends.eslint.spec.ts --js-plugins > config-with-extends.eslint.spec.ts--js-plugins 1`] = `
85+
{
86+
"config": {
87+
"$schema": "./node_modules/oxlint/configuration_schema.json",
88+
"categories": {
89+
"correctness": "off",
90+
},
91+
"env": {
92+
"builtin": true,
93+
},
94+
"overrides": [
95+
{
96+
"files": [
97+
"**/*.ts",
98+
],
99+
"plugins": [
100+
"typescript",
101+
],
102+
"rules": {
103+
"@typescript-eslint/ban-ts-comment": "error",
104+
"@typescript-eslint/no-duplicate-enum-values": "error",
105+
"@typescript-eslint/no-empty-object-type": "error",
106+
"@typescript-eslint/no-explicit-any": "warn",
107+
"@typescript-eslint/no-extra-non-null-assertion": "error",
108+
"@typescript-eslint/no-misused-new": "error",
109+
"@typescript-eslint/no-namespace": "error",
110+
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
111+
"@typescript-eslint/no-require-imports": "error",
112+
"@typescript-eslint/no-this-alias": "error",
113+
"@typescript-eslint/no-unnecessary-type-constraint": "error",
114+
"@typescript-eslint/no-unsafe-declaration-merging": "error",
115+
"@typescript-eslint/no-unsafe-function-type": "error",
116+
"@typescript-eslint/no-wrapper-object-types": "error",
117+
"@typescript-eslint/prefer-as-const": "error",
118+
"@typescript-eslint/prefer-namespace-keyword": "error",
119+
"@typescript-eslint/triple-slash-reference": "error",
120+
"constructor-super": "off",
121+
"no-array-constructor": "error",
122+
"no-class-assign": "off",
123+
"no-const-assign": "off",
124+
"no-dupe-class-members": "off",
125+
"no-dupe-keys": "off",
126+
"no-func-assign": "off",
127+
"no-import-assign": "off",
128+
"no-new-native-nonconstructor": "off",
129+
"no-obj-calls": "off",
130+
"no-redeclare": "off",
131+
"no-setter-return": "off",
132+
"no-this-before-super": "off",
133+
"no-unsafe-negation": "off",
134+
"no-unused-expressions": "error",
135+
"no-unused-vars": "error",
136+
"no-var": "error",
137+
"no-with": "off",
138+
"prefer-const": "error",
139+
"prefer-rest-params": "error",
140+
"prefer-spread": "error",
141+
},
142+
},
143+
],
144+
"plugins": [],
145+
},
146+
"skipped": {
147+
"js-plugins": [],
148+
"not-implemented": [],
149+
"nursery": [
150+
"getter-return",
151+
"no-undef",
152+
"no-unreachable",
153+
],
154+
"type-aware": [],
155+
"unsupported": [],
156+
},
157+
"warnings": [
158+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.tsx"]",
159+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.mts"]",
160+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.cts"]",
161+
],
162+
}
163+
`;
164+
165+
exports[`config-with-extends.eslint.spec.ts --type-aware > config-with-extends.eslint.spec.ts--type-aware 1`] = `
166+
{
167+
"config": {
168+
"$schema": "./node_modules/oxlint/configuration_schema.json",
169+
"categories": {
170+
"correctness": "off",
171+
},
172+
"env": {
173+
"builtin": true,
174+
},
175+
"overrides": [
176+
{
177+
"files": [
178+
"**/*.ts",
179+
],
180+
"plugins": [
181+
"typescript",
182+
],
183+
"rules": {
184+
"@typescript-eslint/ban-ts-comment": "error",
185+
"@typescript-eslint/no-duplicate-enum-values": "error",
186+
"@typescript-eslint/no-empty-object-type": "error",
187+
"@typescript-eslint/no-explicit-any": "warn",
188+
"@typescript-eslint/no-extra-non-null-assertion": "error",
189+
"@typescript-eslint/no-misused-new": "error",
190+
"@typescript-eslint/no-namespace": "error",
191+
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
192+
"@typescript-eslint/no-require-imports": "error",
193+
"@typescript-eslint/no-this-alias": "error",
194+
"@typescript-eslint/no-unnecessary-type-constraint": "error",
195+
"@typescript-eslint/no-unsafe-declaration-merging": "error",
196+
"@typescript-eslint/no-unsafe-function-type": "error",
197+
"@typescript-eslint/no-wrapper-object-types": "error",
198+
"@typescript-eslint/prefer-as-const": "error",
199+
"@typescript-eslint/prefer-namespace-keyword": "error",
200+
"@typescript-eslint/triple-slash-reference": "error",
201+
"constructor-super": "off",
202+
"no-array-constructor": "error",
203+
"no-class-assign": "off",
204+
"no-const-assign": "off",
205+
"no-dupe-class-members": "off",
206+
"no-dupe-keys": "off",
207+
"no-func-assign": "off",
208+
"no-import-assign": "off",
209+
"no-new-native-nonconstructor": "off",
210+
"no-obj-calls": "off",
211+
"no-redeclare": "off",
212+
"no-setter-return": "off",
213+
"no-this-before-super": "off",
214+
"no-unsafe-negation": "off",
215+
"no-unused-expressions": "error",
216+
"no-unused-vars": "error",
217+
"no-var": "error",
218+
"no-with": "off",
219+
"prefer-const": "error",
220+
"prefer-rest-params": "error",
221+
"prefer-spread": "error",
222+
},
223+
},
224+
],
225+
"plugins": [],
226+
},
227+
"skipped": {
228+
"js-plugins": [],
229+
"not-implemented": [],
230+
"nursery": [
231+
"getter-return",
232+
"no-undef",
233+
"no-unreachable",
234+
],
235+
"type-aware": [],
236+
"unsupported": [],
237+
},
238+
"warnings": [
239+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.tsx"]",
240+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.mts"]",
241+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.cts"]",
242+
],
243+
}
244+
`;
245+
246+
exports[`config-with-extends.eslint.spec.ts merge > config-with-extends.eslint.spec.ts--merge 1`] = `
247+
{
248+
"config": {
249+
"$schema": "./node_modules/oxlint/configuration_schema.json",
250+
"categories": {
251+
"correctness": "error",
252+
"perf": "error",
253+
},
254+
"env": {
255+
"builtin": true,
256+
},
257+
"overrides": [
258+
{
259+
"files": [
260+
"**/*.ts",
261+
],
262+
"plugins": [
263+
"typescript",
264+
],
265+
"rules": {
266+
"@typescript-eslint/ban-ts-comment": "error",
267+
"@typescript-eslint/no-duplicate-enum-values": "error",
268+
"@typescript-eslint/no-empty-object-type": "error",
269+
"@typescript-eslint/no-explicit-any": "warn",
270+
"@typescript-eslint/no-extra-non-null-assertion": "error",
271+
"@typescript-eslint/no-misused-new": "error",
272+
"@typescript-eslint/no-namespace": "error",
273+
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
274+
"@typescript-eslint/no-require-imports": "error",
275+
"@typescript-eslint/no-this-alias": "error",
276+
"@typescript-eslint/no-unnecessary-type-constraint": "error",
277+
"@typescript-eslint/no-unsafe-declaration-merging": "error",
278+
"@typescript-eslint/no-unsafe-function-type": "error",
279+
"@typescript-eslint/no-wrapper-object-types": "error",
280+
"@typescript-eslint/prefer-as-const": "error",
281+
"@typescript-eslint/prefer-namespace-keyword": "error",
282+
"@typescript-eslint/triple-slash-reference": "error",
283+
"constructor-super": "off",
284+
"no-array-constructor": "error",
285+
"no-class-assign": "off",
286+
"no-const-assign": "off",
287+
"no-dupe-class-members": "off",
288+
"no-dupe-keys": "off",
289+
"no-func-assign": "off",
290+
"no-import-assign": "off",
291+
"no-new-native-nonconstructor": "off",
292+
"no-obj-calls": "off",
293+
"no-redeclare": "off",
294+
"no-setter-return": "off",
295+
"no-this-before-super": "off",
296+
"no-unsafe-negation": "off",
297+
"no-unused-expressions": "error",
298+
"no-unused-vars": "error",
299+
"no-var": "error",
300+
"no-with": "off",
301+
"prefer-const": "error",
302+
"prefer-rest-params": "error",
303+
"prefer-spread": "error",
304+
},
305+
},
306+
],
307+
},
308+
"skipped": {
309+
"js-plugins": [],
310+
"not-implemented": [],
311+
"nursery": [
312+
"getter-return",
313+
"no-undef",
314+
"no-unreachable",
315+
],
316+
"type-aware": [],
317+
"unsupported": [],
318+
},
319+
"warnings": [
320+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.tsx"]",
321+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.mts"]",
322+
"ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ["**/*.ts","**/*.cts"]",
323+
],
324+
}
325+
`;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @ts-expect-error
2+
import many_extends_test from './projects/config-with-extends.eslint.config.mjs';
3+
import { testProject } from './utils.js';
4+
5+
testProject('config-with-extends.eslint.spec.ts', many_extends_test);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// eslint.config.js
2+
import { defineConfig } from 'eslint/config';
3+
import tseslint from 'typescript-eslint';
4+
5+
export default defineConfig([
6+
{
7+
files: ['**/*.ts'],
8+
extends: [tseslint.configs.recommended],
9+
rules: { '@typescript-eslint/no-explicit-any': 'warn' },
10+
},
11+
]);

src/files.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ describe('processConfigFiles', () => {
6262
['**/*.ts', '**/*.tsx'],
6363
'**/*.js',
6464
['**/*.mjs', '**/*.cjs'],
65+
['**/*.vue', '**/*.vue'],
6566
'**/*.jsx',
6667
],
6768
reporter
6869
);
6970

70-
expect(result).toStrictEqual(['**/*.js', '**/*.jsx']);
71+
expect(result).toStrictEqual(['**/*.js', '**/*.vue', '**/*.jsx']);
7172

7273
const reports = reporter.getWarnings();
7374
expect(reports).toHaveLength(2);

src/files.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ export function processConfigFiles(
2020

2121
for (const file of filesArray) {
2222
if (Array.isArray(file)) {
23-
// Report nested array (AND glob pattern) as unsupported
24-
reporter?.addWarning(
25-
`ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ${JSON.stringify(file)}`
26-
);
23+
const filesSet = new Set<string>(file);
24+
if (filesSet.size === 0) {
25+
// skip empty nested arrays
26+
continue;
27+
}
28+
29+
if (filesSet.size > 1) {
30+
// Report if there are multiple patterns in the nested array (AND pattern)
31+
reporter?.addWarning(
32+
`ESLint AND glob patterns (nested arrays in files) are not supported in oxlint: ${JSON.stringify(file)}`
33+
);
34+
continue;
35+
}
36+
37+
simpleFiles.push(file[0]);
2738
} else {
2839
simpleFiles.push(file);
2940
}

0 commit comments

Comments
 (0)