Skip to content

Commit

Permalink
Fix incorrect no-duplicates prefer-inline default type import handling (
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronMoat authored Sep 29, 2024
1 parent b43350c commit 38d0081
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-ladybugs-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-import-x': patch
---

Fix issue where `no-duplicates` rule with `prefer-inline` incorrectly marks default type and named type imports as duplicates
15 changes: 11 additions & 4 deletions src/rules/no-duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,19 @@ export = createRule<[Options?], MessageId>({
moduleMaps.set(parent, map)
}

if (!preferInline && n.importKind === 'type') {
return n.specifiers.length > 0 &&
if (n.importKind === 'type') {
if (
n.specifiers.length > 0 &&
n.specifiers[0].type === 'ImportDefaultSpecifier'
? map.defaultTypesImported
: map.namedTypesImported
) {
return map.defaultTypesImported
}

if (!preferInline) {
return map.namedTypesImported
}
}

if (
!preferInline &&
n.specifiers.some(
Expand Down
15 changes: 15 additions & 0 deletions test/rules/no-duplicates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,21 @@ describe('TypeScript', () => {
...parserConfig,
}),
]),
test({
code: "import type { A } from 'foo';import type B from 'foo';",
...parserConfig,
options: [{ 'prefer-inline': true }],
}),
test({
code: "import { type A } from 'foo';import type B from 'foo';",
...parserConfig,
options: [{ 'prefer-inline': true }],
}),
test({
code: "import type A from 'foo';import { B } from 'foo';",
...parserConfig,
options: [{ 'prefer-inline': true }],
}),
]

const invalid = [
Expand Down

0 comments on commit 38d0081

Please sign in to comment.