import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.57k stars 1.57k forks source link

Restrict importing specific packages #3084

Closed rclarey closed 1 month ago

rclarey commented 1 month ago

I am working in a monorepo with different "tiers" of packages and I want to restrict which tiers can import from which other tiers. E.g. core packages cannot import from feature packages.

I tried configuring the existing no-restricted-paths rule for this, but I couldn't seem to get it to work since from is of course treated as a path relative to basePath so there is no way to get it to match a package name.

Is this something no-restricted-paths should be able to do? If not should no-restricted-paths be extended to allow this, or is a new rule better?

ljharb commented 1 month ago

No, because other packages aren't relative paths.

Perhaps the https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md rule would help, and you'd use overrides to configure different sets of modules as "internal" for each group of packages?

soryy708 commented 1 month ago

Try no-restricted-imports?