Skip to content

Commit

Permalink
try this way instead
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Feb 19, 2023
1 parent 4d5d116 commit 9abf816
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/rules/no-duplicates.js
Expand Up @@ -107,22 +107,26 @@ function getInlineTypeFix(nodes, sourceCode) {
const nodeClosingBrace = nodeTokens[nodeClosingBraceIndex];
const tokenBeforeClosingBrace = nodeTokens[nodeClosingBraceIndex - 1];
if (nodeClosingBrace) {
if (rest.length && isComma(tokenBeforeClosingBrace)) {
fixes.push(fixer.remove(tokenBeforeClosingBrace));
}
const specifiers = [];
rest.forEach((node) => {
// these will be all Type imports, no Value specifiers
// then add inline type specifiers to importKind === 'type' import
node.specifiers.forEach((specifier) => {
if (specifier.importKind === 'type') {
fixes.push(fixer.insertTextBefore(nodeClosingBrace, `, type ${specifier.local.name}`));
specifiers.push(`type ${specifier.local.name}`);
} else {
fixes.push(fixer.insertTextBefore(nodeClosingBrace, `, ${specifier.local.name}`));
specifiers.push(specifier.local.name);
}
});

fixes.push(fixer.remove(node));
});

if (isComma(tokenBeforeClosingBrace)) {
fixes.push(fixer.insertTextBefore(nodeClosingBrace, ` ${specifiers.join(', ')}`));
} else {
fixes.push(fixer.insertTextBefore(nodeClosingBrace, `, ${specifiers.join(', ')}`));
}
} else {
// we have a default import only
const defaultSpecifier = firstImport.specifiers.find((spec) => spec.type === 'ImportDefaultSpecifier');
Expand Down
2 changes: 1 addition & 1 deletion tests/src/rules/no-duplicates.js
Expand Up @@ -1039,7 +1039,7 @@ context('TypeScript', function () {
code: "import { type C, } from './foo';import {AValue, BValue, } from './foo';",
...parserConfig,
options: [{ 'prefer-inline': true }],
output: "import { type C , AValue, BValue} from './foo';",
output: "import { type C, AValue, BValue} from './foo';",
errors: [
{
line: 1,
Expand Down

0 comments on commit 9abf816

Please sign in to comment.