no-wait-for-empty-callback.js
2.11 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
52
53
54
55
"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-wait-for-empty-callback';
var WAIT_EXPRESSION_QUERY = 'CallExpression[callee.name=/^(waitFor|waitForElementToBeRemoved)$/]';
exports.default = experimental_utils_1.ESLintUtils.RuleCreator(utils_1.getDocsUrl)({
name: exports.RULE_NAME,
meta: {
type: 'suggestion',
docs: {
description: "It's preferred to avoid empty callbacks in `waitFor` and `waitForElementToBeRemoved`",
category: 'Best Practices',
recommended: false,
},
messages: {
noWaitForEmptyCallback: 'Avoid passing empty callback to `{{ methodName }}`. Insert an assertion instead.',
},
fixable: null,
schema: [],
},
defaultOptions: [],
create: function (context) {
var _a;
function reportIfEmpty(node) {
if (node_utils_1.isBlockStatement(node.body) &&
node.body.body.length === 0 &&
node_utils_1.isCallExpression(node.parent) &&
node_utils_1.isIdentifier(node.parent.callee)) {
context.report({
node: node,
loc: node.body.loc.start,
messageId: 'noWaitForEmptyCallback',
data: {
methodName: node.parent.callee.name,
},
});
}
}
function reportNoop(node) {
context.report({
node: node,
loc: node.loc.start,
messageId: 'noWaitForEmptyCallback',
});
}
return _a = {},
_a[WAIT_EXPRESSION_QUERY + " > ArrowFunctionExpression"] = reportIfEmpty,
_a[WAIT_EXPRESSION_QUERY + " > FunctionExpression"] = reportIfEmpty,
_a[WAIT_EXPRESSION_QUERY + " > Identifier[name=\"noop\"]"] = reportNoop,
_a;
},
});