Comments (9)
Is there a rule for this? And how would this be able to differentiate between needed use for window
and false usage?
from aegir.
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.
from aegir.
It might be a case where we want to make the rule just a warning rather than error
from aegir.
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:
from aegir.
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
.
from aegir.
Here is a proposal for eslint to add this as a rule - eslint/eslint#8229.
from aegir.
@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.
from aegir.
@dryajov seems that to move this forward, an example is needed - eslint/eslint#8315 (comment)
from aegir.
eslint/eslint#8315 has been merged, and seems we're only missing a addition to our config for this to be done. PRs welcome! 🤙
from aegir.
Related Issues (20)
- Docs: Fix retrieval of entry points from consumer's `tsconfig.json`
- Docs: Add support for linting typescript snippets in Markdown
- Docs: Add support for generating docs for internal referenced types
- bug: ESM_UNSUPPORTED_ESM_URL_SCHEME for `-t browser` in windows HOT 5
- Generate a markdown table of ecosystem module versions
- docs: LICENSE-APACHE isn't recognized by github HOT 1
- Coverage in aegir + node hangs on CI and Local Dev HOT 4
- Ignore Protons in `dep-check` HOT 2
- Support typedoc-plugin-resolve-crossmodule-reference
- Deno as a test target
- 'yarn install' does not install all dependencies HOT 1
- Generate tsconfig for doc-check
- Do not automate addition of engines field to all modules
- Add "prepare" as alias to "build" by default
- Improving Aegir test speed HOT 2
- Add @packageDocumentation to readme
- docs: Run `dep-check` on TS snippet imports
- docs: Run `lint` on TS snippets in markdown when running `doc-check`
- docs: lint help output references wrong github repo
- bug: aegir memory leak?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aegir.