Skip to content

Commit de77c11

Browse files
authored
Fix: Replace Infinity with Number.MAX_SAFE_INTEGER (fixes #13427) (#13435)
1 parent b7d79b1 commit de77c11

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,12 @@ class ConfigArrayFactory {
722722
*
723723
* Refer https://github.com/eslint/eslint/issues/12592
724724
*/
725-
const clonedRulesConfig = rules && JSON.parse(JSON.stringify((rules)));
725+
const clonedRulesConfig = rules && JSON.parse(
726+
JSON.stringify(
727+
rules,
728+
(key, value) => (value === Infinity ? Number.MAX_SAFE_INTEGER : value)
729+
)
730+
);
726731

727732
// Flatten `extends`.
728733
for (const extendName of extendList.filter(Boolean)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
3+
rules: {
4+
"max-len": [ "error", { code: Infinity }]
5+
}
6+
};

tests/lib/cli.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,7 @@ describe("cli", () => {
11721172

11731173
assert.strictEqual(exit, 0);
11741174
});
1175-
});
11761175

1177-
describe("config file and input file", () => {
11781176
it("should exit with 1 as camelcase has wrong property type", async () => {
11791177
const configPath = getFixturePath("config-file", "cloned-config", "eslintConfigFail.js");
11801178
const filePath = getFixturePath("config-file", "cloned-config", "index.js");
@@ -1187,6 +1185,16 @@ describe("cli", () => {
11871185
}
11881186

11891187
});
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+
});
11901198
});
11911199

11921200
describe("inline config and input file", () => {

0 commit comments

Comments
 (0)