Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Replace Infinity with Number.MAX_SAFE_INTEGER (fixes #13427) #13435

Merged
merged 1 commit into from Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/cli-engine/config-array-factory.js
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)
nzakas marked this conversation as resolved.
Show resolved Hide resolved
)
);

// Flatten `extends`.
for (const extendName of extendList.filter(Boolean)) {
Expand Down
@@ -0,0 +1,6 @@
module.exports = {

rules: {
"max-len": [ "error", { code: Infinity }]
}
};
12 changes: 10 additions & 2 deletions tests/lib/cli.js
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