-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Rule Change: no-restricted-imports should honor a package's declared exports #18104
Comments
Thanks for the issue @JeremyLoy. I don't think that ESLint can support this feature in a core rule because it's about a Node.js-specific API. Also note that the That said, eslint-plugin-n has a rule called |
Thanks for the response @fasttime, I appreciate it. I'll close this since it makes sense to not have Node only concepts in ESLint proper. Also, thank you for pointing me towards eslint-plugin-n, I hadn't seen it before. Is that the de-facto plugin for all things NodeJS specific nowadays? I see it referenced a few times in this repo next to deprecated rules |
hey @fasttime - I updated my repo with Do you mind taking a look and seeing what I have misconfigured? |
Hm, your npm In the eslintrc config system, no files are linted by default, and only .js files are linted if a directory is specified. To lint a directory of .mjs files, one would pass both a directory name ( |
@fasttime thanks 🤦 Can't believe I forgot to do that. Its been a while since I set up a project from scratch. My PoC is working now, correctly failing the impossible import. But now its also failing to find the local workspace module. Unless you think thats an issue with Thanks again for your help! |
No problem :) For usage questions around ESLint there is also a Discord chat, they are usually quick to respond. Good luck! |
What rule do you want to change?
no-restricted-imports, although I'm open to any rule set to be honest
What change do you want to make?
Generate more warnings
How do you think the change should be implemented?
A new default behavior
Example code
https://github.com/JeremyLoy/hidden-module-import-issue-example/blob/main/test/index.test.mjs
I made a sample project demonstrating the issue.
https://nodejs.org/api/packages.html#package-entry-points
Since Node v12 it has been possible for a package to define it's exports, encapsulating unlisted modules. This is a great way to write scalable code.
Unfortunately, importing this hidden modules doesn't cause an issue until runtime. This means that it is up to Linters and IDEs to raise the issue to developers early.
I've opened an issue for Webstorm already, but I think ESLint would be a great place as well.
Because this has been the default behavior for NodeJS for many years, I think its safe to add this new rule behavior and default it to 'on' as well.
What does the rule currently do for this code?
It does nothing for the attached sample project.
What will the rule do after it's changed?
It will warn against import violations defined by packages in the exact same way as manually defined import violations
Participation
Additional comments
Happy to help if you point me in the correct direction. I've never contributed to this codebase specifically nor have I ever looked at its internals.
The text was updated successfully, but these errors were encountered: