forked from testing-library/eslint-plugin-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-await-sync-queries.ts
54 lines (48 loc) · 1.24 KB
/
no-await-sync-queries.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { TSESTree } from '@typescript-eslint/utils';
import { createTestingLibraryRule } from '../create-testing-library-rule';
import { getDeepestIdentifierNode } from '../node-utils';
export const RULE_NAME = 'no-await-sync-queries';
export type MessageIds = 'noAwaitSyncQuery';
type Options = [];
export default createTestingLibraryRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Disallow unnecessary `await` for sync queries',
recommendedConfig: {
dom: 'error',
angular: 'error',
react: 'error',
vue: 'error',
svelte: 'error',
marko: 'error',
},
},
messages: {
noAwaitSyncQuery:
'`{{ name }}` query is sync so it does not need to be awaited',
},
schema: [],
},
defaultOptions: [],
create(context, _, helpers) {
return {
'AwaitExpression > CallExpression'(node: TSESTree.CallExpression) {
const deepestIdentifierNode = getDeepestIdentifierNode(node);
if (!deepestIdentifierNode) {
return;
}
if (helpers.isSyncQuery(deepestIdentifierNode)) {
context.report({
node: deepestIdentifierNode,
messageId: 'noAwaitSyncQuery',
data: {
name: deepestIdentifierNode.name,
},
});
}
},
};
},
});