Skip to content

Commit 752f00d

Browse files
committed
refactor: change sortTypesAmongThemselves => sortTypesGroup
1 parent 9eb4805 commit 752f00d

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

docs/rules/order.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ This rule supports the following options (none of which are required):
106106
- [`alphabetize`][30]
107107
- [`named`][33]
108108
- [`warnOnUnassignedImports`][5]
109-
- [`sortTypesAmongThemselves`][7]
109+
- [`sortTypesGroup`][7]
110110
- [`newlines-between-types`][27]
111111
- [`consolidateIslands`][25]
112112

@@ -159,7 +159,7 @@ Roughly speaking, the grouping algorithm is as follows:
159159

160160
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]
161161
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-
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])
162+
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])
163163
4. If the import's specifier matches [`import/internal-regex`][28], it will be considered **internal**
164164
5. If the import's specifier is an absolute path, it will be considered **unknown**
165165
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**
@@ -174,7 +174,7 @@ Roughly speaking, the grouping algorithm is as follows:
174174
15. If the import's specifier has a name that starts with a word character, it will be considered **external**
175175
16. If this point is reached, the import will be ignored entirely
176176

177-
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].
177+
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].
178178

179179
### `pathGroups`
180180

@@ -545,7 +545,7 @@ import path from 'path';
545545
import './styles.css';
546546
```
547547

548-
### `sortTypesAmongThemselves`
548+
### `sortTypesGroup`
549549

550550
Valid values: `boolean` \
551551
Default: `false`
@@ -589,14 +589,14 @@ import e from "./";
589589

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

594594
```jsonc
595595
{
596596
"import/order": ["error", {
597597
"groups": ["type", "builtin", "parent", "sibling", "index"],
598598
"alphabetize": { "order": "asc" },
599-
"sortTypesAmongThemselves": true
599+
"sortTypesGroup": true
600600
}]
601601
}
602602
```
@@ -610,9 +610,9 @@ Default: the value of [`newlines-between`][20]
610610

611611
> \[!NOTE]
612612
>
613-
> This setting is only meaningful when [`sortTypesAmongThemselves`][7] is enabled.
613+
> This setting is only meaningful when [`sortTypesGroup`][7] is enabled.
614614
615-
`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 [`sortTypesAmongThemselves`][7] is enabled.
615+
`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.
616616

617617
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].
618618

@@ -624,7 +624,7 @@ Given the following settings:
624624
{
625625
"import/order": ["error", {
626626
"groups": ["type", "builtin", "parent", "sibling", "index"],
627-
"sortTypesAmongThemselves": true,
627+
"sortTypesGroup": true,
628628
"newlines-between": "always"
629629
}]
630630
}
@@ -655,7 +655,7 @@ However, if we set `newlines-between-types` to `"ignore"`:
655655
{
656656
"import/order": ["error", {
657657
"groups": ["type", "builtin", "parent", "sibling", "index"],
658-
"sortTypesAmongThemselves": true,
658+
"sortTypesGroup": true,
659659
"newlines-between": "always",
660660
"newlines-between-types": "ignore"
661661
}]
@@ -676,7 +676,7 @@ The next example will pass even though there's a new line preceding the normal i
676676
{
677677
"import/order": ["error", {
678678
"groups": ["type", "builtin", "parent", "sibling", "index"],
679-
"sortTypesAmongThemselves": true,
679+
"sortTypesGroup": true,
680680
"newlines-between": "never",
681681
"newlines-between-types": "always"
682682
}]
@@ -707,7 +707,7 @@ While the following fails due to the new line between the last type import and t
707707
{
708708
"import/order": ["error", {
709709
"groups": ["type", "builtin", "parent", "sibling", "index"],
710-
"sortTypesAmongThemselves": true,
710+
"sortTypesGroup": true,
711711
"newlines-between": "always",
712712
"newlines-between-types": "never"
713713
}]
@@ -750,7 +750,7 @@ When set to `"inside-groups"`, this ensures imports spanning multiple lines are
750750
> - `consolidateIslands` is set to `"inside-groups"`
751751
> - [`newlines-between`][20] is set to `"always-and-inside-groups"`
752752
> - [`newlines-between-types`][27] is set to `"never"`
753-
> - [`sortTypesAmongThemselves`][7] is set to `true`
753+
> - [`sortTypesGroup`][7] is set to `true`
754754
>
755755
> 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.
756756
>
@@ -847,7 +847,7 @@ The same holds true for the next example; when given the following settings:
847847
"newlines-between": "always-and-inside-groups",
848848
"newlines-between-types": "never",
849849
"pathGroupsExcludedImportTypes": [],
850-
"sortTypesAmongThemselves": true,
850+
"sortTypesGroup": true,
851851
"consolidateIslands": "inside-groups"
852852
}]
853853
}
@@ -1006,7 +1006,7 @@ import type { H } from './bbb';
10061006
[4]: https://nodejs.org/api/esm.html#terminology
10071007
[5]: #warnonunassignedimports
10081008
[6]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
1009-
[7]: #sorttypesamongthemselves
1009+
[7]: #sortTypesGroup
10101010
[8]: #pathgroups
10111011
[9]: #pathgroupsexcludedimporttypes
10121012
[10]: https://www.npmjs.com/package/is-core-module

src/rules/order.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ function computePathRank(ranks, pathGroups, path, maxPosition) {
513513
}
514514
}
515515

516-
function computeRank(context, ranks, importEntry, excludedImportTypes, isSortingTypesAmongThemselves) {
516+
function computeRank(context, ranks, importEntry, excludedImportTypes, isSortingTypesGroup) {
517517
let impType;
518518
let rank;
519519

@@ -523,7 +523,7 @@ function computeRank(context, ranks, importEntry, excludedImportTypes, isSorting
523523

524524
if (importEntry.type === 'import:object') {
525525
impType = 'object';
526-
} else if (isTypeOnlyImport && isTypeGroupInGroups && !isSortingTypesAmongThemselves) {
526+
} else if (isTypeOnlyImport && isTypeGroupInGroups && !isSortingTypesGroup) {
527527
impType = 'type';
528528
} else {
529529
impType = importType(importEntry.value, context);
@@ -537,7 +537,7 @@ function computeRank(context, ranks, importEntry, excludedImportTypes, isSorting
537537
rank = ranks.groups[impType];
538538
}
539539

540-
if (isTypeOnlyImport && isSortingTypesAmongThemselves) {
540+
if (isTypeOnlyImport && isSortingTypesGroup) {
541541
rank = ranks.groups['type'] + rank / 10;
542542
}
543543

@@ -548,8 +548,8 @@ function computeRank(context, ranks, importEntry, excludedImportTypes, isSorting
548548
return rank;
549549
}
550550

551-
function registerNode(context, importEntry, ranks, imported, excludedImportTypes, isSortingTypesAmongThemselves) {
552-
const rank = computeRank(context, ranks, importEntry, excludedImportTypes, isSortingTypesAmongThemselves);
551+
function registerNode(context, importEntry, ranks, imported, excludedImportTypes, isSortingTypesGroup) {
552+
const rank = computeRank(context, ranks, importEntry, excludedImportTypes, isSortingTypesGroup);
553553
if (rank !== -1) {
554554
imported.push({ ...importEntry, rank });
555555
}
@@ -793,7 +793,7 @@ module.exports = {
793793
'never',
794794
],
795795
},
796-
sortTypesAmongThemselves: {
796+
sortTypesGroup: {
797797
type: 'boolean',
798798
default: false,
799799
},
@@ -853,7 +853,7 @@ module.exports = {
853853
const options = context.options[0] || {};
854854
const newlinesBetweenImports = options['newlines-between'] || 'ignore';
855855
const pathGroupsExcludedImportTypes = new Set(options.pathGroupsExcludedImportTypes || ['builtin', 'external', 'object']);
856-
const sortTypesAmongThemselves = options.sortTypesAmongThemselves;
856+
const sortTypesGroup = options.sortTypesGroup;
857857

858858
const named = {
859859
types: 'mixed',
@@ -897,7 +897,7 @@ module.exports = {
897897
const exportMap = new Map();
898898

899899
const isTypeGroupInGroups = ranks.omittedTypes.indexOf('type') === -1;
900-
const isSortingTypesAmongThemselves = isTypeGroupInGroups && sortTypesAmongThemselves;
900+
const isSortingTypesGroup = isTypeGroupInGroups && sortTypesGroup;
901901

902902
function getBlockImports(node) {
903903
if (!importMap.has(node)) {
@@ -952,7 +952,7 @@ module.exports = {
952952
ranks,
953953
getBlockImports(node.parent),
954954
pathGroupsExcludedImportTypes,
955-
isSortingTypesAmongThemselves
955+
isSortingTypesGroup
956956
);
957957

958958
if (named.import) {
@@ -1004,7 +1004,7 @@ module.exports = {
10041004
ranks,
10051005
getBlockImports(node.parent),
10061006
pathGroupsExcludedImportTypes,
1007-
isSortingTypesAmongThemselves
1007+
isSortingTypesGroup
10081008
);
10091009
},
10101010
CallExpression(node) {
@@ -1027,7 +1027,7 @@ module.exports = {
10271027
ranks,
10281028
getBlockImports(block),
10291029
pathGroupsExcludedImportTypes,
1030-
isSortingTypesAmongThemselves
1030+
isSortingTypesGroup
10311031
);
10321032
},
10331033
...named.require && {

tests/src/rules/order.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,7 +3285,7 @@ context('TypeScript', function () {
32853285
}],
32863286
}),
32873287
] : [],
3288-
// Option sortTypesAmongThemselves: false (default)
3288+
// Option sortTypesGroup: false (default)
32893289
test({
32903290
code: `
32913291
import c from 'Bar';
@@ -3343,11 +3343,11 @@ context('TypeScript', function () {
33433343
],
33443344
'newlines-between': 'always',
33453345
pathGroupsExcludedImportTypes: [],
3346-
sortTypesAmongThemselves: false,
3346+
sortTypesGroup: false,
33473347
},
33483348
],
33493349
}),
3350-
// Option sortTypesAmongThemselves: true and 'type' in pathGroupsExcludedImportTypes
3350+
// Option sortTypesGroup: true and 'type' in pathGroupsExcludedImportTypes
33513351
test({
33523352
code: `
33533353
import c from 'Bar';
@@ -3375,11 +3375,11 @@ context('TypeScript', function () {
33753375
],
33763376
'newlines-between': 'always',
33773377
pathGroupsExcludedImportTypes: ['type'],
3378-
sortTypesAmongThemselves: true,
3378+
sortTypesGroup: true,
33793379
},
33803380
],
33813381
}),
3382-
// Option sortTypesAmongThemselves: true and 'type' omitted from groups
3382+
// Option sortTypesGroup: true and 'type' omitted from groups
33833383
test({
33843384
code: `
33853385
import c from 'Bar';
@@ -3407,7 +3407,7 @@ context('TypeScript', function () {
34073407
'newlines-between': 'always',
34083408
pathGroupsExcludedImportTypes: [],
34093409
// Becomes a no-op without "type" in groups
3410-
sortTypesAmongThemselves: true,
3410+
sortTypesGroup: true,
34113411
},
34123412
],
34133413
}),
@@ -3440,7 +3440,7 @@ context('TypeScript', function () {
34403440
},
34413441
],
34423442
}),
3443-
// Option: sortTypesAmongThemselves: true puts type imports in the same order as regular imports (from issue #2441, PR #2615)
3443+
// Option: sortTypesGroup: true puts type imports in the same order as regular imports (from issue #2441, PR #2615)
34443444
test({
34453445
code: `
34463446
import type A from "fs";
@@ -3463,7 +3463,7 @@ context('TypeScript', function () {
34633463
order: 'asc',
34643464
caseInsensitive: true,
34653465
},
3466-
sortTypesAmongThemselves: true,
3466+
sortTypesGroup: true,
34673467
},
34683468
],
34693469
}),

0 commit comments

Comments
 (0)