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: [