Skip to content

Commit

Permalink
fix: support namespace type import (#168)
Browse files Browse the repository at this point in the history
Co-authored-by: SukkaW <[email protected]>
  • Loading branch information
hyoban and SukkaW authored Oct 30, 2024
1 parent 9c58269 commit 5de039c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-ants-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": patch
---

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.
8 changes: 8 additions & 0 deletions src/rules/no-duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export = createRule<[Options?], MessageId>({
imported: Map<string, TSESTree.ImportDeclaration[]>
nsImported: Map<string, TSESTree.ImportDeclaration[]>
defaultTypesImported: Map<string, TSESTree.ImportDeclaration[]>
namespaceTypesImported: Map<string, TSESTree.ImportDeclaration[]>
namedTypesImported: Map<string, TSESTree.ImportDeclaration[]>
}
>()
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/rules/no-duplicates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5de039c

Please sign in to comment.