Skip to content

Commit 5de039c

Browse files
hyobanSukkaW
andauthoredOct 30, 2024··
fix: support namespace type import (#168)
Co-authored-by: SukkaW <isukkaw@gmail.com>
1 parent 9c58269 commit 5de039c

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed
 

‎.changeset/tame-ants-thank.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
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.

‎src/rules/no-duplicates.ts

+8
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export = createRule<[Options?], MessageId>({
444444
imported: Map<string, TSESTree.ImportDeclaration[]>
445445
nsImported: Map<string, TSESTree.ImportDeclaration[]>
446446
defaultTypesImported: Map<string, TSESTree.ImportDeclaration[]>
447+
namespaceTypesImported: Map<string, TSESTree.ImportDeclaration[]>
447448
namedTypesImported: Map<string, TSESTree.ImportDeclaration[]>
448449
}
449450
>()
@@ -458,6 +459,7 @@ export = createRule<[Options?], MessageId>({
458459
imported: new Map(),
459460
nsImported: new Map(),
460461
defaultTypesImported: new Map(),
462+
namespaceTypesImported: new Map(),
461463
namedTypesImported: new Map(),
462464
}
463465
moduleMaps.set(parent, map)
@@ -470,6 +472,12 @@ export = createRule<[Options?], MessageId>({
470472
) {
471473
return map.defaultTypesImported
472474
}
475+
if (
476+
n.specifiers.length > 0 &&
477+
n.specifiers[0].type === 'ImportNamespaceSpecifier'
478+
) {
479+
return map.namespaceTypesImported
480+
}
473481

474482
if (!preferInline) {
475483
return map.namedTypesImported

‎test/rules/no-duplicates.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ describe('TypeScript', () => {
631631
code: "import type { x } from './foo'; import y from './foo'",
632632
...parserConfig,
633633
}),
634+
test({
635+
code: "import type { x } from './foo'; import type * as y from './foo'",
636+
...parserConfig,
637+
}),
634638
test({
635639
code: "import type x from './foo'; import type y from './bar'",
636640
...parserConfig,

0 commit comments

Comments
 (0)
Please sign in to comment.