From b757bd8d6910dc1b75f014eaec1f2d36fa38cf4d Mon Sep 17 00:00:00 2001 From: Anix Date: Fri, 24 Apr 2020 08:45:16 +0000 Subject: [PATCH] Fix: clone config data before validation (fixes #12592) --- lib/cli-engine/config-array-factory.js | 4 +++- tests/lib/rules/camelcase.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/cli-engine/config-array-factory.js b/lib/cli-engine/config-array-factory.js index 997a7e15318..74a8319217a 100644 --- a/lib/cli-engine/config-array-factory.js +++ b/lib/cli-engine/config-array-factory.js @@ -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"); @@ -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); } diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index 21f280adb35..80dbe183c9d 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -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: [ @@ -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" + }] } ] });