Skip to content

Commit 9abf816

Browse files
committed
try this way instead
1 parent 4d5d116 commit 9abf816

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/rules/no-duplicates.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,26 @@ function getInlineTypeFix(nodes, sourceCode) {
107107
const nodeClosingBrace = nodeTokens[nodeClosingBraceIndex];
108108
const tokenBeforeClosingBrace = nodeTokens[nodeClosingBraceIndex - 1];
109109
if (nodeClosingBrace) {
110-
if (rest.length && isComma(tokenBeforeClosingBrace)) {
111-
fixes.push(fixer.remove(tokenBeforeClosingBrace));
112-
}
110+
const specifiers = [];
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
const defaultSpecifier = firstImport.specifiers.find((spec) => spec.type === 'ImportDefaultSpecifier');

tests/src/rules/no-duplicates.js

+1-1
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)