Skip to content

Commit 3621ad4

Browse files
authored
Fix: Allow name on global ignores (#806)
1 parent 92daab5 commit 3621ad4

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

lib/xo-to-eslint.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ export function xoToEslintConfig(flatXoConfig: XoConfigItem[] | undefined, {pret
3131
}
3232

3333
/** Special case global ignores */
34-
if (keysOfXoConfig.length === 1 && keysOfXoConfig[0] === 'ignores') {
35-
baseConfig.push({ignores: arrify(xoConfigItem.ignores)});
36-
continue;
34+
if (xoConfigItem.ignores) {
35+
if (keysOfXoConfig.length === 1) {
36+
baseConfig.push({ignores: arrify(xoConfigItem.ignores)});
37+
continue;
38+
} else if (keysOfXoConfig.length === 2 && xoConfigItem.name) {
39+
baseConfig.push({name: xoConfigItem.name, ignores: arrify(xoConfigItem.ignores)});
40+
continue;
41+
}
3742
}
3843

3944
/**

test/xo-to-eslint.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,40 @@ test('prettier rules are applied after react rules', t => {
199199

200200
t.is(getJsRule(flatConfig, 'react/jsx-tag-spacing'), 'off');
201201
});
202+
203+
test('global ignores are respected', t => {
204+
const flatConfig = xoToEslintConfig([
205+
{ignores: ['**/test']},
206+
]);
207+
208+
t.deepEqual(flatConfig.at(-1), {ignores: ['**/test']});
209+
});
210+
211+
test('global ignores as strings are respected', t => {
212+
const flatConfig = xoToEslintConfig([
213+
{ignores: '**/test'},
214+
]);
215+
216+
t.deepEqual(flatConfig.at(-1), {ignores: ['**/test']});
217+
});
218+
219+
test('global ignores with names are respected', t => {
220+
const flatConfig = xoToEslintConfig([
221+
{name: 'test-ignores', ignores: '**/test'},
222+
]);
223+
224+
t.deepEqual(flatConfig.at(-1), {name: 'test-ignores', ignores: ['**/test']});
225+
});
226+
227+
test('empty configs are filtered', t => {
228+
const flatConfig = xoToEslintConfig([
229+
{name: 'test-ignores', ignores: '**/test'},
230+
{},
231+
{},
232+
{},
233+
{rules: {}},
234+
]);
235+
236+
t.deepEqual(flatConfig.at(-1), {files: [allFilesGlob], rules: {}});
237+
t.deepEqual(flatConfig.at(-2), {name: 'test-ignores', ignores: ['**/test']});
238+
});

0 commit comments

Comments
 (0)