Skip to content

Commit

Permalink
Fix: throw an error when disable a non-existent rule (fixes eslint#9505)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jul 5, 2018
1 parent 704bcb0 commit 4cbbf5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/config/config-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ function validateRuleSchema(rule, localOptions) {
*/
function validateRuleOptions(rule, ruleId, options, source) {
if (!rule) {
return;
throw new Error(`Definition for rule '${ruleId}' was not found.`);
}

try {
const severity = validateRuleSeverity(options);

Expand Down
6 changes: 6 additions & 0 deletions tests/lib/config/config-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ describe("Validator", () => {
validator.validate({ rules: { "mock-rule": ["Error", "second"] } }, "tests", ruleMapper, linter.environments);
});

it("should throw an error when the rule does not exist", () => {
const fn = validator.validate.bind(null, { rules: { "non-exsistent-rule": "off" } }, "tests", ruleMapper, linter.environments);

assert.throws(fn, "Definition for rule 'non-exsistent-rule' was not found.");
});

it("should catch invalid rule options", () => {
const fn = validator.validate.bind(null, { rules: { "mock-rule": [3, "third"] } }, "tests", ruleMapper, linter.environments);

Expand Down

0 comments on commit 4cbbf5c

Please sign in to comment.