Skip to content

Commit 38d0081

Browse files
authored
Fix incorrect no-duplicates prefer-inline default type import handling (#162)
1 parent b43350c commit 38d0081

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

.changeset/mighty-ladybugs-agree.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-import-x': patch
3+
---
4+
5+
Fix issue where `no-duplicates` rule with `prefer-inline` incorrectly marks default type and named type imports as duplicates

src/rules/no-duplicates.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,19 @@ export = createRule<[Options?], MessageId>({
463463
moduleMaps.set(parent, map)
464464
}
465465

466-
if (!preferInline && n.importKind === 'type') {
467-
return n.specifiers.length > 0 &&
466+
if (n.importKind === 'type') {
467+
if (
468+
n.specifiers.length > 0 &&
468469
n.specifiers[0].type === 'ImportDefaultSpecifier'
469-
? map.defaultTypesImported
470-
: map.namedTypesImported
470+
) {
471+
return map.defaultTypesImported
472+
}
473+
474+
if (!preferInline) {
475+
return map.namedTypesImported
476+
}
471477
}
478+
472479
if (
473480
!preferInline &&
474481
n.specifiers.some(

test/rules/no-duplicates.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,21 @@ describe('TypeScript', () => {
682682
...parserConfig,
683683
}),
684684
]),
685+
test({
686+
code: "import type { A } from 'foo';import type B from 'foo';",
687+
...parserConfig,
688+
options: [{ 'prefer-inline': true }],
689+
}),
690+
test({
691+
code: "import { type A } from 'foo';import type B from 'foo';",
692+
...parserConfig,
693+
options: [{ 'prefer-inline': true }],
694+
}),
695+
test({
696+
code: "import type A from 'foo';import { B } from 'foo';",
697+
...parserConfig,
698+
options: [{ 'prefer-inline': true }],
699+
}),
685700
]
686701

687702
const invalid = [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy