Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: OverrideTester basePath (fixes #12032) #12205

Merged
merged 1 commit into from Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cli-engine/config-array/override-tester.js
Expand Up @@ -125,10 +125,10 @@ class OverrideTester {
*/
static and(a, b) {
if (!b) {
return a;
return a && new OverrideTester(a.patterns, a.basePath);
}
if (!a) {
return b;
return new OverrideTester(b.patterns, b.basePath);
}

assert.strictEqual(a.basePath, b.basePath);
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/cli-engine/cli-engine.js
Expand Up @@ -3592,6 +3592,36 @@ describe("CLIEngine", () => {
});
});
});

describe("with 'overrides[*].extends' setting on deep locations", () => {
const root = getFixturePath("cli-engine/deeply-overrides-i-extends");

it("should not throw.", () => {
CLIEngine = defineCLIEngineWithInMemoryFileSystem({
cwd: () => root,
files: {
"node_modules/eslint-config-one/index.js": `module.exports = ${JSON.stringify({
overrides: [{ files: ["*test*"], extends: "two" }]
})}`,
"node_modules/eslint-config-two/index.js": `module.exports = ${JSON.stringify({
overrides: [{ files: ["*.js"], extends: "three" }]
})}`,
"node_modules/eslint-config-three/index.js": `module.exports = ${JSON.stringify({
rules: { "no-console": "error" }
})}`,
"test.js": "console.log('hello')",
".eslintrc.yml": "extends: one"
}
}).CLIEngine;
engine = new CLIEngine();

const { results } = engine.executeOnFiles(["test.js"]);
const messages = results[0].messages;

assert.strictEqual(messages.length, 1);
assert.strictEqual(messages[0].ruleId, "no-console");
});
});
});

describe("getConfigForFile", () => {
Expand Down
18 changes: 12 additions & 6 deletions tests/lib/cli-engine/config-array/override-tester.js
Expand Up @@ -58,16 +58,22 @@ describe("OverrideTester", () => {
assert.strictEqual(OverrideTester.and(null, null), null);
});

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

assert.strictEqual(OverrideTester.and(tester, null), tester);
assert.notStrictEqual(result, tester);
assert.strictEqual(result.patterns, tester.patterns);
assert.strictEqual(result.basePath, tester.basePath);
});

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

assert.strictEqual(OverrideTester.and(null, tester), tester);
assert.notStrictEqual(result, tester);
assert.strictEqual(result.patterns, tester.patterns);
assert.strictEqual(result.basePath, tester.basePath);
});

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