Skip to content

Commit

Permalink
Fix: Replace Infinity with Number.MAX_SAFE_INTEGER (fixes #13427) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas authored Jun 23, 2020
1 parent b7d79b1 commit de77c11
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/cli-engine/config-array-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {

rules: {
"max-len": [ "error", { code: Infinity }]
}
};
12 changes: 10 additions & 2 deletions tests/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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", () => {
Expand Down

0 comments on commit de77c11

Please sign in to comment.