Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 58c4046

Browse files
committedMay 11, 2024·
fix: refactor to return an array
1 parent 004f14e commit 58c4046

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed
 

‎src/rules/valid-expect.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils';
7+
import type { RuleFix } from '@typescript-eslint/utils/ts-eslint';
78
import {
89
type FunctionExpression,
910
ModifierName,
@@ -376,14 +377,13 @@ export default createRule<[Options], MessageIds>({
376377
return [];
377378
}
378379

380+
const fixes: RuleFix[] = [];
381+
379382
if (!functionExpression.async) {
380383
const targetFunction =
381384
getNormalizeFunctionExpression(functionExpression);
382385

383-
return [
384-
fixer.insertTextBefore(targetFunction, 'async '),
385-
fixer.insertTextBefore(finalNode, 'await '),
386-
];
386+
fixes.push(fixer.insertTextBefore(targetFunction, 'async '));
387387
}
388388
const returnStatement =
389389
finalNode.parent.type === AST_NODE_TYPES.ReturnStatement
@@ -395,10 +395,13 @@ export default createRule<[Options], MessageIds>({
395395
getSourceCode(context).getText(returnStatement);
396396
const replacedText = sourceCodeText.replace('return', 'await');
397397

398-
return fixer.replaceText(returnStatement, replacedText);
398+
return [
399+
...fixes,
400+
fixer.replaceText(returnStatement, replacedText),
401+
];
399402
}
400403

401-
return fixer.insertTextBefore(finalNode, 'await ');
404+
return [...fixes, fixer.insertTextBefore(finalNode, 'await ')];
402405
},
403406
});
404407

0 commit comments

Comments
 (0)
Please sign in to comment.