Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe558e5

Browse files
fix(typescript-eslint): address bugs inconfig() around global ignores (typescript-eslint#11065)
Co-authored-by: Jeremy Nguyen <nguyen.jeremyt@gmail.com>
1 parent1a3ab0d commitbe558e5

File tree

2 files changed

+102
-8
lines changed

2 files changed

+102
-8
lines changed

‎packages/typescript-eslint/src/config-helper.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,42 @@ export function config(
128128
);
129129
}
130130

131-
return[
132-
...extendsArrFlattened.map(extension=>{
133-
constname=[config.name,extension.name].filter(Boolean).join('__');
134-
return{
131+
constconfigArray=[];
132+
133+
for(constextensionofextendsArrFlattened){
134+
constname=[config.name,extension.name].filter(Boolean).join('__');
135+
if(isPossiblyGlobalIgnores(extension)){
136+
// If it's a global ignores, then just pass it along
137+
configArray.push({
138+
...extension,
139+
...(name&&{ name}),
140+
});
141+
}else{
142+
configArray.push({
135143
...extension,
136144
...(config.files&&{files:config.files}),
137145
...(config.ignores&&{ignores:config.ignores}),
138146
...(name&&{ name}),
139-
};
140-
}),
141-
config,
142-
];
147+
});
148+
}
149+
}
150+
151+
// If the base config could form a global ignores object, then we mustn't include
152+
// it in the output. Otherwise, we must add it in order for it to have effect.
153+
if(!isPossiblyGlobalIgnores(config)){
154+
configArray.push(config);
155+
}
156+
157+
returnconfigArray;
143158
});
144159
}
160+
161+
/**
162+
* This utility function returns false if the config objects contains any field
163+
* that would prevent it from being considered a global ignores object and true
164+
* otherwise. Note in particular that the `ignores` field may not be present and
165+
* the return value can still be true.
166+
*/
167+
functionisPossiblyGlobalIgnores(config:object):boolean{
168+
returnObject.keys(config).every(key=>['name','ignores'].includes(key));
169+
}

‎packages/typescript-eslint/tests/config-helper.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,73 @@ describe('config helper', () => {
247247
{rules:{rule:'error'}},
248248
]);
249249
});
250+
251+
it('does not create global ignores in extends',()=>{
252+
constconfigWithIgnores=plugin.config({
253+
extends:[{rules:{rule1:'error'}},{rules:{rule2:'error'}}],
254+
ignores:['ignored'],
255+
});
256+
257+
expect(configWithIgnores).toEqual([
258+
{ignores:['ignored'],rules:{rule1:'error'}},
259+
{ignores:['ignored'],rules:{rule2:'error'}},
260+
]);
261+
expect(configWithIgnores).not.toContainEqual(
262+
// Should not create global ignores
263+
{ignores:['ignored']},
264+
);
265+
});
266+
267+
it('creates noop config in extends',()=>{
268+
constconfigWithMetadata=plugin.config({
269+
extends:[{rules:{rule1:'error'}},{rules:{rule2:'error'}}],
270+
files:['file'],
271+
ignores:['ignored'],
272+
name:'my-config',
273+
});
274+
275+
expect(configWithMetadata).toEqual([
276+
{
277+
files:['file'],
278+
ignores:['ignored'],
279+
name:'my-config',
280+
rules:{rule1:'error'},
281+
},
282+
{
283+
files:['file'],
284+
ignores:['ignored'],
285+
name:'my-config',
286+
rules:{rule2:'error'},
287+
},
288+
// it would also be ok for this not to be present, but we want to align
289+
// with the eslint `defineConfig()` behavior.
290+
{
291+
files:['file'],
292+
ignores:['ignored'],
293+
name:'my-config',
294+
},
295+
]);
296+
});
297+
298+
it('does not create global ignores when extending empty configs',()=>{
299+
expect(
300+
plugin.config({
301+
extends:[{rules:{rule1:'error'}},{}],
302+
ignores:['ignored'],
303+
}),
304+
).toEqual([
305+
{ignores:['ignored'],rules:{rule1:'error'}},
306+
// Should not create global ignores
307+
{},
308+
]);
309+
});
310+
311+
it('handles name field when global-ignoring in extension',()=>{
312+
expect(
313+
plugin.config({
314+
extends:[{ignores:['files/**/*'],name:'global-ignore-stuff'}],
315+
ignores:['ignored'],
316+
}),
317+
).toEqual([{ignores:['files/**/*'],name:'global-ignore-stuff'}]);
318+
});
250319
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp