You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit df5f8a9
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/src/rules/no-restricted-imports.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -286,6 +286,31 @@ import { AllowedObject } from "foo";
286
286
287
287
This is also an object option whose value is an array. This option allows you to specify multiple modules to restrict using `gitignore`-style patterns.
288
288
289
+
Where `paths` option takes exact import paths, `patterns` option can be used to specify the import paths with more flexibility, allowing for the restriction of multiple modules within the same directory. For example:
290
+
291
+
```json
292
+
"no-restricted-imports": ["error", {
293
+
"paths": [{
294
+
"name": "import-foo",
295
+
}]
296
+
}]
297
+
```
298
+
299
+
This configuration restricts import of the `import-foo` module but wouldn't restrict the import of `import-foo/bar` or `import-foo/baz`. You can use `patterns` to restrict both:
300
+
301
+
```json
302
+
"no-restricted-imports": ["error", {
303
+
"paths": [{
304
+
"name": "import-foo",
305
+
}],
306
+
"patterns": [{
307
+
"group": ["import-foo/ba*"],
308
+
}]
309
+
}]
310
+
```
311
+
312
+
This configuration restricts imports not just from `import-foo` using `path`, but also `import-foo/bar` and `import-foo/baz` using `patterns`.
313
+
289
314
Because the patterns follow the `gitignore`-style, if you want to reinclude any particular module this can be done by prefixing a negation (`!`) mark in front of the pattern. (Negated patterns should come last in the array because order is important.)
290
315
291
316
```json
@@ -294,7 +319,7 @@ Because the patterns follow the `gitignore`-style, if you want to reinclude any
294
319
}]
295
320
```
296
321
297
-
Examples of **incorrect** code for `pattern` option:
322
+
Examples of **incorrect** code for `patterns` option:
298
323
299
324
::: incorrect { "sourceType": "module" }
300
325
@@ -328,7 +353,7 @@ import pick from 'import1/private/someModule';
328
353
329
354
In this example, `"!import1/private/*"` is not reincluding the modules inside `private` because the negation mark (`!`) does not reinclude the files if it's parent directory is excluded by a pattern. In this case, `import1/private` directory is already excluded by the `import1/*` pattern. (The excluded directory can be reincluded using `"!import1/private"`.)
330
355
331
-
Examples of **correct** code for `pattern` option:
356
+
Examples of **correct** code for `patterns` option:
0 commit comments