@@ -33,6 +33,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
3333 'Avoid using multiple assertions within `waitFor` callback' ,
3434 } ,
3535 schema : [ ] ,
36+ fixable : 'code' ,
3637 } ,
3738 defaultOptions : [ ] ,
3839 create ( context , _ , helpers ) {
@@ -108,6 +109,37 @@ export default createTestingLibraryRule<Options, MessageIds>({
108109 context . report ( {
109110 node : expressionStatement ,
110111 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+ } ,
111143 } ) ;
112144 }
113145 }
0 commit comments