Skip to content

Commit 32e9b55

Browse files
fix(no-duplicates): merge type import as with value import (#204)
1 parent ac6d2e1 commit 32e9b55

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

.changeset/tasty-llamas-deny.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
fix type-import and value-import merging when import-as is used

src/rules/no-duplicates.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function getFix(
152152
sourceCode.text
153153
.slice(openBrace.range[1], closeBrace.range[0])
154154
.split(',')
155-
.map(x => x.trim()),
155+
.map(x => x.split(' as ')[0].trim()),
156156
)
157157

158158
const [specifiersText] = specifiers.reduce(

test/rules/no-duplicates.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,24 @@ describe('TypeScript', () => {
818818
},
819819
],
820820
}),
821+
tInvalid({
822+
code: "import type { AType as BType } from './foo'; import { CValue } from './foo'",
823+
...parserConfig,
824+
options: [{ 'prefer-inline': true }],
825+
output: `import { type AType as BType , CValue } from './foo'; `,
826+
errors: [
827+
{
828+
...createDuplicatedError('./foo'),
829+
line: 1,
830+
column: 37,
831+
},
832+
{
833+
...createDuplicatedError('./foo'),
834+
line: 1,
835+
column: 69,
836+
},
837+
],
838+
}),
821839
]),
822840
]
823841

0 commit comments

Comments
 (0)