-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Docs: Added note about Node/CJS scoping to no-redeclare (fixes #8814) #8820
Conversation
Thanks for the pull request, @platinumazure! I took a look to make sure it's ready for merging and found some changes are needed:
Can you please update the pull request to address these? (More information can be found in our pull request guide.) |
Thanks for the pull request, @platinumazure! I took a look to make sure it's ready for merging and found some changes are needed:
Can you please update the pull request to address these? (More information can be found in our pull request guide.) |
docs/rules/no-redeclare.md
Outdated
@@ -50,3 +52,9 @@ var top = 0; | |||
``` | |||
|
|||
The `browser` environment has many built-in global variables (for example, `top`). Some of built-in global variables cannot be redeclared. | |||
|
|||
Note that when using the `node` or `commonjs` environments (or `ecmaFeatures.globalReturn`, if using the default parser), the top scope of a program is not actually the global scope, but rather a "module" scope. When this is the case, declaring a variable named after a builtin global is not a redeclaration, but rather a shadowing of the global variable. In that case, the `no-shadow` rule with the `"builtinGlobals"` option should be used. |
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.
Nitpick: Would it be worth linking to the no-shadow
rule in the last sentence?
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.
Yes, I think so. I'll push a new commit, thanks.
Thanks for the pull request, @platinumazure! I took a look to make sure it's ready for merging and found some changes are needed:
Can you please update the pull request to address these? (More information can be found in our pull request guide.) |
What is the purpose of this pull request? (put an "X" next to item)
[x] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
See #8814 (but scroll down a bit).
What changes did you make? (Give an overview)
Added a note to
no-redeclare
docs explaining that Node/CommonJS module scoping means "global variables" are not actually global, so the "builtinGlobals" option will not work as expected. The note also recommends the use ofno-shadow
in that case, which would hopefully satisfy users' needs in those cases.Is there anything you'd like reviewers to focus on?
Is the new paragraph clear? Could it be improved?