diff --git a/lib/cli-engine/config-array-factory.js b/lib/cli-engine/config-array-factory.js index 39f62bb6da1..7c0fba65c67 100644 --- a/lib/cli-engine/config-array-factory.js +++ b/lib/cli-engine/config-array-factory.js @@ -697,38 +697,6 @@ class ConfigArrayFactory { ctx.matchBasePath ); - /** - * Cloning the rule's config as we are setting `useDefaults` to true` - * which mutates the config with its default value if present. And when we - * refer to a same variable for config for different rules, that referred variable will - * be mutated and it will be used for both. - * - * Example: - * - * const commonRuleConfig = ['error', {}]; - * - * Now if we use this variable as a config for rules like this - * - * { - * rules: { - * "a" : commonRuleConfig, - * "b" : commonRuleConfig, - * } - * } - * - * And if these rules have default values in their schema, their - * config will be mutated with default values, the mutated `commonRuleConfig` will be used for `b` as well and it probably - * throw schema voilation errors. - * - * Refer https://github.com/eslint/eslint/issues/12592 - */ - const clonedRulesConfig = rules && JSON.parse( - JSON.stringify( - rules, - (key, value) => (value === Infinity ? Number.MAX_SAFE_INTEGER : value) - ) - ); - // Flatten `extends`. for (const extendName of extendList.filter(Boolean)) { yield* this._loadExtends(extendName, ctx); @@ -763,7 +731,7 @@ class ConfigArrayFactory { processor, reportUnusedDisableDirectives, root, - rules: clonedRulesConfig, + rules, settings }; diff --git a/tests/fixtures/config-file/cloned-config/circularRefEslintConfig.js b/tests/fixtures/config-file/cloned-config/circularRefEslintConfig.js deleted file mode 100644 index cc9fcdbcc7c..00000000000 --- a/tests/fixtures/config-file/cloned-config/circularRefEslintConfig.js +++ /dev/null @@ -1,15 +0,0 @@ -let errorConfig = ["error", {}]; - -class CircularRef { - constructor() { - this.self = this; - } -} - -module.exports = { - settings: { - sharedData: new CircularRef() - }, - - rules: { camelcase: errorConfig, "default-case": errorConfig } -}; diff --git a/tests/fixtures/config-file/cloned-config/configWithInfinity.js b/tests/fixtures/config-file/cloned-config/configWithInfinity.js deleted file mode 100644 index 73e3c93c085..00000000000 --- a/tests/fixtures/config-file/cloned-config/configWithInfinity.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - - rules: { - "max-len": [ "error", { code: Infinity }] - } -}; diff --git a/tests/fixtures/config-file/cloned-config/eslintConfig.js b/tests/fixtures/config-file/cloned-config/eslintConfig.js deleted file mode 100644 index 8602e60b0fd..00000000000 --- a/tests/fixtures/config-file/cloned-config/eslintConfig.js +++ /dev/null @@ -1,4 +0,0 @@ -let errorConfig = ["error", {}]; -module.exports = { - rules: { camelcase: errorConfig, "default-case": errorConfig } -}; diff --git a/tests/fixtures/config-file/cloned-config/eslintConfigFail.js b/tests/fixtures/config-file/cloned-config/eslintConfigFail.js deleted file mode 100644 index b8702c6ffb8..00000000000 --- a/tests/fixtures/config-file/cloned-config/eslintConfigFail.js +++ /dev/null @@ -1,13 +0,0 @@ -let errorConfig = ["error", {}]; -module.exports = { - rules: { - camelcase: errorConfig, - "default-case": errorConfig , - "camelcase" : [ - 'error', - { - "ignoreDestructuring": new Date().getUTCFullYear // returns a function - } - ] - } -}; diff --git a/tests/fixtures/config-file/cloned-config/index.js b/tests/fixtures/config-file/cloned-config/index.js deleted file mode 100644 index b792f78cad3..00000000000 --- a/tests/fixtures/config-file/cloned-config/index.js +++ /dev/null @@ -1 +0,0 @@ -var someValue = "bar"; diff --git a/tests/fixtures/config-file/cloned-config/inlineText.js b/tests/fixtures/config-file/cloned-config/inlineText.js deleted file mode 100644 index e000713abaf..00000000000 --- a/tests/fixtures/config-file/cloned-config/inlineText.js +++ /dev/null @@ -1,3 +0,0 @@ -/*eslint default-case: ["error", {}]*/ -/*eslint camelcase: ["error", {}]*/ -var someValue = "bar"; diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 2f84900eefb..a1d9a23e491 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -187,7 +187,6 @@ describe("cli", () => { }); }); - describe("when given a config with environment set to Node.js", () => { it("should execute without any errors", async () => { const configPath = getFixturePath("configurations", "env-node.json"); @@ -1161,66 +1160,4 @@ describe("cli", () => { }); }); - describe("testing the cloned config", () => { - describe("config file and input file", () => { - it("should not modify original configuration object", async () => { - const configPath = getFixturePath("config-file", "cloned-config", "eslintConfig.js"); - const filePath = getFixturePath("config-file", "cloned-config", "index.js"); - const args = `--config ${configPath} ${filePath}`; - - const exit = await cli.execute(args); - - assert.strictEqual(exit, 0); - }); - - it("should exit with 1 as camelcase has wrong property type", async () => { - const configPath = getFixturePath("config-file", "cloned-config", "eslintConfigFail.js"); - const filePath = getFixturePath("config-file", "cloned-config", "index.js"); - const args = `--config ${configPath} ${filePath}`; - - try { - await cli.execute(args); - } catch (error) { - assert.strictEqual(/Configuration for rule "camelcase" is invalid:/u.test(error), true); - } - - }); - - it("should not cause an error when a rule configuration has `Infinity`", async () => { - const configPath = getFixturePath("config-file", "cloned-config", "configWithInfinity.js"); - const filePath = getFixturePath("config-file", "cloned-config", "index.js"); - const args = `--config ${configPath} ${filePath}`; - - const exit = await cli.execute(args); - - assert.strictEqual(exit, 0); - }); - }); - - describe("inline config and input file", () => { - it("should not modify original configuration object", async () => { - const filePath = getFixturePath("config-file", "cloned-config", "inlineText.js"); - const args = `${filePath}`; - - const exit = await cli.execute(args); - - assert.strictEqual(exit, 0); - }); - }); - - }); - - describe("handling circular reference while cloning", () => { - it("should handle circular ref", async () => { - const configPath = getFixturePath("config-file", "cloned-config", "circularRefEslintConfig.js"); - const filePath = getFixturePath("config-file", "cloned-config", "index.js"); - const args = `--config ${configPath} ${filePath}`; - - try { - await cli.execute(args); - } catch (error) { - assert.instanceOf(error, Error); - } - }); - }); });