diff --git a/lib/cli-engine/config-array-factory.js b/lib/cli-engine/config-array-factory.js index 6d0992151ad..39f62bb6da1 100644 --- a/lib/cli-engine/config-array-factory.js +++ b/lib/cli-engine/config-array-factory.js @@ -722,7 +722,12 @@ class ConfigArrayFactory { * * Refer https://github.com/eslint/eslint/issues/12592 */ - const clonedRulesConfig = rules && JSON.parse(JSON.stringify((rules))); + 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)) { diff --git a/tests/fixtures/config-file/cloned-config/configWithInfinity.js b/tests/fixtures/config-file/cloned-config/configWithInfinity.js new file mode 100644 index 00000000000..73e3c93c085 --- /dev/null +++ b/tests/fixtures/config-file/cloned-config/configWithInfinity.js @@ -0,0 +1,6 @@ +module.exports = { + + rules: { + "max-len": [ "error", { code: Infinity }] + } +}; diff --git a/tests/lib/cli.js b/tests/lib/cli.js index afb225f1f7c..2f84900eefb 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -1172,9 +1172,7 @@ describe("cli", () => { assert.strictEqual(exit, 0); }); - }); - describe("config file and input file", () => { 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"); @@ -1187,6 +1185,16 @@ describe("cli", () => { } }); + + 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", () => {