Skip to content

Commit

Permalink
docs: Add example with side-effect imports to no-restricted-imports (#…
Browse files Browse the repository at this point in the history
…18997)

* docs: Add example with side-effect imports to no-restricted-imports

* update quotes for consistency
  • Loading branch information
mdjermanovic authored Oct 8, 2024
1 parent ed4635f commit 5dcbc51
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/src/rules/no-restricted-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,40 @@ import isEmpty, { hasValue } from 'utils/collection-utils';

:::

You can also use this option to allow only side-effect imports by setting it to a pattern that matches any name, such as `^`.

Examples of **incorrect** code for `importNamePattern` option:

::: incorrect { "sourceType": "module" }

```js
/*eslint no-restricted-imports: ["error", { patterns: [{
group: ["utils/*"],
importNamePattern: "^"
}]}]*/

import isEmpty, { hasValue } from 'utils/collection-utils';

import * as file from 'utils/file-utils';
```

:::

Examples of **correct** code for `importNamePattern` option:

::: correct { "sourceType": "module" }

```js
/*eslint no-restricted-imports: ["error", { patterns: [{
group: ["utils/*"],
importNamePattern: "^"
}]}]*/

import 'utils/init-utils';
```

:::

#### allowImportNamePattern

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.
Expand Down

0 comments on commit 5dcbc51

Please sign in to comment.