Skip to content

Commit e8fe8c4

Browse files
committed
docs: outdated order rule doc
close #279
1 parent 178f360 commit e8fe8c4

File tree

3 files changed

+68
-86
lines changed

3 files changed

+68
-86
lines changed

.github/workflows/pkg-pr-new.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ jobs:
2727
- name: Build
2828
run: yarn build
2929

30-
- run: yarn dlx pkg-pr-new publish --compact
30+
- name: Publish
31+
run: yarn dlx pkg-pr-new publish --compact

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
645645
[`eslint-loader`]: https://www.npmjs.com/package/eslint-loader
646646
[`resolve`]: https://www.npmjs.com/package/resolve
647647
[`externals`]: https://webpack.github.io/docs/library-and-externals.html
648-
[1stg.me]: https://www.1stg.me
649-
[jounqin]: https://GitHub.com/JounQin
650-
[mit]: http://opensource.org/licenses/MIT
648+
[1stG.me]: https://www.1stG.me
649+
[JounQin]: https://github.com/JounQin
650+
[MIT]: http://opensource.org/licenses/MIT
651651
[node]: https://www.npmjs.com/package/eslint-import-resolver-node
652652
[webpack]: https://www.npmjs.com/package/eslint-import-resolver-webpack

docs/rules/order.md

+63-82
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ import 'format2.css' // OK
9999
This rule supports the following options (none of which are required):
100100

101101
- [`groups`][18]
102-
- [`pathGroups`][19]
103-
- [`pathGroupsExcludedImportTypes`][15]
102+
- [`pathGroups`][8]
103+
- [`pathGroupsExcludedImportTypes`][9]
104104
- [`distinctGroup`][32]
105-
- [`newlines-between`][24]
105+
- [`newlines-between`][20]
106106
- [`alphabetize`][30]
107107
- [`named`][33]
108108
- [`warnOnUnassignedImports`][5]
109-
- [`sortTypesAmongThemselves`][7]
109+
- [`sortTypesGroup`][7]
110110
- [`newlines-between-types`][27]
111111
- [`consolidateIslands`][25]
112112

@@ -162,7 +162,7 @@ Roughly speaking, the grouping algorithm is as follows:
162162

163163
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]
164164
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
165-
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])
165+
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])
166166
4. If the import's specifier matches [`import-x/internal-regex`][28], it will be considered **internal**
167167
5. If the import's specifier is an absolute path, it will be considered **unknown**
168168
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**
@@ -177,22 +177,20 @@ Roughly speaking, the grouping algorithm is as follows:
177177
15. If the import's specifier has a name that starts with a word character, it will be considered **external**
178178
16. If this point is reached, the import will be ignored entirely
179179

180-
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 [`sortTypesAmongThemselves`][7].
180+
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].
181181

182182
### `pathGroups`
183183

184184
Valid values: `PathGroup[]` \
185185
Default: `[]`
186186

187-
Sometimes [the predefined groups][18] are not fine-grained
188-
enough, especially when using import aliases. `pathGroups` defines one or more
189-
[`PathGroup`][13]s relative to a predefined group. Imports are associated with a
190-
[`PathGroup`][13] based on path matching against the import specifier (using
191-
[minimatch][14]).
187+
Sometimes [the predefined groups][18] are not fine-grained enough, especially when using import aliases.
188+
`pathGroups` defines one or more [`PathGroup`][13]s relative to a predefined group.
189+
Imports are associated with a [`PathGroup`][13] based on path matching against the import specifier (using [minimatch][14]).
192190

193-
> \[!IMPORTANT]
191+
> [!IMPORTANT]
194192
>
195-
> Note that, by default, imports grouped as `"builtin"`, `"external"`, or `"object"` will not be considered for further `pathGroups` matching unless they are removed from [`pathGroupsExcludedImportTypes`][15].
193+
> Note that, by default, imports grouped as `"builtin"`, `"external"`, or `"object"` will not be considered for further `pathGroups` matching unless they are removed from [`pathGroupsExcludedImportTypes`][9].
196194
197195
#### `PathGroup`
198196

@@ -230,11 +228,10 @@ enough, especially when using import aliases. `pathGroups` defines one or more
230228
Valid values: `("builtin" | "external" | "internal" | "unknown" | "parent" | "sibling" | "index" | "object" | "type")[]` \
231229
Default: `["builtin", "external", "object"]`
232230

233-
By default, imports in certain [groups][18] are excluded
234-
from being matched against [`pathGroups`][19] to prevent overeager sorting. Use
235-
`pathGroupsExcludedImportTypes` to modify which groups are excluded.
231+
By default, imports in certain [groups][18] are excluded from being matched against [`pathGroups`][8] to prevent overeager sorting.
232+
Use `pathGroupsExcludedImportTypes` to modify which groups are excluded.
236233

