-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Rule proposal: No assignment to global object #144
Comments
Related rule https://eslint.org/docs/rules/no-global-assign. But not sure if it blocks my example. On mobile so can't check. |
@SamVerschueren Can you check? |
When the The rule won't report for adding to global properties as in the original post. See https://runkit.com/brettz9/5e36777bfa499e001b98ecb4 . |
Particularly in the age of ES modules, this sounds like a great rule. Even a rule to prevent reading from the global object (besides whitelisted properties) would be great (including for checking imported code, as a kind of privilege checker). |
I agree, this could be useful. It should prevent setting properties on |
I don't see how that's feasible in a browser environment. Pretty much everything are globals. |
// @fisker Thoughts on this rule? |
How do we do with setting Should |
We should only disallow setting nonexistent properties. |
|
By I guess, |
@sindresorhus : If you mean that users need to access their own variables, besides the case of ESM where users don't need to access globals for such functionality, users can add their globals to If you mean that the HTML APIs are globals, yes, but I had been thinking the rule could allow permitting certain globals (e.g., a While one can disable |
Yes, we can document that in the rule docs. |
Yes, this is what I meant. |
I feel like this would be better as just an option to https://eslint.org/docs/rules/no-implicit-globals to prevent assigning to known globals. |
Someone please open an issue on ESLint about this and link it here. If they decline it, we can consider adding it here. |
Recently someone did a PR where he put something on the
global
object. Something likeThis doesn't feel like a good thing to do. You might accidentally override something. Also it makes it very hard to track where the global variable was set. I don't believe I actually ever used the
global
keyword in my code.It's the same thing for
window
in browser environments.Just wanted to bring up the discussion as I might be wrong though. If not, should we forbid the use of global entirely? Or only setting values?
The text was updated successfully, but these errors were encountered: