|
6 | 6 |
|
7 | 7 | Enforce a convention in the order of `require()` / `import` statements.
|
8 | 8 |
|
9 |
| -With the [`groups`][2] option set to `["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"]` the order is as shown in the following example: |
| 9 | +With the [`groups`][18] option set to `["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"]` the order is as shown in the following example: |
10 | 10 |
|
11 | 11 | ```ts
|
12 | 12 | // 1. node "builtin" modules
|
@@ -157,7 +157,7 @@ const identifier3 = require('specifier3');
|
157 | 157 |
|
158 | 158 | Roughly speaking, the grouping algorithm is as follows:
|
159 | 159 |
|
160 |
| -1. If the import has no corresponding identifiers (e.g. `import'./my/thing.js'`), is otherwise "unassigned," or is an unsupported use of `require()`, and [`warnOnUnassignedImports`][5] is disabled, it will be ignored entirely since the order of these imports may be important for their [side-effects][31] |
| 160 | +1. If the import has no corresponding identifiers (e.g. `import './my/thing.js'`), is otherwise "unassigned," or is an unsupported use of `require()`, and [`warnOnUnassignedImports`][5] is disabled, it will be ignored entirely since the order of these imports may be important for their [side-effects][31] |
161 | 161 | 2. If the import is part of an arcane TypeScript declaration (e.g. `import log = console.log`), it will be considered **object**. However, note that external module references (e.g. `import x = require('z')`) are treated as normal `require()`s and import-exports (e.g. `export import w = y;`) are ignored entirely
|
162 | 162 | 3. If the import is [type-only][6], `"type"` is in `groups`, and [`sortTypesAmongThemselves`][7] is disabled, it will be considered **type** (with additional implications if using [`pathGroups`][8] and `"type"` is in [`pathGroupsExcludedImportTypes`][9])
|
163 | 163 | 4. If the import's specifier matches [`import/internal-regex`][28], it will be considered **internal**
|
@@ -298,7 +298,7 @@ Enforces or forbids new lines between import groups.
|
298 | 298 |
|
299 | 299 | - If set to `always`, at least one new line between each group will be enforced, and new lines inside a group will be forbidden
|
300 | 300 |
|
301 |
| - > \[!TIP] |
| 301 | + > [!TIP] |
302 | 302 | >
|
303 | 303 | > To prevent multiple lines between imports, the [`no-multiple-empty-lines` rule][21], or a tool like [Prettier][22], can be used.
|
304 | 304 |
|
@@ -552,11 +552,11 @@ Default: `false`
|
552 | 552 |
|
553 | 553 | > \[!NOTE]
|
554 | 554 | >
|
555 |
| -> This setting is only meaningful when `"type"` is included in [`groups`][2]. |
| 555 | +> This setting is only meaningful when `"type"` is included in [`groups`][18]. |
556 | 556 |
|
557 | 557 | Sort [type-only imports][6] separately from normal non-type imports.
|
558 | 558 |
|
559 |
| -When enabled, the intragroup sort order of [type-only imports][6] will mirror the intergroup ordering of normal imports as defined by [`groups`][2], [`pathGroups`][8], etc. |
| 559 | +When enabled, the intragroup sort order of [type-only imports][6] will mirror the intergroup ordering of normal imports as defined by [`groups`][18], [`pathGroups`][8], etc. |
560 | 560 |
|
561 | 561 | #### Example
|
562 | 562 |
|
@@ -612,13 +612,9 @@ Default: the value of [`newlines-between`][24]
|
612 | 612 | >
|
613 | 613 | > This setting is only meaningful when [`sortTypesAmongThemselves`][7] is enabled.
|
614 | 614 |
|
615 |
| -Enforces or forbids new lines between _[type-only][6] import groups_, which only |
616 |
| -exist when [`sortTypesAmongThemselves`][7] is enabled. `newlines-between-types` |
617 |
| -is otherwise functionally identical to [`newlines-between`][24]. |
| 615 | +`newlines-between-types` is functionally identical to [`newlines-between`][24] except it only enforces or forbids new lines between _[type-only][6] import groups_, which exist only when [`sortTypesAmongThemselves`][7] is enabled. |
618 | 616 |
|
619 |
| -In addition, when determining if a new line is enforceable or forbidden between |
620 |
| -the type-only imports and the normal imports, `newlines-between-types` takes |
621 |
| -precedence over [`newlines-between`][24]. |
| 617 | +In addition, when determining if a new line is enforceable or forbidden between the type-only imports and the normal imports, `newlines-between-types` takes precedence over [`newlines-between`][24]. |
622 | 618 |
|
623 | 619 | #### Example
|
624 | 620 |
|
@@ -745,7 +741,7 @@ Default: `"never"`
|
745 | 741 | >
|
746 | 742 | > This setting is only meaningful when [`newlines-between`][24] and/or [`newlines-between-types`][27] is set to `"always-and-inside-groups"`.
|
747 | 743 |
|
748 |
| -When set to `"inside-groups"`, this ensures imports spanning multiple lines are separated from other imports with a new line while single-line imports are grouped together (and the space between them consolidated) if they belong to the same [group][2] or [`pathGroups`][26]. |
| 744 | +When set to `"inside-groups"`, this ensures imports spanning multiple lines are separated from other imports with a new line while single-line imports are grouped together (and the space between them consolidated) if they belong to the same [group][18] or [`pathGroups`][26]. |
749 | 745 |
|
750 | 746 | > \[!IMPORTANT]
|
751 | 747 | >
|
@@ -859,16 +855,11 @@ The same holds true for the next example; when given the following settings:
|
859 | 855 |
|
860 | 856 | > [!IMPORTANT]
|
861 | 857 | >
|
862 |
| -> **Pay special attention to the value of |
863 |
| -> [`pathGroupsExcludedImportTypes`](#pathgroupsexcludedimporttypes)** in this |
864 |
| -> example's settings. Without it, the successful example below would fail. This is |
865 |
| -> because the imports with specifiers starting with "dirA/", "dirB/", and |
866 |
| -> "dirC/" are all [considered part of the `"external"` |
867 |
| -> group](#how-imports-are-grouped), and imports in that group are |
868 |
| -> excluded from [`pathGroups`](#pathgroups) matching by default. |
| 858 | +> **Pay special attention to the value of [`pathGroupsExcludedImportTypes`](#pathgroupsexcludedimporttypes)** in this example's settings. |
| 859 | +> Without it, the successful example below would fail. |
| 860 | +> This is because the imports with specifiers starting with "dirA/", "dirB/", and "dirC/" are all [considered part of the `"external"` group](#how-imports-are-grouped), and imports in that group are excluded from [`pathGroups`](#pathgroups) matching by default. |
869 | 861 | >
|
870 |
| -> The fix is to remove `"external"` (and, in this example, the others) from |
871 |
| -> [`pathGroupsExcludedImportTypes`](#pathgroupsexcludedimporttypes). |
| 862 | +> The fix is to remove `"external"` (and, in this example, the others) from [`pathGroupsExcludedImportTypes`](#pathgroupsexcludedimporttypes). |
872 | 863 |
|
873 | 864 | This will fail the rule check:
|
874 | 865 |
|
@@ -1012,7 +1003,6 @@ import type { H } from './bbb';
|
1012 | 1003 | - [`import/core-modules`][11]
|
1013 | 1004 |
|
1014 | 1005 | [1]: https://eslint.org/docs/latest/user-guide/command-line-interface#--fix
|
1015 |
| -[2]: #groups-string |
1016 | 1006 | [3]: #how-imports-are-grouped
|
1017 | 1007 | [4]: https://nodejs.org/api/esm.html#terminology
|
1018 | 1008 | [5]: #warnonunassignedimports
|
|
0 commit comments