diff --git a/.changeset/mighty-ladybugs-agree.md b/.changeset/mighty-ladybugs-agree.md new file mode 100644 index 000000000..552ec8214 --- /dev/null +++ b/.changeset/mighty-ladybugs-agree.md @@ -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 diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts index b706541aa..334b2071b 100644 --- a/src/rules/no-duplicates.ts +++ b/src/rules/no-duplicates.ts @@ -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( diff --git a/test/rules/no-duplicates.spec.ts b/test/rules/no-duplicates.spec.ts index 3be9b76dd..1fb645d59 100644 --- a/test/rules/no-duplicates.spec.ts +++ b/test/rules/no-duplicates.spec.ts @@ -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 = [