await-fire-event.js
1.61 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
"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 = 'await-fire-event';
exports.default = experimental_utils_1.ESLintUtils.RuleCreator(utils_1.getDocsUrl)({
name: exports.RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Enforce async fire event methods to be awaited',
category: 'Best Practices',
recommended: false,
},
messages: {
awaitFireEvent: 'async `fireEvent.{{ methodName }}` must be awaited',
},
fixable: null,
schema: [],
},
defaultOptions: [],
create: function (context) {
return {
'CallExpression > MemberExpression > Identifier[name=fireEvent]': function (node) {
var memberExpression = node.parent;
var fireEventMethodNode = memberExpression.property;
if (node_utils_1.isIdentifier(fireEventMethodNode) &&
!node_utils_1.isAwaited(node.parent.parent.parent) &&
!node_utils_1.isPromiseResolved(fireEventMethodNode.parent)) {
context.report({
node: fireEventMethodNode,
messageId: 'awaitFireEvent',
data: {
methodName: fireEventMethodNode.name,
},
});
}
},
};
},
});