237-
> \[!TIP]
234+
> [!TIP]
238235
>
239236
> If using imports with custom specifier aliases (e.g.
240237
> you're using `eslint-import-resolver-alias`, `paths` in `tsconfig.json`, etc) that [end up
@@ -267,7 +264,7 @@ from being matched against [`pathGroups`][19] to prevent overeager sorting. Use
267264
Valid values: `boolean` \
268265
Default: `true`
269266

270-
> \[!CAUTION]
267+
> [!CAUTION]
271268
>
272269
> Currently, `distinctGroup` defaults to `true`. However, in a later update, the
273270
> default will change to `false`.
@@ -310,9 +307,9 @@ Enforces or forbids new lines between import groups.
310307

311308
- If set to `always`, at least one new line between each group will be enforced, and new lines inside a group will be forbidden
312309

313-
> \[!TIP]
314-
>
315-
> To prevent multiple lines between imports, the [`no-multiple-empty-lines` rule][21], or a tool like [Prettier][22], can be used.
310+
> [!TIP]
311+
>
312+
> To prevent multiple lines between imports, the [`no-multiple-empty-lines` rule][21], or a tool like [Prettier][22], can be used.
316313
317314
- If set to `always-and-inside-groups`, it will act like `always` except new lines are allowed inside import groups
318315

@@ -385,9 +382,9 @@ import index from './'
385382
Valid values: `{ order?: "asc" | "desc" | "ignore", orderImportKind?: "asc" | "desc" | "ignore", caseInsensitive?: boolean }` \
386383
Default: `{ order: "ignore", orderImportKind: "ignore", caseInsensitive: false }`
387384

388-
Determine the sort order of imports within each [predefined group][18] or [`PathGroup`][19] alphabetically based on specifier.
385+
Determine the sort order of imports within each [predefined group][18] or [`PathGroup`][8] alphabetically based on specifier.
389386

390-
> \[!NOTE]
387+
> [!NOTE]
391388
>
392389
> Imports will be alphabetized based on their _specifiers_, not by their
393390
> identifiers. For example, `const a = require('z');` will come _after_ `const z = require('a');` when `alphabetize` is set to `{ order: "asc" }`.
@@ -445,13 +442,10 @@ Default: `false`
445442

446443
Enforce ordering of names within imports and exports.
447444

448-
If set to `true` or `{ enabled: true }`, _all_ named imports must be ordered
449-
according to [`alphabetize`][30]. If set to `false` or `{ enabled:
450-
false }`, named imports can occur in any order.
445+
If set to `true` or `{ enabled: true }`, _all_ named imports must be ordered according to [`alphabetize`][30].
446+
If set to `false` or `{ enabled: false }`, named imports can occur in any order.
451447

452-
If set to `{ enabled: true, ... }`, and any of the properties `import`,
453-
`export`, `require`, or `cjsExports` are set to `false`, named ordering is
454-
disabled with respect to the following kind of expressions:
448+
If set to `{ enabled: true, ... }`, and any of the properties `import`, `export`, `require`, or `cjsExports` are set to `false`, named ordering is disabled with respect to the following kind of expressions:
455449

456450
- `import`:
457451

@@ -524,15 +518,12 @@ import { apply, compose } from 'xcompose'
524518
Valid values: `boolean` \
525519
Default: `false`
526520

527-
Warn when "unassigned" imports are out of order. Unassigned imports are imports
528-
with no corresponding identifiers (e.g. `import './my/thing.js'` or
529-
`require('./side-effects.js')`).
521+
Warn when "unassigned" imports are out of order.
522+
Unassigned imports are imports with no corresponding identifiers (e.g. `import './my/thing.js'` or `require('./side-effects.js')`).
530523

531-
> \[!NOTE]
524+
> [!NOTE]
532525
>
533-
> These warnings are not fixable with `--fix` since unassigned imports might be
534-
> used for their
535-
> [side-effects][31],
526+
> These warnings are not fixable with `--fix` since unassigned imports might be used for their [side-effects][31],
536527
> and changing the order of such imports cannot be done safely.
537528
538529
#### Example
@@ -566,12 +557,12 @@ import path from 'path'
566557
import './styles.css'
567558
```
568559

569-
### `sortTypesAmongThemselves`
560+
### `sortTypesGroup`
570561

571562
Valid values: `boolean` \
572563
Default: `false`
573564

574-
> \[!NOTE]
565+
> [!NOTE]
575566
>
576567
> This setting is only meaningful when `"type"` is included in [`groups`][18].
577568
@@ -613,7 +604,7 @@ import e from './'
613604

614605
This happens because [type-only imports][6] are considered part of one global
615606
[`"type"` group](#how-imports-are-grouped) by default. However, if we set
616-
`sortTypesAmongThemselves` to `true`:
607+
`sortTypesGroup` to `true`:
617608

618609
```jsonc
619610
{
@@ -622,7 +613,7 @@ This happens because [type-only imports][6] are considered part of one global
622613
{
623614
"groups": ["type", "builtin", "parent", "sibling", "index"],
624615
"alphabetize": { "order": "asc" },
625-
"sortTypesAmongThemselves": true,
616+
"sortTypesGroup": true,
626617
},
627618
],
628619
}
@@ -633,19 +624,15 @@ The same example will pass.
633624
### `newlines-between-types`
634625

