4
4
*/
5
5
6
6
import { AST_NODE_TYPES , type TSESTree } from '@typescript-eslint/utils' ;
7
+ import type { RuleFix } from '@typescript-eslint/utils/ts-eslint' ;
7
8
import {
8
9
type FunctionExpression ,
9
10
ModifierName ,
@@ -376,14 +377,13 @@ export default createRule<[Options], MessageIds>({
376
377
return [ ] ;
377
378
}
378
379
380
+ const fixes : RuleFix [ ] = [ ] ;
381
+
379
382
if ( ! functionExpression . async ) {
380
383
const targetFunction =
381
384
getNormalizeFunctionExpression ( functionExpression ) ;
382
385
383
- return [
384
- fixer . insertTextBefore ( targetFunction , 'async ' ) ,
385
- fixer . insertTextBefore ( finalNode , 'await ' ) ,
386
- ] ;
386
+ fixes . push ( fixer . insertTextBefore ( targetFunction , 'async ' ) ) ;
387
387
}
388
388
const returnStatement =
389
389
finalNode . parent . type === AST_NODE_TYPES . ReturnStatement
@@ -395,10 +395,13 @@ export default createRule<[Options], MessageIds>({
395
395
getSourceCode ( context ) . getText ( returnStatement ) ;
396
396
const replacedText = sourceCodeText . replace ( 'return' , 'await' ) ;
397
397
398
- return fixer . replaceText ( returnStatement , replacedText ) ;
398
+ return [
399
+ ...fixes ,
400
+ fixer . replaceText ( returnStatement , replacedText ) ,
401
+ ] ;
399
402
}
400
403
401
- return fixer . insertTextBefore ( finalNode , 'await ' ) ;
404
+ return [ ... fixes , fixer . insertTextBefore ( finalNode , 'await ' ) ] ;
402
405
} ,
403
406
} ) ;
404
407
0 commit comments