Skip to content

Commit 7b42ee0

Browse files
committed
chore: enhance
1 parent dd1f012 commit 7b42ee0

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/rules/order.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,22 @@ const categories = {
4646
type Category = keyof typeof categories
4747

4848
const defaultGroups = [
49-
'private-import',
5049
'builtin',
5150
'external',
5251
'parent',
5352
'sibling',
5453
'index',
5554
] as const
5655

56+
const defaultGroupsOfficialOrganizeImports = [
57+
'private-import',
58+
'external',
59+
'builtin',
60+
'parent',
61+
'sibling',
62+
'index',
63+
] as const
64+
5765
// REPORTING AND FIXING
5866

5967
function reverse(array: ImportEntryWithRank[]): ImportEntryWithRank[] {
@@ -1398,8 +1406,8 @@ export default createRule<[Options?], MessageId>({
13981406
const { groups, omittedTypes } = convertGroupsToRanks(
13991407
options.groups ||
14001408
(options.privateImportsFeatureFlag
1401-
? defaultGroups
1402-
: defaultGroups.slice(1)),
1409+
? defaultGroupsOfficialOrganizeImports
1410+
: defaultGroups),
14031411
)
14041412
ranks = {
14051413
groups,

test/rules/order.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4813,9 +4813,9 @@ describe('TypeScript', () => {
48134813
tValid({
48144814
code: `import { internA } from "#a";
48154815
import { scopeA } from "@a/a";
4816+
import fs from 'node:fs';
4817+
import path from "path";
48164818
import { localA } from "./a";
4817-
4818-
console.log({ internA, scopeA, localA });
48194819
`,
48204820
...parserConfig,
48214821
options: [
@@ -5207,6 +5207,30 @@ console.log({ internA, scopeA, localA });
52075207
// { message: '`node:fs/promises` import should occur before import of `express`' },
52085208
],
52095209
}),
5210+
// By default it should order same as TS LSP (issue-286)
5211+
tInvalid({
5212+
code: `import { scopeA } from "@a/a";
5213+
import fs from 'node:fs';
5214+
import path from "path";
5215+
import { localA } from "./a";
5216+
import { internA } from "#a";
5217+
`,
5218+
output: `import { internA } from "#a";
5219+
import { scopeA } from "@a/a";
5220+
import fs from 'node:fs';
5221+
import path from "path";
5222+
import { localA } from "./a";
5223+
`,
5224+
...parserConfig,
5225+
options: [
5226+
{
5227+
privateImportsFeatureFlag: true,
5228+
},
5229+
],
5230+
errors: [
5231+
createOrderError(['`#a` import', 'before', 'import of `@a/a`']),
5232+
],
5233+
}),
52105234
],
52115235
})
52125236
}

0 commit comments

Comments
 (0)