source: frontend/node_modules/eslint-plugin-testing-library/rules/no-wait-for-empty-callback.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RULE_NAME = void 0;
4const utils_1 = require("@typescript-eslint/utils");
5const create_testing_library_rule_1 = require("../create-testing-library-rule");
6const node_utils_1 = require("../node-utils");
7exports.RULE_NAME = 'no-wait-for-empty-callback';
8exports.default = (0, create_testing_library_rule_1.createTestingLibraryRule)({
9 name: exports.RULE_NAME,
10 meta: {
11 type: 'suggestion',
12 docs: {
13 description: 'Disallow empty callbacks for `waitFor` and `waitForElementToBeRemoved`',
14 recommendedConfig: {
15 dom: 'error',
16 angular: 'error',
17 react: 'error',
18 vue: 'error',
19 marko: 'error',
20 },
21 },
22 messages: {
23 noWaitForEmptyCallback: 'Avoid passing empty callback to `{{ methodName }}`. Insert an assertion instead.',
24 },
25 schema: [],
26 },
27 defaultOptions: [],
28 create(context, _, helpers) {
29 function isValidWaitFor(node) {
30 const parentCallExpression = node.parent;
31 const parentIdentifier = (0, node_utils_1.getPropertyIdentifierNode)(parentCallExpression);
32 if (!parentIdentifier) {
33 return false;
34 }
35 return helpers.isAsyncUtil(parentIdentifier, [
36 'waitFor',
37 'waitForElementToBeRemoved',
38 ]);
39 }
40 function reportIfEmpty(node) {
41 if (!isValidWaitFor(node)) {
42 return;
43 }
44 if ((0, node_utils_1.isEmptyFunction)(node) &&
45 (0, node_utils_1.isCallExpression)(node.parent) &&
46 utils_1.ASTUtils.isIdentifier(node.parent.callee)) {
47 context.report({
48 node,
49 loc: node.body.loc.start,
50 messageId: 'noWaitForEmptyCallback',
51 data: {
52 methodName: node.parent.callee.name,
53 },
54 });
55 }
56 }
57 function reportNoop(node) {
58 if (!isValidWaitFor(node)) {
59 return;
60 }
61 context.report({
62 node,
63 loc: node.loc.start,
64 messageId: 'noWaitForEmptyCallback',
65 data: {
66 methodName: (0, node_utils_1.isCallExpression)(node.parent) &&
67 utils_1.ASTUtils.isIdentifier(node.parent.callee) &&
68 node.parent.callee.name,
69 },
70 });
71 }
72 return {
73 'CallExpression > ArrowFunctionExpression': reportIfEmpty,
74 'CallExpression > FunctionExpression': reportIfEmpty,
75 'CallExpression > Identifier[name="noop"]': reportNoop,
76 };
77 },
78});
Note: See TracBrowser for help on using the repository browser.