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

Prevent all Node.js modules when not detected to be in a Node environment #321

Open
brettz9 opened this issue Jan 24, 2022 · 0 comments
Open

Comments

@brettz9
Copy link

brettz9 commented Jan 24, 2022

I would like to propose a rule which forbids all Node.js core modules, though which makes allowances for them under certain conditions. The purpose would be to ensure that one restricts such modules to use within Node entry files but otherwise allows one's code to work universally as polyglot code.

As far as the conditions under which to allow Node.js modules:

  1. The file is pointed to by a node conditional export in package.json
  2. The file has {env: {node: true}} applied to it

These conditions are more likely to suggest that the file or the entire package is Node only.

Such an option ought to help discourage packages which could be polyglot friendly from restricting their files or packages unnecessarily to Node only.

If you are open to the idea, I would think this could be its own rule, or it could be added as an option within the likes of node/no-restricted-import/node/no-restricted-require.

(Note that I originally submitted this rule proposal to import-js/eslint-plugin-import#2369 as that project already has a rule to restrict Node modules, but as they did not wish to support this, I thought I would ask here, especially since you already have some other very convenient rules which check package.json or other config.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant