Skip to content

Commit

Permalink
Fix: radix rule crash on disabled globals (#12824)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Jan 29, 2020
1 parent 03a69db commit a9d92f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/rules/radix.js
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions tests/lib/rules/radix.js
Expand Up @@ -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: [
Expand Down

0 comments on commit a9d92f9

Please sign in to comment.