Skip to content

Commit 1c65ff0

Browse files
committed
docs: add regexGroup option in no-restricted-imports
1 parent c34d0bd commit 1c65ff0

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

docs/src/rules/no-restricted-imports.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ import pick from 'import1/private/someModule';
389389

390390
The `patterns` array can also include objects. The `group` property is used to specify the `gitignore`-style patterns for restricting modules and the `message` property is used to specify a custom message.
391391

392-
The `group` property is required property when using objects inside the `patterns` array.
392+
Either of the `group` or `regexGroup` property is required when using the `patterns` option.
393393

394394
```json
395395
"no-restricted-imports": ["error", {
@@ -433,6 +433,53 @@ import lodash from 'lodash';
433433

434434
:::
435435

436+
#### regexGroup
437+
438+
The `regexGroup` property is used to specify the regex patterns for restricting modules.
439+
440+
```json
441+
"no-restricted-imports": ["error", {
442+
"patterns": [{
443+
"regexGroup": "import1/private/",
444+
"message": "usage of import1 private modules not allowed."
445+
}, {
446+
"regexGroup": "import2/(?!good)",
447+
"message": "import2 is deprecated, except the modules in import2/good."
448+
}]
449+
}]
450+
```
451+
452+
Examples of **incorrect** code for `regexGroup` option:
453+
454+
::: incorrect { "sourceType": "module" }
455+
456+
```js
457+
/*eslint no-restricted-imports: ["error", { patterns: [{
458+
regexGroup: "@app/(?!(api/enums$)).*",
459+
}]}]*/
460+
461+
import Foo from '@app/api';
462+
import Bar from '@app/api/bar';
463+
import Baz from '@app/api/baz';
464+
import Bux from '@app/api/enums/foo';
465+
```
466+
467+
:::
468+
469+
Examples of **correct** code for `regexGroup` option:
470+
471+
::: correct { "sourceType": "module" }
472+
473+
```js
474+
/*eslint no-restricted-imports: ["error", { patterns: [{
475+
regexGroup: "@app/(?!(api/enums$)).*",
476+
}]}]*/
477+
478+
import Foo from '@app/api/enums';
479+
```
480+
481+
:::
482+
436483
#### caseSensitive
437484

438485
This is a boolean option and sets the patterns specified in the `group` array to be case-sensitive when `true`. Default is `false`.

0 commit comments

Comments
 (0)