Skip to content

Commit

Permalink
Fix: clone config data before validation (fixes #12592)
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Apr 24, 2020
1 parent 0243549 commit b757bd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/cli-engine/config-array-factory.js
Expand Up @@ -43,6 +43,7 @@ const fs = require("fs");
const path = require("path");
const importFresh = require("import-fresh");
const stripComments = require("strip-json-comments");
const lodash = require("lodash");
const { validateConfigSchema } = require("../shared/config-validator");
const naming = require("../shared/naming");
const ModuleResolver = require("../shared/relative-module-resolver");
Expand Down Expand Up @@ -593,8 +594,9 @@ class ConfigArrayFactory {
? path.resolve(cwd, providedFilePath)
: "";
const name = providedName || (filePath && path.relative(cwd, filePath));
const clonedConfig = lodash.cloneDeep(configData);

validateConfigSchema(configData, name || filePath);
validateConfigSchema(clonedConfig, name || filePath);

return this._normalizeObjectConfigData(configData, filePath, name);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/camelcase.js
Expand Up @@ -225,6 +225,10 @@ ruleTester.run("camelcase", rule, {
code: "foo = { [computedBar]: 0 };",
options: [{ ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "var obj = { mem_var: 1 };",
options: [{ properties: "never" }]
}
],
invalid: [
Expand Down Expand Up @@ -736,6 +740,25 @@ ruleTester.run("camelcase", rule, {
type: "Identifier"
}
]
},
{
code: "const {mem_var = 1} = obh",
options: [{ ignoreDestructuring: false }],
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "notCamelCase",
data: { name: "mem_var" },
type: "Identifier"
}]
},
{
code: "var obj = { mem_var: 1 };",
options: [{}],
errors: [{
messageId: "notCamelCase",
data: { name: "mem_var" },
type: "Identifier"
}]
}
]
});

0 comments on commit b757bd8

Please sign in to comment.