-
Notifications
You must be signed in to change notification settings - Fork 227
/
no-truthy-falsy.ts
41 lines (38 loc) · 986 Bytes
/
no-truthy-falsy.ts
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
import { createRule, isExpectCall, parseExpectCall } from './utils';
// todo: refactor into "ban-matchers"
export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow using `toBeTruthy()` & `toBeFalsy()`',
recommended: false,
},
deprecated: true,
replacedBy: ['no-restricted-matchers'],
messages: {
avoidMatcher: 'Avoid {{ matcherName }}',
},
type: 'suggestion',
schema: [],
},
defaultOptions: [],
create(context) {
return {
CallExpression(node) {
if (!isExpectCall(node)) {
return;
}
const { matcher } = parseExpectCall(node);
if (!matcher || !['toBeTruthy', 'toBeFalsy'].includes(matcher.name)) {
return;
}
context.report({
messageId: 'avoidMatcher',
node: matcher.node.property,
data: { matcherName: matcher.name },
});
},
};
},
});