-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
New: no-global-assign
rule (fixes #5358)
#6395
Conversation
LGTM |
By analyzing the blame information on this pull request, we identified @nzakas, @scriptdaemon and @pedrottimark to be potential reviewers |
LGTM |
12db73d
to
ec75c9e
Compare
@@ -0,0 +1,47 @@ | |||
# Disallow assignments to readonly global variables (no-global-assign) | |||
|
|||
If people rewrite embedded global variables, it may cause severe problems. |
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.
I'd suggest something like:
JavaScript environments contain a number of built-in global variables, such as window
in browsers and process
in Node.js. In almost all cases, you don't want to assign a value to these global variables as doing so could result in losing access to important functionality. For example, you probably don't want to do this in browser code:
window = {};
While examples such as window
are obvious, there are often hundreds of built-in global objects provided by JavaScript environments. It can be hard to know if you're assigning to a global variable or not.
Code looks good, just some documentation things to clear up. |
Oooh, now I found that this rule has existed already -- no-native-reassign. I'll close this PR after someone double-check it. Then I will send a PR to update document. @nzakas Thank you for the correction! |
@mysticatea That rule seems to focus on reassignments- I'm not sure there is a rule to cover assignments of new global variables. Then again, I only glanced at the source and escope is one of my weak areas, so I can't tell for sure. But I thinking there is probably a need for this rule. |
@platinumazure Actually, the rule warns all modifications of read-only global variables. |
Yeah, I'm talking about new variables: MyObject = {}; That's not warned by no-native-reassign, is it?
|
@platinumazure Yeah, it's warned by |
Oh interesting! It looks like this rule actually does more than |
Both
I don't oppose renaming :) |
Oops, I missed that! I don't think renaming is a good idea -- it's a breaking change for no good reason. Should we close this? |
I don't know- I think it's confusing. "no-native-assign", to me, means you
|
@platinumazure it's obviously a bit confusing, hence why this PR exists. But is it really worth a breaking change? I don't think so, but this should be discussed on an issue, not a PR. |
Closing as I agree with @nzakas . |
Fixes #5358.
And I added a note into
docs/user-guide/configuring.md
.