Skip to content
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

Closed
dryajov opened this issue Feb 21, 2017 · 9 comments · Fixed by #737
Closed

Need a way of preventing window being used instead of self #107

dryajov opened this issue Feb 21, 2017 · 9 comments · Fixed by #737
Assignees
Labels
aegir.next P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked

Comments

@dryajov
Copy link
Member

dryajov commented Feb 21, 2017

Add eslint rule/plugin to check for self vs window.

@dryajov dryajov changed the title Need a way of checking for preventing window being used instead of self Need a way of preventing window being used instead of self Feb 21, 2017
@dignifiedquire
Copy link
Member

Is there a rule for this? And how would this be able to differentiate between needed use for window and false usage?

@dryajov
Copy link
Member Author

dryajov commented Mar 8, 2017

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.

@dignifiedquire
Copy link
Member

It might be a case where we want to make the rule just a warning rather than error

@dryajov
Copy link
Member Author

dryajov commented Mar 8, 2017

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:

@daviddias daviddias added the status/deferred Conscious decision to pause or backlog label Mar 10, 2017
@platinumazure
Copy link

Saw this come up in ESLint's Gitter chat. Maybe I'm missing something, but maybe no-restricted-globals would work for your use case? Unfortunately you can't customize the error message, but you should be able to use it to generate warnings when someone uses window.

@dryajov
Copy link
Member Author

dryajov commented Mar 10, 2017

Here is a proposal for eslint to add this as a rule - eslint/eslint#8229.

@dryajov
Copy link
Member Author

dryajov commented Mar 10, 2017

@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 no-restricted-globals can be customized to provide such a message that would be ideal, but after a quick glance, it doesn't seem that that's possible.

@daviddias daviddias added status/ready Ready to be worked and removed status/deferred Conscious decision to pause or backlog labels Apr 5, 2017
@daviddias
Copy link
Member

@dryajov seems that to move this forward, an example is needed - eslint/eslint#8315 (comment)

@daviddias daviddias added status/deferred Conscious decision to pause or backlog and removed status/ready Ready to be worked labels Jun 20, 2017
@daviddias daviddias added status/ready Ready to be worked P2 Medium: Good to have, but can wait until someone steps up and removed status/deferred Conscious decision to pause or backlog labels Oct 13, 2017
@victorb
Copy link
Member

victorb commented Oct 1, 2018

eslint/eslint#8315 has been merged, and seems we're only missing a addition to our config for this to be done. PRs welcome! 🤙

@hugomrdias hugomrdias mentioned this issue Feb 23, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aegir.next P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants