Skip to content

Commit 5dcbc51

Browse files
authored
docs: Add example with side-effect imports to no-restricted-imports (#18997)
* docs: Add example with side-effect imports to no-restricted-imports * update quotes for consistency
1 parent ed4635f commit 5dcbc51

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,40 @@ import isEmpty, { hasValue } from 'utils/collection-utils';
694694

695695
:::
696696

697+
You can also use this option to allow only side-effect imports by setting it to a pattern that matches any name, such as `^`.
698+
699+
Examples of **incorrect** code for `importNamePattern` option:
700+
701+
::: incorrect { "sourceType": "module" }
702+
703+
```js
704+
/*eslint no-restricted-imports: ["error", { patterns: [{
705+
group: ["utils/*"],
706+
importNamePattern: "^"
707+
}]}]*/
708+
709+
import isEmpty, { hasValue } from 'utils/collection-utils';
710+
711+
import * as file from 'utils/file-utils';
712+
```
713+
714+
:::
715+
716+
Examples of **correct** code for `importNamePattern` option:
717+
718+
::: correct { "sourceType": "module" }
719+
720+
```js
721+
/*eslint no-restricted-imports: ["error", { patterns: [{
722+
group: ["utils/*"],
723+
importNamePattern: "^"
724+
}]}]*/
725+
726+
import 'utils/init-utils';
727+
```
728+
729+
:::
730+
697731
#### allowImportNamePattern
698732

699733
This is a string option. Inverse of `importNamePattern`, this option allows imports that matches the specified regex pattern. So it restricts all imports from a module, except specified allowed patterns.

0 commit comments

Comments
 (0)