no-await-sync-query.js
1.57 KB
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RULE_NAME = void 0;
const create_testing_library_rule_1 = require("../create-testing-library-rule");
const node_utils_1 = require("../node-utils");
exports.RULE_NAME = 'no-await-sync-query';
exports.default = (0, create_testing_library_rule_1.createTestingLibraryRule)({
name: exports.RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Disallow unnecessary `await` for sync queries',
recommendedConfig: {
dom: 'error',
angular: 'error',
react: 'error',
vue: '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) {
const deepestIdentifierNode = (0, node_utils_1.getDeepestIdentifierNode)(node);
if (!deepestIdentifierNode) {
return;
}
if (helpers.isSyncQuery(deepestIdentifierNode)) {
context.report({
node: deepestIdentifierNode,
messageId: 'noAwaitSyncQuery',
data: {
name: deepestIdentifierNode.name,
},
});
}
},
};
},
});