Skip to content

Commit 36f07d4

Browse files
committed
feat: [import/order] allow intragroup sorting of type-only imports via sortTypesAmongThemselves
Closes import-js#2912 import-js#2347 import-js#2441 Subsumes import-js#2615
1 parent 0c179cd commit 36f07d4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/rules/order.md

+43
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,49 @@ import type { G } from './aaa.js';
996996
import type { H } from './bbb';
997997
```
998998

999+
### `sortTypesAmongThemselves: true|false`
1000+
1001+
Sort type-only imports separately from normal non-type imports.
1002+
1003+
When enabled, the intragroup sort order of type-only imports will mirror the intergroup ordering of normal imports as defined by `group`, `pathGroups`, etc.
1004+
1005+
> This setting is only meaningful when `"type"` is included in `groups`.
1006+
1007+
Given the following settings:
1008+
1009+
```ts
1010+
{
1011+
groups: ['type', 'builtin', 'parent', 'sibling', 'index']
1012+
}
1013+
```
1014+
1015+
This example will fail the rule check:
1016+
1017+
```ts
1018+
import type A from "fs";
1019+
import type B from "path";
1020+
import type C from "../foo.js";
1021+
import type D from "./bar.js";
1022+
import type E from './';
1023+
1024+
import a from "fs";
1025+
import b from "path";
1026+
import c from "../foo.js";
1027+
import d from "./bar.js";
1028+
import e from "./";
1029+
```
1030+
1031+
However, if we add `sortTypesAmongThemselves: true`:
1032+
1033+
```ts
1034+
{
1035+
groups: ['type', 'builtin', 'parent', 'sibling', 'index'],
1036+
sortTypesAmongThemselves: true
1037+
}
1038+
```
1039+
1040+
The same example will pass.
1041+
9991042
## Related
10001043

10011044
- [`import/external-module-folders`][29]

0 commit comments

Comments
 (0)