From c52f8f7f838e88eba6b1065ec8a28ec95d923d46 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:42:00 +0800 Subject: [PATCH 1/2] fix: support namespace type import --- .changeset/tame-ants-thank.md | 5 +++++ src/rules/no-duplicates.ts | 8 ++++++++ test/rules/no-duplicates.spec.ts | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 .changeset/tame-ants-thank.md diff --git a/.changeset/tame-ants-thank.md b/.changeset/tame-ants-thank.md new file mode 100644 index 0000000000..ba3dc1a70a --- /dev/null +++ b/.changeset/tame-ants-thank.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-import-x": patch +--- + +support namespace type import diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts index 334b2071bc..2ed7cb5039 100644 --- a/src/rules/no-duplicates.ts +++ b/src/rules/no-duplicates.ts @@ -444,6 +444,7 @@ export = createRule<[Options?], MessageId>({ imported: Map nsImported: Map defaultTypesImported: Map + namespaceTypesImported: Map namedTypesImported: Map } >() @@ -458,6 +459,7 @@ export = createRule<[Options?], MessageId>({ imported: new Map(), nsImported: new Map(), defaultTypesImported: new Map(), + namespaceTypesImported: new Map(), namedTypesImported: new Map(), } moduleMaps.set(parent, map) @@ -470,6 +472,12 @@ export = createRule<[Options?], MessageId>({ ) { return map.defaultTypesImported } + if ( + n.specifiers.length > 0 && + n.specifiers[0].type === 'ImportNamespaceSpecifier' + ) { + return map.namespaceTypesImported + } if (!preferInline) { return map.namedTypesImported diff --git a/test/rules/no-duplicates.spec.ts b/test/rules/no-duplicates.spec.ts index 1fb645d595..7aecacb1fd 100644 --- a/test/rules/no-duplicates.spec.ts +++ b/test/rules/no-duplicates.spec.ts @@ -631,6 +631,10 @@ describe('TypeScript', () => { code: "import type { x } from './foo'; import y from './foo'", ...parserConfig, }), + test({ + code: "import type { x } from './foo'; import type * as y from './foo'", + ...parserConfig, + }), test({ code: "import type x from './foo'; import type y from './bar'", ...parserConfig, From f088751be88b682aa9853785dc441121e7081512 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 30 Oct 2024 21:06:11 +0800 Subject: [PATCH 2/2] chore: update changeset --- .changeset/tame-ants-thank.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tame-ants-thank.md b/.changeset/tame-ants-thank.md index ba3dc1a70a..302c495569 100644 --- a/.changeset/tame-ants-thank.md +++ b/.changeset/tame-ants-thank.md @@ -2,4 +2,4 @@ "eslint-plugin-import-x": patch --- -support namespace type import +Fixes https://github.com/un-ts/eslint-plugin-import-x/issues/167, the `no-duplicates` rule now allows co-existing inline type imports and namespace imports.