Skip to content

Commit c05d1b1

Browse files
authored
fix(sort-imports): add submodule imports as internal patterns
1 parent b98c82d commit c05d1b1

3 files changed

Lines changed: 13 additions & 43 deletions

File tree

docs/content/rules/sort-imports.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Controls whether sorting should be done using the path of the import or its firs
261261

262262
### internalPattern
263263

264-
<sub>default: `['^~/.+', '^@/.+']`</sub>
264+
<sub>default: `['^~/.+', '^@/.+', '^#.+']`</sub>
265265

266266
Specifies a pattern for identifying internal imports. This is useful for distinguishing your own modules from external dependencies.
267267

@@ -748,7 +748,7 @@ Specifies whether to use a new experimental dependency detection logic, with red
748748
ignoreCase: true,
749749
specialCharacters: 'keep',
750750
sortBy: 'path',
751-
internalPattern: ['^~/.+', '^@/.+'],
751+
internalPattern: ['^~/.+', '^@/.+', '^#.+'],
752752
partitionByComment: false,
753753
partitionByNewLine: false,
754754
newlinesBetween: 1,
@@ -793,7 +793,7 @@ Specifies whether to use a new experimental dependency detection logic, with red
793793
ignoreCase: true,
794794
specialCharacters: 'keep',
795795
sortBy: 'path',
796-
internalPattern: ['^~/.+', '^@/.+'],
796+
internalPattern: ['^~/.+', '^@/.+', '^#.+'],
797797
partitionByComment: false,
798798
partitionByNewLine: false,
799799
newlinesBetween: 1,

rules/sort-imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ let defaultOptions: Required<Options[number]> = {
101101
'ts-equals-import',
102102
'unknown',
103103
],
104+
internalPattern: ['^~/.+', '^@/.+', '^#.+'],
104105
useExperimentalDependencyDetection: true,
105-
internalPattern: ['^~/.+', '^@/.+'],
106106
fallbackSort: { type: 'unsorted' },
107107
partitionByComment: false,
108108
partitionByNewLine: false,

test/rules/sort-imports.test.ts

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ describe('sort-imports', () => {
602602
})
603603
})
604604

605-
it('handles hash symbol in internal patterns correctly', async () => {
605+
it('marks submodule imports as internal by default', async () => {
606606
await valid({
607607
code: dedent`
608608
import type { T } from 'a'
@@ -616,12 +616,7 @@ describe('sort-imports', () => {
616616
617617
import { d } from '../d'
618618
`,
619-
options: [
620-
{
621-
...options,
622-
internalPattern: ['#.+'],
623-
},
624-
],
619+
options: [options],
625620
})
626621

627622
await invalid({
@@ -658,12 +653,7 @@ describe('sort-imports', () => {
658653
659654
import { d } from '../d'
660655
`,
661-
options: [
662-
{
663-
...options,
664-
internalPattern: ['#.+'],
665-
},
666-
],
656+
options: [options],
667657
})
668658
})
669659

@@ -4222,7 +4212,7 @@ describe('sort-imports', () => {
42224212
})
42234213
})
42244214

4225-
it('handles hash symbol in internal patterns correctly', async () => {
4215+
it('marks submodule imports as internal by default', async () => {
42264216
await valid({
42274217
code: dedent`
42284218
import type { T } from 'a'
@@ -4236,12 +4226,7 @@ describe('sort-imports', () => {
42364226
42374227
import { d } from '../d'
42384228
`,
4239-
options: [
4240-
{
4241-
...options,
4242-
internalPattern: ['#.+'],
4243-
},
4244-
],
4229+
options: [options],
42454230
})
42464231

42474232
await invalid({
@@ -4278,12 +4263,7 @@ describe('sort-imports', () => {
42784263
42794264
import { d } from '../d'
42804265
`,
4281-
options: [
4282-
{
4283-
...options,
4284-
internalPattern: ['#.+'],
4285-
},
4286-
],
4266+
options: [options],
42874267
})
42884268
})
42894269

@@ -7642,7 +7622,7 @@ describe('sort-imports', () => {
76427622
})
76437623
})
76447624

7645-
it('handles hash symbol in internal patterns correctly', async () => {
7625+
it('marks submodule imports as internal by default', async () => {
76467626
await valid({
76477627
code: dedent`
76487628
import type { T } from 'a'
@@ -7656,12 +7636,7 @@ describe('sort-imports', () => {
76567636
76577637
import { d } from '../d'
76587638
`,
7659-
options: [
7660-
{
7661-
...options,
7662-
internalPattern: ['#.+'],
7663-
},
7664-
],
7639+
options: [options],
76657640
})
76667641

76677642
await invalid({
@@ -7698,12 +7673,7 @@ describe('sort-imports', () => {
76987673
76997674
import { d } from '../d'
77007675
`,
7701-
options: [
7702-
{
7703-
...options,
7704-
internalPattern: ['#.+'],
7705-
},
7706-
],
7676+
options: [options],
77077677
})
77087678
})
77097679

0 commit comments

Comments
 (0)