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

Commit9abf816

Browse files
committed
try this way instead
1 parent4d5d116 commit9abf816

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

‎src/rules/no-duplicates.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,26 @@ function getInlineTypeFix(nodes, sourceCode) {
107107
constnodeClosingBrace=nodeTokens[nodeClosingBraceIndex];
108108
consttokenBeforeClosingBrace=nodeTokens[nodeClosingBraceIndex-1];
109109
if(nodeClosingBrace){
110-
if(rest.length&&isComma(tokenBeforeClosingBrace)){
111-
fixes.push(fixer.remove(tokenBeforeClosingBrace));
112-
}
110+
constspecifiers=[];
113111
rest.forEach((node)=>{
114112
// these will be all Type imports, no Value specifiers
115113
// then add inline type specifiers to importKind === 'type' import
116114
node.specifiers.forEach((specifier)=>{
117115
if(specifier.importKind==='type'){
118-
fixes.push(fixer.insertTextBefore(nodeClosingBrace,`,type${specifier.local.name}`));
116+
specifiers.push(`type${specifier.local.name}`);
119117
}else{
120-
fixes.push(fixer.insertTextBefore(nodeClosingBrace,`,${specifier.local.name}`));
118+
specifiers.push(specifier.local.name);
121119
}
122120
});
123121

124122
fixes.push(fixer.remove(node));
125123
});
124+
125+
if(isComma(tokenBeforeClosingBrace)){
126+
fixes.push(fixer.insertTextBefore(nodeClosingBrace,`${specifiers.join(', ')}`));
127+
}else{
128+
fixes.push(fixer.insertTextBefore(nodeClosingBrace,`,${specifiers.join(', ')}`));
129+
}
126130
}else{
127131
// we have a default import only
128132
constdefaultSpecifier=firstImport.specifiers.find((spec)=>spec.type==='ImportDefaultSpecifier');

‎tests/src/rules/no-duplicates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ context('TypeScript', function () {
10391039
code:"import { type C, } from './foo';import {AValue, BValue, } from './foo';",
10401040
...parserConfig,
10411041
options:[{'prefer-inline':true}],
1042-
output:"import { type C , AValue, BValue} from './foo';",
1042+
output:"import { type C, AValue, BValue} from './foo';",
10431043
errors:[
10441044
{
10451045
line:1,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp