diff --git a/lib/config/config-validator.js b/lib/config/config-validator.js index 6b151f46a496..5262cbbc9ee8 100644 --- a/lib/config/config-validator.js +++ b/lib/config/config-validator.js @@ -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); diff --git a/tests/lib/config/config-validator.js b/tests/lib/config/config-validator.js index 456b1518364e..5b01c4b827db 100644 --- a/tests/lib/config/config-validator.js +++ b/tests/lib/config/config-validator.js @@ -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);