Skip to content

Commit de7c535

Browse files
committed
try this way instead
1 parent 7f535b2 commit de7c535

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
@@ -109,22 +109,26 @@ function getInlineTypeFix(nodes, sourceCode) {
109109
const nodeClosingBrace = nodeTokens[nodeClosingBraceIndex];
110110
const tokenBeforeClosingBrace = nodeTokens[nodeClosingBraceIndex - 1];
111111
if (nodeClosingBrace) {
112-
if (rest.length && isComma(tokenBeforeClosingBrace)) {
113-
fixes.push(fixer.remove(tokenBeforeClosingBrace));
114-
}
112+
const specifiers = [];
115113
rest.forEach((node) => {
116114
// these will be all Type imports, no Value specifiers
117115
// then add inline type specifiers to importKind === 'type' import
118116
node.specifiers.forEach((specifier) => {
119117
if (specifier.importKind === 'type') {
120-
fixes.push(fixer.insertTextBefore(nodeClosingBrace, `, type ${specifier.local.name}`));
118+
specifiers.push(`type ${specifier.local.name}`);
121119
} else {
122-
fixes.push(fixer.insertTextBefore(nodeClosingBrace, `, ${specifier.local.name}`));
120+
specifiers.push(specifier.local.name);
123121
}
124122
});
125123

126124
fixes.push(fixer.remove(node));
127125
});
126+
127+
if (isComma(tokenBeforeClosingBrace)) {
128+
fixes.push(fixer.insertTextBefore(nodeClosingBrace, ` ${specifiers.join(', ')}`));
129+
} else {
130+
fixes.push(fixer.insertTextBefore(nodeClosingBrace, `, ${specifiers.join(', ')}`));
131+
}
128132
} else {
129133
// we have a default import only
130134
const defaultSpecifier = 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)