eslint-plugin-import
eslint-plugin-import copied to clipboard
[no-restricted-paths] Add options to ignore type imports
Can an option be added to the no-restricted-paths rule to ignore TypeScript's type imports?
// Allow this.
import type { T } from 'some/restricted/path';
// While still disallowing this.
import { foo } from 'some/restricted/path';
My proposal is to add an option at the top level of the config called something along the lines of allowedImportKinds which can be set to any number of the following options: "type" or "value".
Additionally, this option could be available in each "zone" so that individual zones can override this behavior (but this may not be needed).
I haven't touched this project's code base before but I can probably whip up a PR for this.
Although I'm not a fan of adding typescript-specific options, I think a per-zone option (that's also available higher "up", as well, as you describe) would be good.
I'm not sure if we need an enum - will there ever be another kind of import that's not value or type? - but we can discuss that in a PR.
I agree this would be useful. I want to restrict some imports to silo code between contexts; sharing types is obvious since they're used to sync communication between the siloes.
In some cases I can extract them to ./types.ts and exclude them in batch, but that isn't always practical.
I think this is a duplicate of https://github.com/import-js/eslint-plugin-import/issues/2450
I think so too, but this one is older. I'm ok in keeping the newer one open since it has more thumbs up though
My bad, didn't check the date 😅
I made PR for this years back. It's probably got heaps of conflicts now: #1900
any update here?