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

Commit3025495

Browse files
committed
one bugfix with trailing commas
1 parent806a0f8 commit3025495

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

‎src/rules/no-duplicates.js‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,24 @@ function getInlineTypeFix(nodes, sourceCode) {
9292
returnfixer=>{
9393
constfixes=[];
9494

95-
// if (!semver.satisfies(typescriptPkg.version, '>= 4.5')) {
96-
// throw new Error('Your version of TypeScript does not support inline type imports.');
97-
// }
98-
9995
// push to first import
10096
let[firstImport, ...rest]=nodes;
101-
constvalueImport=nodes.find((n)=>n.specifiers.every((spec)=>spec.importKind==='value'))||nodes.find((n)=>n.specifiers.some((spec)=>spec.type==='ImportDefaultSpecifier'));
97+
// const valueImport = nodes.find((n) => n.specifiers.every((spec) => spec.importKind === 'value')) || nodes.find((n) => n.specifiers.some((spec) => spec.type === 'ImportDefaultSpecifier'));
98+
constvalueImport=nodes.find((n)=>n.specifiers.some((spec)=>spec.type==='ImportDefaultSpecifier'));
10299
if(valueImport){
103100
firstImport=valueImport;
104101
rest=nodes.filter((n)=>n!==firstImport);
105102
}
106103

107104
constnodeTokens=sourceCode.getTokens(firstImport);
108105
// we are moving the rest of the Type or Inline Type imports here.
109-
constnodeClosingBrace=nodeTokens.find(token=>isPunctuator(token,'}'));
110-
// const preferInline = context.options[0] && context.options[0]['prefer-inline'];
106+
constnodeClosingBraceIndex=nodeTokens.findIndex(token=>isPunctuator(token,'}'));
107+
constnodeClosingBrace=nodeTokens[nodeClosingBraceIndex];
108+
constpreviousToken=nodeTokens[nodeClosingBraceIndex-1];
111109
if(nodeClosingBrace){
110+
if(rest.length&&isComma(previousToken)){
111+
fixes.push(fixer.remove(previousToken));
112+
}
112113
rest.forEach((node)=>{
113114
// these will be all Type imports, no Value specifiers
114115
// then add inline type specifiers to importKind === 'type' import

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,23 @@ context('TypeScript', function () {
614614
},
615615
],
616616
}),
617+
test({
618+
code:"import {type x} from './foo'; import {y} from './foo'",
619+
...parserConfig,
620+
output:`import {type x, y} from './foo'; `,
621+
errors:[
622+
{
623+
line:1,
624+
column:22,
625+
message:"'./foo' imported multiple times.",
626+
},
627+
{
628+
line:1,
629+
column:47,
630+
message:"'./foo' imported multiple times.",
631+
},
632+
],
633+
}),
617634
].concat(!tsVersionSatisfies('>= 4.5')||!typescriptEslintParserSatisfies('>= 5.7.0') ?[] :[
618635
// without prefer-inline, will dedupe with type import kind
619636
test({
@@ -1018,6 +1035,24 @@ context('TypeScript', function () {
10181035
},
10191036
],
10201037
}),
1038+
test({
1039+
code:"import { type C, } from './foo';import {AValue, BValue, } from './foo';",
1040+
...parserConfig,
1041+
options:[{'prefer-inline':true}],
1042+
output:"import { type C , AValue, BValue} from './foo';",
1043+
errors:[
1044+
{
1045+
line:1,
1046+
column:25,
1047+
message:"'./foo' imported multiple times.",
1048+
},
1049+
{
1050+
line:1,
1051+
column:64,
1052+
message:"'./foo' imported multiple times.",
1053+
},
1054+
],
1055+
}),
10211056
]);
10221057

10231058
ruleTester.run('no-duplicates',rule,{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp