Skip to content

Commit

Permalink
Fix: clone config before validation (fixes #12592)
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Mar 25, 2020
1 parent 0243549 commit aad0f64
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/linter/linter.js
Expand Up @@ -393,7 +393,9 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
}

try {
validator.validateRuleOptions(rule, name, ruleValue);
const cloneRuleValue = lodash.cloneDeep(ruleValue);

validator.validateRuleOptions(rule, name, cloneRuleValue);
} catch (err) {
problems.push(createLintingProblem({
ruleId: name,
Expand Down Expand Up @@ -584,10 +586,17 @@ function stripUnicodeBOM(text) {
/**
* Get the options for a rule (not including severity), if any
* @param {Array|number} ruleConfig rule configuration
* @param {string} ruleId rule id
* @param {Object} rule rule schema
* @returns {Array} of rule options, empty Array if none
*/
function getRuleOptions(ruleConfig) {
function getRuleOptions(ruleConfig, ruleId = "", rule = {}) {
if (Array.isArray(ruleConfig)) {
if (ruleId !== "" && Object.keys(rule) !== 0) {
const cloneRuleValue = lodash.cloneDeep(ruleConfig);

validator.validateRuleOptions(rule, ruleId, cloneRuleValue);
}
return ruleConfig.slice(1);
}
return [];
Expand Down Expand Up @@ -892,7 +901,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
Object.create(sharedTraversalContext),
{
id: ruleId,
options: getRuleOptions(configuredRules[ruleId]),
options: getRuleOptions(configuredRules[ruleId], ruleId, ruleMapper(ruleId)),
report(...args) {

/*
Expand Down

0 comments on commit aad0f64

Please sign in to comment.