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
Copy file name to clipboardExpand all lines: docs/rules/order.md
+62-2
Original file line number
Diff line number
Diff line change
@@ -106,6 +106,7 @@ This rule supports the following options (none of which are required):
106
106
-[`alphabetize`][30]
107
107
-[`named`][33]
108
108
-[`warnOnUnassignedImports`][5]
109
+
-[`sortTypesGroup`][7]
109
110
110
111
---
111
112
@@ -156,7 +157,7 @@ Roughly speaking, the grouping algorithm is as follows:
156
157
157
158
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]
158
159
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
159
-
3. If the import is [type-only][6], and `"type"` is in `groups`, it will be considered **type** (with additional implications if using [`pathGroups`][8] and `"type"` is in [`pathGroupsExcludedImportTypes`][9])
160
+
3. If the import is [type-only][6], `"type"` is in `groups`, and [`sortTypesGroup`][7] is disabled, it will be considered **type** (with additional implications if using [`pathGroups`][8] and `"type"` is in [`pathGroupsExcludedImportTypes`][9])
160
161
4. If the import's specifier matches [`import/internal-regex`][28], it will be considered **internal**
161
162
5. If the import's specifier is an absolute path, it will be considered **unknown**
162
163
6. If the import's specifier has the name of a Node.js core module (using [is-core-module][10]), it will be considered **builtin**
@@ -171,7 +172,7 @@ Roughly speaking, the grouping algorithm is as follows:
171
172
15. If the import's specifier has a name that starts with a word character, it will be considered **external**
172
173
16. If this point is reached, the import will be ignored entirely
173
174
174
-
At the end of the process, if they co-exist in the same file, all top-level `require()` statements that haven't been ignored are shifted (with respect to their order) below any ES6 `import` or similar declarations.
175
+
At the end of the process, if they co-exist in the same file, all top-level `require()` statements that haven't been ignored are shifted (with respect to their order) below any ES6 `import` or similar declarations. Finally, any type-only declarations are potentially reorganized according to [`sortTypesGroup`][7].
175
176
176
177
### `pathGroups`
177
178
@@ -533,6 +534,64 @@ import path from 'path';
533
534
import'./styles.css';
534
535
```
535
536
537
+
### `sortTypesGroup`
538
+
539
+
Valid values: `boolean`\
540
+
Default: `false`
541
+
542
+
> \[!NOTE]
543
+
>
544
+
> This setting is only meaningful when `"type"` is included in [`groups`][18].
545
+
546
+
Sort [type-only imports][6] separately from normal non-type imports.
547
+
548
+
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.
This will fail the rule check even though it's logically ordered as we expect (builtins come before parents, parents come before siblings, siblings come before indices), the only difference is we separated type-only imports from normal imports:
564
+
565
+
```ts
566
+
importtypeAfrom"fs";
567
+
importtypeBfrom"path";
568
+
importtypeCfrom"../foo.js";
569
+
importtypeDfrom"./bar.js";
570
+
importtypeEfrom'./';
571
+
572
+
importafrom"fs";
573
+
importbfrom"path";
574
+
importcfrom"../foo.js";
575
+
importdfrom"./bar.js";
576
+
importefrom"./";
577
+
```
578
+
579
+
This happens because [type-only imports][6] are considered part of one global
580
+
[`"type"` group](#how-imports-are-grouped) by default. However, if we set
0 commit comments