-
Notifications
You must be signed in to change notification settings - Fork 59
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
Need a way of preventing window
being used instead of self
#107
Comments
window
being used instead of self
window
being used instead of self
Is there a rule for this? And how would this be able to differentiate between needed use for |
Not currently, but I was planning on writing an eslint plugin for it. As for self vs window, self should be preferred everywhere since it's a lot more portable, if window is needed explicitly the rule can be disabled on a line/file level. In general tho, it's probably safe to just check for specific features rather than for the existence of window itself. But again, being able to disable the rule should work in all remaining cases. |
It might be a case where we want to make the rule just a warning rather than error |
I kinda like the idea of ditching window for self across the board. I might be missing something but, IMHO if self is a more portable way of referencing global context then why not rely on it? I'm talking in a more general sense here, since most (all as far as I can tell) IPFS codebase has been ported to using self now. What would be the reasoning for not preferring it over window, maybe @kumavis, @diasdavid and @haadcode can weigh in on this one. I'd also love to hear thoughts from @Gozala, @nolanlawson, @substack, @nzakas and anyone that might help shedding some light on this. IMHO, if self is a more portable way of referencing global context in general, then we should promote it everywhere else, and I bet that lots of code could be easily made more portable by just enforcing this one thing. To give some background, when adding support for WebWorkers in IPFS, it became apparent that self is a more portable global context reference than window, it is available in both WebWorkers/ServiceWorkers as well as in the DOM enabled environments. Here are the related discussions/PRs: |
Saw this come up in ESLint's Gitter chat. Maybe I'm missing something, but maybe |
Here is a proposal for eslint to add this as a rule - eslint/eslint#8229. |
@platinumazure Thanks for bring this up! This would be a great intermediate solution, and perhaps it could be improved/customized to do what I'm proposing. However, the spirit of this rule is to make sure that this sets in as a best practice across the community, for the reasons I mentioned here and in the rule proposal, and for that a clear message suggesting the correct alternative is essential. If |
@dryajov seems that to move this forward, an example is needed - eslint/eslint#8315 (comment) |
eslint/eslint#8315 has been merged, and seems we're only missing a addition to our config for this to be done. PRs welcome! 🤙 |
Add eslint rule/plugin to check for
self
vswindow
.The text was updated successfully, but these errors were encountered: