@@ -33,6 +33,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
33
33
'Avoid using multiple assertions within `waitFor` callback' ,
34
34
} ,
35
35
schema : [ ] ,
36
+ fixable : 'code' ,
36
37
} ,
37
38
defaultOptions : [ ] ,
38
39
create ( context , _ , helpers ) {
@@ -108,6 +109,37 @@ export default createTestingLibraryRule<Options, MessageIds>({
108
109
context . report ( {
109
110
node : expressionStatement ,
110
111
messageId : 'noWaitForMultipleAssertion' ,
112
+ fix ( fixer ) {
113
+ const sourceCode = getSourceCode ( context ) ;
114
+
115
+ const lineStart = sourceCode . getIndexFromLoc ( {
116
+ line : expressionStatement . loc . start . line ,
117
+ column : 0 ,
118
+ } ) ;
119
+ const lineEnd = sourceCode . getIndexFromLoc ( {
120
+ line : expressionStatement . loc . end . line + 1 ,
121
+ column : 0 ,
122
+ } ) ;
123
+ const lines = sourceCode . getText ( ) . split ( '\n' ) ;
124
+ const line = lines [ callExpressionNode . loc . start . line - 1 ] ;
125
+ const indent = line . match ( / ^ \s * / ) ?. [ 0 ] ?? '' ;
126
+
127
+ const expressionStatementLines = lines . slice (
128
+ expressionStatement . loc . start . line - 1 ,
129
+ expressionStatement . loc . end . line
130
+ ) ;
131
+ const statementText = expressionStatementLines
132
+ . join ( '\n' )
133
+ . trimStart ( ) ;
134
+
135
+ return [
136
+ fixer . removeRange ( [ lineStart , lineEnd ] ) ,
137
+ fixer . insertTextAfter (
138
+ callExpressionNode ,
139
+ `\n${ indent } ${ statementText } `
140
+ ) ,
141
+ ] ;
142
+ } ,
111
143
} ) ;
112
144
}
113
145
}
0 commit comments