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: allow references to external globals in id-blacklist (fixes #12567) #12987
Conversation
* Write access isn't allowed, because it potentially creates a new property with a blacklisted name. | ||
*/ | ||
if ( | ||
parent.type === "MemberExpression" && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe, Is this PR intended to ignoring check an identifier in an assignment that has no declaration?
I tested it and recognized it pass the blacklist identifier with assignment in destructuring.
This is the case which I tested.
({a: parseInt} = a); // no warning in this pr version.
// but it warns with the declaration.
var paseInt; ({a: parseInt} = a); // warning
And it is warned in v6.8.0 (no declaraion)
/*eslint id-blacklist: ["error", "parseInt"] */
({a: parseInt} = foo); // warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe, Is this PR intended to ignoring check an identifier in an assignment that has no declaration?
Only if it is a global variable that isn't declared in the same source code. The logic is: if it is declared, then we can assume it's a user-controlled name. Otherwise, it's a built-in/env- specific/third-party global so user can't change the name.
It could be also indeed a user-controlled name declared elsewhere, but in that case id-blacklist
will warn in the file where it is declared.
This shouldn't be a warning because parseInt
is a global variable that isn't declared in this code:
/*eslint id-blacklist: ["error", "parseInt"] */
({a: parseInt} = a);
This should be warning (2 warnings, one for each Identifier
node) because parseInt
is declared:
/*eslint id-blacklist: ["error", "parseInt"] */
var parseInt; ({a: parseInt} = a);
This should be also a warning because foo isn't defined in the configuration as a global variable:
/*eslint id-blacklist: ["error", "foo"] */
({a: foo} = a);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if it is a global variable that isn't declared in the same source code. The logic is: if it is declared, then we can assume it's a user-controlled name. Otherwise, it's a built-in/env- specific/third-party global so user can't change the name.
Thanks for the explanation. 👍 it makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Appreciate all the clear comments in the code and tests 👍
] | ||
}, | ||
{ | ||
code: "var foo = [Map];", // this actually isn't a disabled global: it was never enabled because es6 environment isn't enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[X] Bug fix
Fixes #12567
What changes did you make? (Give an overview)
id-blacklist
will now ignore identifiers that represent a reference to an external global variable:Global variables declared in the same source code will be still invalid:
Is there anything you'd like reviewers to focus on?
This will be still invalid although it is a reference to a global variable, because it also represents a property name: