From a9d92f991d69902a9150db373590e2ed54dec988 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Wed, 29 Jan 2020 18:58:59 +0100 Subject: [PATCH] Fix: radix rule crash on disabled globals (#12824) --- lib/rules/radix.js | 4 ++-- tests/lib/rules/radix.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/rules/radix.js b/lib/rules/radix.js index 2174e7d0339..d1503dba1a4 100644 --- a/lib/rules/radix.js +++ b/lib/rules/radix.js @@ -144,7 +144,7 @@ module.exports = { // Check `parseInt()` variable = astUtils.getVariableByName(scope, "parseInt"); - if (!isShadowed(variable)) { + if (variable && !isShadowed(variable)) { variable.references.forEach(reference => { const node = reference.identifier; @@ -156,7 +156,7 @@ module.exports = { // Check `Number.parseInt()` variable = astUtils.getVariableByName(scope, "Number"); - if (!isShadowed(variable)) { + if (variable && !isShadowed(variable)) { variable.references.forEach(reference => { const node = reference.identifier.parent; diff --git a/tests/lib/rules/radix.js b/tests/lib/rules/radix.js index 5e27c9c135b..6c0bed80a19 100644 --- a/tests/lib/rules/radix.js +++ b/tests/lib/rules/radix.js @@ -45,13 +45,15 @@ ruleTester.run("radix", rule, { "Number.foo();", "Number[parseInt]();", - // Ignores if it's shadowed. + // Ignores if it's shadowed or disabled. "var parseInt; parseInt();", { code: "var parseInt; parseInt(foo);", options: ["always"] }, { code: "var parseInt; parseInt(foo, 10);", options: ["as-needed"] }, "var Number; Number.parseInt();", { code: "var Number; Number.parseInt(foo);", options: ["always"] }, - { code: "var Number; Number.parseInt(foo, 10);", options: ["as-needed"] } + { code: "var Number; Number.parseInt(foo, 10);", options: ["as-needed"] }, + { code: "/* globals parseInt:off */ parseInt(foo);", options: ["always"] }, + { code: "Number.parseInt(foo, 10);", options: ["as-needed"], globals: { Number: "off" } } ], invalid: [