Skip to content

Commit

Permalink
fix: refactor to return an array
Browse files Browse the repository at this point in the history
  • Loading branch information
y-hsgw committed May 11, 2024
1 parent 004f14e commit 58c4046
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/rules/valid-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils';
import type { RuleFix } from '@typescript-eslint/utils/ts-eslint';
import {
type FunctionExpression,
ModifierName,
Expand Down Expand Up @@ -376,14 +377,13 @@ export default createRule<[Options], MessageIds>({
return [];
}

const fixes: RuleFix[] = [];

if (!functionExpression.async) {
const targetFunction =
getNormalizeFunctionExpression(functionExpression);

return [
fixer.insertTextBefore(targetFunction, 'async '),
fixer.insertTextBefore(finalNode, 'await '),
];
fixes.push(fixer.insertTextBefore(targetFunction, 'async '));
}
const returnStatement =
finalNode.parent.type === AST_NODE_TYPES.ReturnStatement
Expand All @@ -395,10 +395,13 @@ export default createRule<[Options], MessageIds>({
getSourceCode(context).getText(returnStatement);
const replacedText = sourceCodeText.replace('return', 'await');

return fixer.replaceText(returnStatement, replacedText);
return [
...fixes,
fixer.replaceText(returnStatement, replacedText),
];
}

return fixer.insertTextBefore(finalNode, 'await ');
return [...fixes, fixer.insertTextBefore(finalNode, 'await ')];
},
});

Expand Down

0 comments on commit 58c4046

Please sign in to comment.