Skip to content

Commit e91bb87

Browse files
authored
fix: allow separate default and named type imports (#19899)
* fix: allow separate default and named type imports in no-duplicate-imports * fix default import and named export
1 parent ab7c625 commit e91bb87

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

lib/rules/no-duplicate-imports.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ function isImportExportCanBeMerged(node1, node2) {
6666
const importExportType1 = getImportExportType(node1);
6767
const importExportType2 = getImportExportType(node2);
6868

69+
if (
70+
(node1.importKind === "type" || node1.exportKind === "type") &&
71+
(node2.importKind === "type" || node2.exportKind === "type")
72+
) {
73+
const isDefault1 = importExportType1 === "ImportDefaultSpecifier";
74+
const isDefault2 = importExportType2 === "ImportDefaultSpecifier";
75+
const isNamed1 = isImportExportSpecifier(importExportType1, "named");
76+
const isNamed2 = isImportExportSpecifier(importExportType2, "named");
77+
78+
if ((isDefault1 && isNamed2) || (isDefault2 && isNamed1)) {
79+
return false;
80+
}
81+
}
82+
6983
if (
7084
(importExportType1 === "ExportAll" &&
7185
importExportType2 !== "ExportAll" &&

tests/lib/rules/no-duplicate-imports.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ ruleTesterTypeScript.run("no-duplicate-imports", rule, {
247247
'import type * as Bar from "os";\nimport { type Baz } from "os";',
248248
'import foo, * as bar from "os";\nimport { type Baz } from "os";',
249249
'import foo, { type bar } from "os";\nimport type * as Baz from "os";',
250+
'import type { Merge } from "lodash-es";\nimport type _ from "lodash-es";',
250251
{
251252
code: 'import type Os from "os";\nexport { type Hello } from "hello";',
252253
options: [{ includeExports: true }],
@@ -283,6 +284,10 @@ ruleTesterTypeScript.run("no-duplicate-imports", rule, {
283284
code: 'import type Os from "os";\nexport * from "os";',
284285
options: [{ includeExports: true }],
285286
},
287+
{
288+
code: 'import type Os from "os";\nexport type { Something } from "os";',
289+
options: [{ includeExports: true }],
290+
},
286291
{
287292
code: 'export type { Something } from "os";\nexport * from "os";',
288293
options: [{ includeExports: true }],
@@ -361,16 +366,6 @@ ruleTesterTypeScript.run("no-duplicate-imports", rule, {
361366
},
362367
],
363368
},
364-
{
365-
code: 'import type { Merge } from "lodash-es";\nimport type _ from "lodash-es";',
366-
errors: [
367-
{
368-
messageId: "import",
369-
data: { module: "lodash-es" },
370-
type: "ImportDeclaration",
371-
},
372-
],
373-
},
374369
{
375370
code: 'import type Os from "os";\nimport type { Something } from "os";\nimport type * as Foobar from "os";',
376371
errors: [
@@ -379,11 +374,6 @@ ruleTesterTypeScript.run("no-duplicate-imports", rule, {
379374
data: { module: "os" },
380375
type: "ImportDeclaration",
381376
},
382-
{
383-
messageId: "import",
384-
data: { module: "os" },
385-
type: "ImportDeclaration",
386-
},
387377
],
388378
},
389379
{

0 commit comments

Comments
 (0)