Skip to content

Commit 06443b8

Browse files
committed
feat: add auto-fix
1 parent 9d3c771 commit 06443b8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/rules/no-await-sync-queries.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createTestingLibraryRule } from '../create-testing-library-rule';
22
import { getDeepestIdentifierNode } from '../node-utils';
3+
import { getSourceCode } from '../utils';
34

45
import type { TSESTree } from '@typescript-eslint/utils';
56

@@ -27,12 +28,16 @@ export default createTestingLibraryRule<Options, MessageIds>({
2728
'`{{ name }}` query is sync so it does not need to be awaited',
2829
},
2930
schema: [],
31+
fixable: 'code',
3032
},
3133
defaultOptions: [],
3234

3335
create(context, _, helpers) {
3436
return {
35-
'AwaitExpression > CallExpression'(node: TSESTree.CallExpression) {
37+
'AwaitExpression > CallExpression'(
38+
node: TSESTree.CallExpression & { parent: TSESTree.AwaitExpression }
39+
) {
40+
const awaitExpression = node.parent;
3641
const deepestIdentifierNode = getDeepestIdentifierNode(node);
3742

3843
if (!deepestIdentifierNode) {
@@ -46,6 +51,12 @@ export default createTestingLibraryRule<Options, MessageIds>({
4651
data: {
4752
name: deepestIdentifierNode.name,
4853
},
54+
fix: (fixer) => {
55+
const awaitToken =
56+
getSourceCode(context).getFirstToken(awaitExpression);
57+
58+
return awaitToken ? fixer.remove(awaitToken) : null;
59+
},
4960
});
5061
}
5162
},

0 commit comments

Comments
 (0)