Skip to content

Commit 21eb904

Browse files
authored
Fix: basePath of OverrideTester (fixes #12032) (#12205)
1 parent 86e5e65 commit 21eb904

3 files changed

Lines changed: 44 additions & 8 deletions

File tree

‎lib/cli-engine/config-array/override-tester.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ class OverrideTester {
125125
*/
126126
static and(a, b) {
127127
if (!b) {
128-
return a;
128+
return a && new OverrideTester(a.patterns, a.basePath);
129129
}
130130
if (!a) {
131-
return b;
131+
return new OverrideTester(b.patterns, b.basePath);
132132
}
133133

134134
assert.strictEqual(a.basePath, b.basePath);

‎tests/lib/cli-engine/cli-engine.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,36 @@ describe("CLIEngine", () => {
35923592
});
35933593
});
35943594
});
3595+
3596+
describe("with 'overrides[*].extends' setting on deep locations", () => {
3597+
const root = getFixturePath("cli-engine/deeply-overrides-i-extends");
3598+
3599+
it("should not throw.", () => {
3600+
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
3601+
cwd: () => root,
3602+
files: {
3603+
"node_modules/eslint-config-one/index.js": `module.exports = ${JSON.stringify({
3604+
overrides: [{ files: ["*test*"], extends: "two" }]
3605+
})}`,
3606+
"node_modules/eslint-config-two/index.js": `module.exports = ${JSON.stringify({
3607+
overrides: [{ files: ["*.js"], extends: "three" }]
3608+
})}`,
3609+
"node_modules/eslint-config-three/index.js": `module.exports = ${JSON.stringify({
3610+
rules: { "no-console": "error" }
3611+
})}`,
3612+
"test.js": "console.log('hello')",
3613+
".eslintrc.yml": "extends: one"
3614+
}
3615+
}).CLIEngine;
3616+
engine = new CLIEngine();
3617+
3618+
const { results } = engine.executeOnFiles(["test.js"]);
3619+
const messages = results[0].messages;
3620+
3621+
assert.strictEqual(messages.length, 1);
3622+
assert.strictEqual(messages[0].ruleId, "no-console");
3623+
});
3624+
});
35953625
});
35963626

35973627
describe("getConfigForFile", () => {

‎tests/lib/cli-engine/config-array/override-tester.js‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,22 @@ describe("OverrideTester", () => {
5858
assert.strictEqual(OverrideTester.and(null, null), null);
5959
});
6060

61-
it("should return the first one if the second one was null.", () => {
62-
const tester = OverrideTester.create("*.js");
61+
it("should return a new tester with the the first one's properties if the second one was null.", () => {
62+
const tester = OverrideTester.create("*.js", null, process.cwd());
63+
const result = OverrideTester.and(tester, null);
6364

64-
assert.strictEqual(OverrideTester.and(tester, null), tester);
65+
assert.notStrictEqual(result, tester);
66+
assert.strictEqual(result.patterns, tester.patterns);
67+
assert.strictEqual(result.basePath, tester.basePath);
6568
});
6669

67-
it("should return the second one if the first one was null.", () => {
68-
const tester = OverrideTester.create("*.js");
70+
it("should return a new tester with the the second one's properties if the first one was null.", () => {
71+
const tester = OverrideTester.create("*.js", null, process.cwd());
72+
const result = OverrideTester.and(null, tester);
6973

70-
assert.strictEqual(OverrideTester.and(null, tester), tester);
74+
assert.notStrictEqual(result, tester);
75+
assert.strictEqual(result.patterns, tester.patterns);
76+
assert.strictEqual(result.basePath, tester.basePath);
7177
});
7278

7379
it("should return another one what includes both patterns if both are testers.", () => {

0 commit comments

Comments
 (0)