-
Notifications
You must be signed in to change notification settings - Fork 227
/
no-expect-resolves.ts
40 lines (37 loc) · 976 Bytes
/
no-expect-resolves.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
import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { createRule, isExpectCall } from './utils';
function isIdentifierResolves(node: TSESTree.MemberExpression) {
return (
node.property.type === AST_NODE_TYPES.Identifier &&
node.property.name === 'resolves'
);
}
function isExpectResolves(node: TSESTree.MemberExpression) {
return isExpectCall(node.object) && isIdentifierResolves(node);
}
export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description: 'Disallow expect.resolves',
recommended: false,
},
messages: {
expectResolves: 'Use `expect(await promise)` instead.',
},
schema: [],
type: 'suggestion',
},
defaultOptions: [],
create: context => ({
MemberExpression(node) {
if (isExpectResolves(node)) {
context.report({ node: node.property, messageId: 'expectResolves' });
}
},
}),
});