-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add rules for hybrid Node.js and browser environments #242
Conversation
I'm not sure what the best way would be to handle test files. For testing in production, I simply added this package to the |
Could we add this to the base package instead? That package is already meant to prevent the use of anything Node.js or browser-specific. I'm still confused as to why Node.js specific globals aren't already disallowed though 🤔 The base package uses |
I'm afraid that it will cause many breaking changes in projects, preventing them from upgrading to the latest config. Fixing these errors is not as simple as changing one line of code, some possibly requiring a larger refactor (like swapping out It might be better to have it as a new package, wait until most of our modules have implemented it, and then merge it with the base rules.
It seems to be overridden somewhere. Explicitly adding |
I think this is the culprit: https://github.com/typescript-eslint/typescript-eslint/blob/efc147b04dce52ab17415b6a4ae4076b944b9036/packages/eslint-plugin/src/configs/eslint-recommended.ts It's disabled because TypeScript is already checking for undefined types. But TypeScript isn't seeing it as undefined because we have |
In the past, we've handled this by disabling disruptive rules in the project ESLint config to make the update easier. Then we can re-enable any rules one-by-one to fix lint errors. We're made many disruptive lint changes recently, and many more are planned (e.g. enabling the ESLint TypeScript rules that require type information); making a new package each time would be confusing. |
I looked into this, and couldn't find a reasonable way of excluding So I guess we should explicitly add no-undef to our TypeScript ESLint config. |
1e55041
to
c97444a
Compare
This adds a new package for hybrid Node.js and browser envrionments. It prevents the use of any Node.js or browser-specific globals.
Because we make use of Node.js and browser APIs in many modules right now, adding this to an existing package would cause a lot of breaking changes. That's why I created a new package instead. It includes a script to update the rules automatically.
Using the following file as example:
Results in these errors:
To do