1+ import { isAwaitExpression } from '@typescript-eslint/utils/ast-utils' ;
2+
13import { createTestingLibraryRule } from '../create-testing-library-rule' ;
24import {
35 getPropertyIdentifierNode ,
@@ -8,6 +10,7 @@ import {
810 isSequenceExpression ,
911 hasThenProperty ,
1012} from '../node-utils' ;
13+ import { getSourceCode } from '../utils' ;
1114
1215import type { TSESTree } from '@typescript-eslint/utils' ;
1316
@@ -35,6 +38,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
3538 'Avoid using side effects within `waitFor` callback' ,
3639 } ,
3740 schema : [ ] ,
41+ fixable : 'code' ,
3842 } ,
3943 defaultOptions : [ ] ,
4044 create ( context , _ , helpers ) {
@@ -209,10 +213,15 @@ export default createTestingLibraryRule<Options, MessageIds>({
209213 }
210214
211215 function reportImplicitReturnSideEffect (
212- node :
216+ node : (
213217 | TSESTree . AssignmentExpression
214218 | TSESTree . CallExpression
215219 | TSESTree . SequenceExpression
220+ ) & {
221+ parent : TSESTree . ArrowFunctionExpression & {
222+ parent : TSESTree . CallExpression ;
223+ } ;
224+ }
216225 ) {
217226 if ( ! isCallerWaitFor ( node ) ) {
218227 return ;
@@ -242,6 +251,14 @@ export default createTestingLibraryRule<Options, MessageIds>({
242251 context . report ( {
243252 node,
244253 messageId : 'noSideEffectsWaitFor' ,
254+ fix : ( fixer ) => {
255+ const { parent : callExpressionNode } = node . parent ;
256+ const targetNode = isAwaitExpression ( callExpressionNode . parent )
257+ ? callExpressionNode . parent
258+ : callExpressionNode ;
259+ const sourceCode = getSourceCode ( context ) ;
260+ return fixer . replaceText ( targetNode , sourceCode . getText ( node ) ) ;
261+ } ,
245262 } ) ;
246263 }
247264
0 commit comments