@@ -43,7 +43,6 @@ function createNodeSwapper(context: UtilRuleContext<string, RuleOptions>) {
43
43
*/
44
44
function getLineRange ( node : TSESTree . Comment ) : TSESTree . Range {
45
45
const [ start ] = getRangeWithIndent ( node ) ;
46
- // TODO check SourceCode own methods
47
46
const index = sourceCode . lineStartIndices . findIndex ( n => start === n ) ;
48
47
49
48
if ( index < 0 ) {
@@ -63,14 +62,11 @@ function createNodeSwapper(context: UtilRuleContext<string, RuleOptions>) {
63
62
return sourceCode . text . slice ( ...getIndentRange ( node ) ) ;
64
63
}
65
64
66
- function getNodePunctuator ( token : TSESTree . Token ) {
67
- const punctuator =
68
- token . type === AST_TOKEN_TYPES . Punctuator
69
- ? token
70
- : sourceCode . getTokenAfter ( token , {
71
- filter : n => n . type === AST_TOKEN_TYPES . Punctuator && n . value !== ':' ,
72
- includeComments : false ,
73
- } ) ;
65
+ function getNodePunctuator ( node : TSESTree . Node ) {
66
+ const punctuator = sourceCode . getTokenAfter ( node , {
67
+ filter : n => n . type === AST_TOKEN_TYPES . Punctuator && n . value !== ':' ,
68
+ includeComments : false ,
69
+ } ) ;
74
70
75
71
// Check the punctuator value outside of filter because we
76
72
// want to stop traversal on any terminating punctuator
@@ -83,17 +79,18 @@ function createNodeSwapper(context: UtilRuleContext<string, RuleOptions>) {
83
79
currentNode : TSType ,
84
80
replaceNode : TSType ,
85
81
) =>
86
- [ currentNode , replaceNode ] . reduce ( ( acc , node ) => {
82
+ [ currentNode , replaceNode ] . reduce < RuleFix [ ] > ( ( acc , node ) => {
87
83
const otherNode = node === currentNode ? replaceNode : currentNode ;
88
84
const comments = sourceCode . getCommentsBefore ( node ) ;
89
85
const nextSibling = sourceCode . getTokenAfter ( node ) ;
90
86
const isLastReplacingLast =
91
87
nodePositions . get ( node ) . final === nodePositions . size - 1 &&
92
88
nodePositions . get ( node ) . final === nodePositions . get ( otherNode ) . initial ;
93
89
94
- let text = `${ comments . length ? getIndentText ( node ) : '' } ${ sourceCode . getText (
95
- node ,
96
- ) } `;
90
+ let text = [
91
+ comments . length ? getIndentText ( node ) : '' ,
92
+ sourceCode . getText ( node ) ,
93
+ ] . join ( '' ) ;
97
94
98
95
// If nextSibling is the node punctuator, remove it
99
96
if ( nextSibling === getNodePunctuator ( node ) ) {
@@ -116,7 +113,7 @@ function createNodeSwapper(context: UtilRuleContext<string, RuleOptions>) {
116
113
fixer . insertTextBefore (
117
114
otherNode ,
118
115
comments
119
- . map ( c => sourceCode . getText ( c ) )
116
+ . map ( comment => sourceCode . getText ( comment as any ) )
120
117
. concat ( '' )
121
118
. join ( '\n' ) ,
122
119
) ,
@@ -133,7 +130,7 @@ function createNodeSwapper(context: UtilRuleContext<string, RuleOptions>) {
133
130
) ;
134
131
135
132
return acc ;
136
- } , [ ] as RuleFix [ ] ) ;
133
+ } , [ ] ) ;
137
134
}
138
135
139
136
export function createReporter < MessageIds extends string > (
0 commit comments