eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

[no-restricted-paths] Add options to ignore type imports

Open RebeccaStevens opened this issue 5 years ago • 7 comments

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.

RebeccaStevens avatar Sep 14 '20 22:09 RebeccaStevens

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.

ljharb avatar Sep 14 '20 23:09 ljharb

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.

fregante avatar Dec 06 '22 10:12 fregante

I think this is a duplicate of https://github.com/import-js/eslint-plugin-import/issues/2450

golergka avatar Feb 28 '23 15:02 golergka

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

fregante avatar Feb 28 '23 16:02 fregante

My bad, didn't check the date 😅

golergka avatar Feb 28 '23 17:02 golergka

I made PR for this years back. It's probably got heaps of conflicts now: #1900

RebeccaStevens avatar Feb 28 '23 17:02 RebeccaStevens

any update here?

OrReuben avatar Aug 15 '25 21:08 OrReuben