From b84797d701b0acd97994504abcd6a692ba91b990 Mon Sep 17 00:00:00 2001 From: "weiran.zsd" Date: Mon, 2 Apr 2018 05:17:52 +0800 Subject: [PATCH] Fix: throw an error when disable a non-existent rule (fixes #9505) --- lib/config/config-validator.js | 2 +- tests/lib/config/config-validator.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/config/config-validator.js b/lib/config/config-validator.js index 1a5b3ef13e03..d45ff5b7b36a 100644 --- a/lib/config/config-validator.js +++ b/lib/config/config-validator.js @@ -104,7 +104,7 @@ 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 5d6cf8cc0d2e..ded895371ffb 100644 --- a/tests/lib/config/config-validator.js +++ b/tests/lib/config/config-validator.js @@ -306,6 +306,12 @@ describe("Validator", () => { assert.doesNotThrow(fn); }); + 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 do nothing with an invalid config when severity is an array with 'off'", () => { const fn = validator.validate.bind(null, { rules: { "mock-required-options-rule": ["off"] } }, "tests", ruleMapper, linter.environments);