UNPKG

1.72 kBMarkdownView Raw
1# `no-restricted-imports`
2
3Disallow specified modules when loaded by `import`.
4
5## Rule Details
6
7This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) rule.
8
9## How to Use
10
11```jsonc
12{
13 // note you must disable the base rule as it can report incorrect errors
14 "no-restricted-imports": "off",
15 "@typescript-eslint/no-restricted-imports": ["error"]
16}
17```
18
19## Options
20
21See [`eslint/no-restricted-imports` options](https://eslint.org/docs/rules/no-restricted-imports#options).
22This rule adds the following options:
23
24### `allowTypeImports`
25
26(default: `false`)
27
28You can specify this option for a specific path or pattern as follows:
29
30```jsonc
31"@typescript-eslint/no-restricted-imports": ["error", {
32 "paths": [{
33 "name": "import-foo",
34 "message": "Please use import-bar instead.",
35 "allowTypeImports": true
36 }, {
37 "name": "import-baz",
38 "message": "Please use import-quux instead.",
39 "allowTypeImports": true
40 }]
41}]
42```
43
44When set to `true`, the rule will allow [Type-Only Imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export).
45
46Examples of code with the above config:
47
48<!--tabs-->
49
50#### ❌ Incorrect
51
52```ts
53import foo from 'import-foo';
54export { Foo } from 'import-foo';
55
56import baz from 'import-baz';
57export { Baz } from 'import-baz';
58```
59
60#### ✅ Correct
61
62```ts
63import { foo } from 'other-module';
64
65import type foo from 'import-foo';
66export type { Foo } from 'import-foo';
67
68import type baz from 'import-baz';
69export type { Baz } from 'import-baz';
70```
71
72## Attributes
73
74- Configs:
75 - [ ] ✅ Recommended
76 - [ ] 🔒 Strict
77- [ ] 🔧 Fixable
78- [ ] 💭 Requires type information