1 | 'use strict';
|
2 |
|
3 | const {
|
4 | getDocsUrl,
|
5 | expectCase,
|
6 | expectNotCase,
|
7 | expectResolveCase,
|
8 | expectRejectCase,
|
9 | method,
|
10 | } = require('./util');
|
11 |
|
12 | module.exports = {
|
13 | meta: {
|
14 | docs: {
|
15 | url: getDocsUrl(__filename),
|
16 | },
|
17 | },
|
18 | create(context) {
|
19 | return {
|
20 | CallExpression(node) {
|
21 | if (
|
22 | expectCase(node) ||
|
23 | expectNotCase(node) ||
|
24 | expectResolveCase(node) ||
|
25 | expectRejectCase(node)
|
26 | ) {
|
27 | const targetNode =
|
28 | node.parent.parent.type === 'MemberExpression' ? node.parent : node;
|
29 |
|
30 | const methodNode = method(targetNode);
|
31 | const { name: methodName } = methodNode;
|
32 |
|
33 | if (methodName === 'toBeTruthy' || methodName === 'toBeFalsy') {
|
34 | context.report({
|
35 | data: { methodName },
|
36 | message: 'Avoid {{methodName}}',
|
37 | node: methodNode,
|
38 | });
|
39 | }
|
40 | }
|
41 | },
|
42 | };
|
43 | },
|
44 | };
|