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 Apr 1, 2018
1 parent d0dc2e3 commit b84797d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/config/config-validator.js
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/config/config-validator.js
Expand Up @@ -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);

Expand Down

0 comments on commit b84797d

Please sign in to comment.