Skip to content

Commit 89ee01e

Browse files
authored
Fix: Revert config cloning (fixes #13447) (#13449)
* Revert "Fix: Replace Infinity with Number.MAX_SAFE_INTEGER (fixes #13427) (#13435)" This reverts commit de77c11. * Revert "Fix: clone config before validating (fixes #12592) (#13034)" This reverts commit 7fb45cf.
1 parent 0a463db commit 89ee01e

File tree

8 files changed

+1
-138
lines changed

8 files changed

+1
-138
lines changed

lib/cli-engine/config-array-factory.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -697,38 +697,6 @@ class ConfigArrayFactory {
697697
ctx.matchBasePath
698698
);
699699

700-
/**
701-
* Cloning the rule's config as we are setting `useDefaults` to true`
702-
* which mutates the config with its default value if present. And when we
703-
* refer to a same variable for config for different rules, that referred variable will
704-
* be mutated and it will be used for both.
705-
*
706-
* Example:
707-
*
708-
* const commonRuleConfig = ['error', {}];
709-
*
710-
* Now if we use this variable as a config for rules like this
711-
*
712-
* {
713-
* rules: {
714-
* "a" : commonRuleConfig,
715-
* "b" : commonRuleConfig,
716-
* }
717-
* }
718-
*
719-
* And if these rules have default values in their schema, their
720-
* config will be mutated with default values, the mutated `commonRuleConfig` will be used for `b` as well and it probably
721-
* throw schema voilation errors.
722-
*
723-
* Refer https://github.com/eslint/eslint/issues/12592
724-
*/
725-
const clonedRulesConfig = rules && JSON.parse(
726-
JSON.stringify(
727-
rules,
728-
(key, value) => (value === Infinity ? Number.MAX_SAFE_INTEGER : value)
729-
)
730-
);
731-
732700
// Flatten `extends`.
733701
for (const extendName of extendList.filter(Boolean)) {
734702
yield* this._loadExtends(extendName, ctx);
@@ -763,7 +731,7 @@ class ConfigArrayFactory {
763731
processor,
764732
reportUnusedDisableDirectives,
765733
root,
766-
rules: clonedRulesConfig,
734+
rules,
767735
settings
768736
};
769737

tests/fixtures/config-file/cloned-config/circularRefEslintConfig.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/fixtures/config-file/cloned-config/configWithInfinity.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/fixtures/config-file/cloned-config/eslintConfig.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/fixtures/config-file/cloned-config/eslintConfigFail.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/fixtures/config-file/cloned-config/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/fixtures/config-file/cloned-config/inlineText.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/lib/cli.js

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ describe("cli", () => {
187187
});
188188
});
189189

190-
191190
describe("when given a config with environment set to Node.js", () => {
192191
it("should execute without any errors", async () => {
193192
const configPath = getFixturePath("configurations", "env-node.json");
@@ -1161,66 +1160,4 @@ describe("cli", () => {
11611160
});
11621161
});
11631162

1164-
describe("testing the cloned config", () => {
1165-
describe("config file and input file", () => {
1166-
it("should not modify original configuration object", async () => {
1167-
const configPath = getFixturePath("config-file", "cloned-config", "eslintConfig.js");
1168-
const filePath = getFixturePath("config-file", "cloned-config", "index.js");
1169-
const args = `--config ${configPath} ${filePath}`;
1170-
1171-
const exit = await cli.execute(args);
1172-
1173-
assert.strictEqual(exit, 0);
1174-
});
1175-
1176-
it("should exit with 1 as camelcase has wrong property type", async () => {
1177-
const configPath = getFixturePath("config-file", "cloned-config", "eslintConfigFail.js");
1178-
const filePath = getFixturePath("config-file", "cloned-config", "index.js");
1179-
const args = `--config ${configPath} ${filePath}`;
1180-
1181-
try {
1182-
await cli.execute(args);
1183-
} catch (error) {
1184-
assert.strictEqual(/Configuration for rule "camelcase" is invalid:/u.test(error), true);
1185-
}
1186-
1187-
});
1188-
1189-
it("should not cause an error when a rule configuration has `Infinity`", async () => {
1190-
const configPath = getFixturePath("config-file", "cloned-config", "configWithInfinity.js");
1191-
const filePath = getFixturePath("config-file", "cloned-config", "index.js");
1192-
const args = `--config ${configPath} ${filePath}`;
1193-
1194-
const exit = await cli.execute(args);
1195-
1196-
assert.strictEqual(exit, 0);
1197-
});
1198-
});
1199-
1200-
describe("inline config and input file", () => {
1201-
it("should not modify original configuration object", async () => {
1202-
const filePath = getFixturePath("config-file", "cloned-config", "inlineText.js");
1203-
const args = `${filePath}`;
1204-
1205-
const exit = await cli.execute(args);
1206-
1207-
assert.strictEqual(exit, 0);
1208-
});
1209-
});
1210-
1211-
});
1212-
1213-
describe("handling circular reference while cloning", () => {
1214-
it("should handle circular ref", async () => {
1215-
const configPath = getFixturePath("config-file", "cloned-config", "circularRefEslintConfig.js");
1216-
const filePath = getFixturePath("config-file", "cloned-config", "index.js");
1217-
const args = `--config ${configPath} ${filePath}`;
1218-
1219-
try {
1220-
await cli.execute(args);
1221-
} catch (error) {
1222-
assert.instanceOf(error, Error);
1223-
}
1224-
});
1225-
});
12261163
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy