Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite91bb87

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 parentab7c625 commite91bb87

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
constimportExportType1=getImportExportType(node1);
6767
constimportExportType2=getImportExportType(node2);
6868

69+
if(
70+
(node1.importKind==="type"||node1.exportKind==="type")&&
71+
(node2.importKind==="type"||node2.exportKind==="type")
72+
){
73+
constisDefault1=importExportType1==="ImportDefaultSpecifier";
74+
constisDefault2=importExportType2==="ImportDefaultSpecifier";
75+
constisNamed1=isImportExportSpecifier(importExportType1,"named");
76+
constisNamed2=isImportExportSpecifier(importExportType2,"named");
77+
78+
if((isDefault1&&isNamed2)||(isDefault2&&isNamed1)){
79+
returnfalse;
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)

[8]ページ先頭

©2009-2025 Movatter.jp