Skip to content

Commit

Permalink
Add tests with overrideConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Oct 20, 2022
1 parent 475792f commit c259ab7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/fixtures/eslint.config_with_rules.js
@@ -0,0 +1,5 @@
module.exports = [{
rules: {
quotes: ["error", "single"]
}
}];
55 changes: 55 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -4751,6 +4751,61 @@ describe("FlatESLint", () => {
assert.strictEqual(messages.length, 0);
});

it("should be inserted before overrideConfig", async () => {
const eslint = new FlatESLint({
overrideConfigFile: true,
baseConfig: {
rules: {
semi: 2
}
},
overrideConfig: {
rules: {
semi: 1
}
}
});

const [{ messages }] = await eslint.lintText("foo");

assert.strictEqual(messages.length, 1);
assert.strictEqual(messages[0].ruleId, "semi");
assert.strictEqual(messages[0].severity, 1);
});

it("should be inserted before configs from the config file and overrideConfig", async () => {
const eslint = new FlatESLint({
overrideConfigFile: getFixturePath("eslint.config_with_rules.js"),
baseConfig: {
rules: {
quotes: ["error", "double"],
semi: "error"
}
},
overrideConfig: {
rules: {
quotes: "warn"
}
}
});

const [{ messages }] = await eslint.lintText('const foo = "bar"');

/*
* baseConfig: { quotes: ["error", "double"], semi: "error" }
* eslint.config_with_rules.js: { quotes: ["error", "single"] }
* overrideConfig: { quotes: "warn" }
*
* Merged config: { quotes: ["warn", "single"], semi: "error" }
*/

assert.strictEqual(messages.length, 2);
assert.strictEqual(messages[0].ruleId, "quotes");
assert.strictEqual(messages[0].severity, 1);
assert.strictEqual(messages[1].ruleId, "semi");
assert.strictEqual(messages[1].severity, 2);
});

it("when it has 'files' they should be intepreted as relative to the config file", async () => {

/*
Expand Down

0 comments on commit c259ab7

Please sign in to comment.