no-await-sync-events.js
2.13 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
47
48
49
50
51
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RULE_NAME = void 0;
var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
var utils_1 = require("../utils");
var node_utils_1 = require("../node-utils");
exports.RULE_NAME = 'no-await-sync-events';
var SYNC_EVENTS_REGEXP = new RegExp("^(" + utils_1.SYNC_EVENTS.join('|') + ")$");
exports.default = experimental_utils_1.ESLintUtils.RuleCreator(utils_1.getDocsUrl)({
name: exports.RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Disallow unnecessary `await` for sync events',
category: 'Best Practices',
recommended: 'error',
},
messages: {
noAwaitSyncEvents: '`{{ name }}` does not need `await` operator',
},
fixable: null,
schema: [],
},
defaultOptions: [],
create: function (context) {
var _a;
return _a = {},
_a["AwaitExpression > CallExpression > MemberExpression > Identifier[name=" + SYNC_EVENTS_REGEXP + "]"] = function (node) {
var memberExpression = node.parent;
var methodNode = memberExpression.property;
var callExpression = memberExpression.parent;
var withDelay = callExpression.arguments.length >= 3 &&
node_utils_1.isObjectExpression(callExpression.arguments[2]) &&
callExpression.arguments[2].properties.some(function (property) {
return node_utils_1.isProperty(property) &&
node_utils_1.isIdentifier(property.key) &&
property.key.name === 'delay';
});
if (!(node.name === 'userEvent' && methodNode.name === 'type' && withDelay)) {
context.report({
node: methodNode,
messageId: 'noAwaitSyncEvents',
data: {
name: node.name + "." + methodNode.name,
},
});
}
},
_a;
},
});