635626
Valid values: `"ignore" | "always" | "always-and-inside-groups" | "never"` \
636-
Default: the value of [`newlines-between`][24]
627+
Default: the value of [`newlines-between`][20]
637628

638-
> \[!NOTE]
629+
> [!NOTE]
639630
>
640-
> This setting is only meaningful when [`sortTypesAmongThemselves`][7] is enabled.
631+
> This setting is only meaningful when [`sortTypesGroup`][7] is enabled.
641632
642-
`newlines-between-types` is functionally identical to [`newlines-between`][24]
643-
except it only enforces or forbids new lines between _[type-only][6] import
644-
groups_, which exist only when [`sortTypesAmongThemselves`][7] is enabled.
633+
`newlines-between-types` is functionally identical to [`newlines-between`][20] except it only enforces or forbids new lines between _[type-only][6] import groups_, which exist only when [`sortTypesGroup`][7] is enabled.
645634

646-
In addition, when determining if a new line is enforceable or forbidden between
647-
the type-only imports and the normal imports, `newlines-between-types` takes
648-
precedence over [`newlines-between`][24].
635+
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`][20].
649636

650637
#### Example
651638

@@ -657,7 +644,7 @@ Given the following settings:
657644
"error",
658645
{
659646
"groups": ["type", "builtin", "parent", "sibling", "index"],
660-
"sortTypesAmongThemselves": true,
647+
"sortTypesGroup": true,
661648
"newlines-between": "always",
662649
},
663650
],
@@ -691,7 +678,7 @@ However, if we set `newlines-between-types` to `"ignore"`:
691678
"error",
692679
{
693680
"groups": ["type", "builtin", "parent", "sibling", "index"],
694-
"sortTypesAmongThemselves": true,
681+
"sortTypesGroup": true,
695682
"newlines-between": "always",
696683
"newlines-between-types": "ignore",
697684
},
@@ -703,19 +690,19 @@ The same example will pass.
703690

704691
Note the new line after `import type E from './';` but before `import a from "fs";`. This new line separates the type-only imports from the normal imports. Its existence is governed by [`newlines-between-types`][27] and _not `newlines-between`_.
705692

706-
> \[!IMPORTANT]
693+
> [!IMPORTANT]
707694
>
708695
> In certain situations, [`consolidateIslands: true`][25] will take precedence over `newlines-between-types: "never"`, if used, when it comes to the new line separating type-only imports from normal imports.
709696
710-
The next example will pass even though there's a new line preceding the normal import and [`newlines-between`][24] is set to `"never"`:
697+
The next example will pass even though there's a new line preceding the normal import and [`newlines-between`][20] is set to `"never"`:
711698

712699
```jsonc
713700
{
714701
"import-x/order": [
715702
"error",
716703
{
717704
"groups": ["type", "builtin", "parent", "sibling", "index"],
718-
"sortTypesAmongThemselves": true,
705+
"sortTypesGroup": true,
719706
"newlines-between": "never",
720707
"newlines-between-types": "always",
721708
},
@@ -749,7 +736,7 @@ While the following fails due to the new line between the last type import and t
749736
"error",
750737
{
751738
"groups": ["type", "builtin", "parent", "sibling", "index"],
752-
"sortTypesAmongThemselves": true,
739+
"sortTypesGroup": true,
753740
"newlines-between": "always",
754741
"newlines-between-types": "never",
755742
},
@@ -780,26 +767,28 @@ import e from './'
780767
Valid values: `"inside-groups" | "never"` \
781768
Default: `"never"`
782769

783-
> \[!NOTE]
770+
> [!NOTE]
784771
>
785-
> This setting is only meaningful when [`newlines-between`][24] and/or [`newlines-between-types`][27] is set to `"always-and-inside-groups"`.
772+
> This setting is only meaningful when [`newlines-between`][20] and/or [`newlines-between-types`][27] is set to `"always-and-inside-groups"`.
786773
787-
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].
774+
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`][8].
788775

789-
> \[!IMPORTANT]
776+
> [!IMPORTANT]
790777
>
791778
> When all of the following are true:
792779
>
780+
> - [`sortTypesGroup`][7] is set to `true`
793781
> - `consolidateIslands` is set to `"inside-groups"`
794-
> - [`newlines-between`][24] is set to `"always-and-inside-groups"`
795-
> - [`newlines-between-types`][27] is set to `"never"`
796-
> - [`sortTypesAmongThemselves`][7] is set to `true`
782+
> - [`newlines-between`][20] is set to `"always-and-inside-groups"` when [`newlines-between-types`][27] is set to `"never"` (or vice-versa)
797783
>
798-
> Then [`newlines-between-types`][27] will yield to `consolidateIslands` and allow new lines to separate multi-line imports and a single new line to separate all [type-only imports][6] from all normal imports. Other than that, [`newlines-between-types: "never"`][27] functions as described.
784+
> Then [`newlines-between`][20]/[`newlines-between-types`][27] will yield to
785+
> `consolidateIslands` and allow new lines to separate multi-line imports
786+
> regardless of the `"never"` setting.
799787
>
800-
> This configuration is useful to keep type-only imports stacked tightly
801-
> together at the bottom of your import block to preserve space while still
802-
> logically organizing normal imports for quick and pleasant reference.
788+
> This configuration is useful, for instance, to keep single-line type-only
789+
> imports stacked tightly together at the bottom of your import block to
790+
> preserve space while still logically organizing normal imports for quick and
791+
> pleasant reference.
803792
804793
#### Example
805794

@@ -853,7 +842,7 @@ var sibling2 = require('./bar')
853842
var sibling3 = require('./foobar')
854843
```
855844

856-
Note the intragroup "islands" of grouped single-line imports, as well as multi-line imports, are surrounded by new lines. At the same time, note the typical new lines separating different groups are still maintained thanks to [`newlines-between`][24].
845+
Note the intragroup "islands" of grouped single-line imports, as well as multi-line imports, are surrounded by new lines. At the same time, note the typical new lines separating different groups are still maintained thanks to [`newlines-between`][20].
857846

858847
The same holds true for the next example; when given the following settings:
859848

@@ -883,25 +872,20 @@ The same holds true for the next example; when given the following settings:
883872
"newlines-between": "always-and-inside-groups",
884873
"newlines-between-types": "never",
885874
"pathGroupsExcludedImportTypes": [],
886-
"sortTypesAmongThemselves": true,
875+
"sortTypesGroup": true,
887876
"consolidateIslands": "inside-groups",
888877
},
889878
],
890879
}
891880
```
892881

893-
> \[!IMPORTANT]
882+
> [!IMPORTANT]
894883
>
895-
> **Pay special attention to the value of
896-
> [`pathGroupsExcludedImportTypes`](#pathgroupsexcludedimporttypes)** in this
897-
> example's settings. Without it, the successful example below would fail. This is
898-
> because the imports with specifiers starting with "dirA/", "dirB/", and
899-
> "dirC/" are all [considered part of the `"external"`
900-
> group](#how-imports-are-grouped), and imports in that group are
901-
> excluded from [`pathGroups`](#pathgroups) matching by default.
884+
> **Pay special attention to the value of [`pathGroupsExcludedImportTypes`][9]** in this example's settings.
885+
> Without it, the successful example below would fail.
886+
> 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`][8] matching by default.
902887
>
903-
> The fix is to remove `"external"` (and, in this example, the others) from
904-
> [`pathGroupsExcludedImportTypes`](#pathgroupsexcludedimporttypes).
888+
> The fix is to remove `"external"` (and, in this example, the others) from [`pathGroupsExcludedImportTypes`][9].
905889
906890
This will fail the rule check:
907891

@@ -984,24 +968,21 @@ import type { H } from './bbb'
984968
[4]: https://nodejs.org/api/esm.html#terminology
985969
[5]: #warnonunassignedimports
986970
[6]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
987-
[7]: #sorttypesamongthemselves
971+
[7]: #sorttypesgroup
988972
[8]: #pathgroups
989973
[9]: #pathgroupsexcludedimporttypes
990974
[10]: https://www.npmjs.com/package/is-core-module
991975
[11]: ../../README.md#importcore-modules
992976
[12]: https://www.npmjs.com/package/package-up
993977
[13]: #pathgroup
994978
[14]: https://www.npmjs.com/package/minimatch
995-
[15]: #pathgroupsexcludedimporttypes
996979
[16]: https://www.npmjs.com/package/minimatch#features
997980
[17]: https://www.npmjs.com/package/minimatch#options
998981
[18]: #groups
999-
[19]: #pathgroups
1000982
[20]: #newlines-between
1001983
[21]: https://eslint.org/docs/latest/rules/no-multiple-empty-lines
1002984
[22]: https://prettier.io
1003985
[23]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names
1004-
[24]: #newlines-between
1005986
[25]: #consolidateislands
1006987
[27]: #newlines-between-types
1007988
[28]: ../../README.md#importinternal-regex

0 commit comments

Comments
 (0)