eslint-plugin-jest 25.7.0 → 26.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/rules/consistent-test-it.js +20 -20
- package/lib/rules/expect-expect.js +9 -9
- package/lib/rules/max-nested-describe.js +5 -5
- package/lib/rules/no-conditional-expect.js +9 -9
- package/lib/rules/no-deprecated-functions.js +6 -6
- package/lib/rules/no-done-callback.js +10 -10
- package/lib/rules/no-export.js +6 -6
- package/lib/rules/no-focused-tests.js +11 -11
- package/lib/rules/no-if.js +11 -11
- package/lib/rules/no-interpolation-in-snapshots.js +6 -6
- package/lib/rules/no-jasmine-globals.js +10 -10
- package/lib/rules/no-large-snapshots.js +8 -8
- package/lib/rules/no-standalone-expect.js +14 -14
- package/lib/rules/no-test-prefixes.js +6 -6
- package/lib/rules/no-test-return-statement.js +8 -8
- package/lib/rules/prefer-comparison-matcher.js +10 -10
- package/lib/rules/prefer-equality-matcher.js +10 -10
- package/lib/rules/prefer-expect-assertions.js +12 -12
- package/lib/rules/prefer-expect-resolves.js +4 -4
- package/lib/rules/prefer-spy-on.js +9 -9
- package/lib/rules/prefer-to-be.js +15 -15
- package/lib/rules/prefer-to-contain.js +11 -11
- package/lib/rules/prefer-to-have-length.js +6 -6
- package/lib/rules/prefer-todo.js +9 -9
- package/lib/rules/require-hook.js +12 -12
- package/lib/rules/utils.js +27 -27
- package/lib/rules/valid-describe-callback.js +9 -9
- package/lib/rules/valid-expect-in-promise.js +44 -44
- package/lib/rules/valid-expect.js +18 -18
- package/lib/rules/valid-title.js +14 -14
- package/package.json +3 -3
- package/CHANGELOG.md +0 -846
|
@@ -5,18 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
12
|
const isPromiseChainCall = node => {
|
|
13
|
-
if (node.type ===
|
|
13
|
+
if (node.type === _utils.AST_NODE_TYPES.CallExpression && node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property)) {
|
|
14
14
|
// promise methods should have at least 1 argument
|
|
15
15
|
if (node.arguments.length === 0) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
switch ((0,
|
|
19
|
+
switch ((0, _utils2.getAccessorValue)(node.callee.property)) {
|
|
20
20
|
case 'then':
|
|
21
21
|
return node.arguments.length < 3;
|
|
22
22
|
|
|
@@ -36,13 +36,13 @@ const findTopMostCallExpression = node => {
|
|
|
36
36
|
} = node;
|
|
37
37
|
|
|
38
38
|
while (parent) {
|
|
39
|
-
if (parent.type ===
|
|
39
|
+
if (parent.type === _utils.AST_NODE_TYPES.CallExpression) {
|
|
40
40
|
topMostCallExpression = parent;
|
|
41
41
|
parent = parent.parent;
|
|
42
42
|
continue;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (parent.type !==
|
|
45
|
+
if (parent.type !== _utils.AST_NODE_TYPES.MemberExpression) {
|
|
46
46
|
break;
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -53,13 +53,13 @@ const findTopMostCallExpression = node => {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
const isTestCaseCallWithCallbackArg = node => {
|
|
56
|
-
if (!(0,
|
|
56
|
+
if (!(0, _utils2.isTestCaseCall)(node)) {
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
const isJestEach = (0,
|
|
60
|
+
const isJestEach = (0, _utils2.getNodeName)(node).endsWith('.each');
|
|
61
61
|
|
|
62
|
-
if (isJestEach && node.callee.type !==
|
|
62
|
+
if (isJestEach && node.callee.type !== _utils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
63
63
|
// isJestEach but not a TaggedTemplateExpression, so this must be
|
|
64
64
|
// the `jest.each([])()` syntax which this rule doesn't support due
|
|
65
65
|
// to its complexity (see jest-community/eslint-plugin-jest#710)
|
|
@@ -70,7 +70,7 @@ const isTestCaseCallWithCallbackArg = node => {
|
|
|
70
70
|
if (isJestEach || node.arguments.length >= 2) {
|
|
71
71
|
const [, callback] = node.arguments;
|
|
72
72
|
const callbackArgIndex = Number(isJestEach);
|
|
73
|
-
return callback && (0,
|
|
73
|
+
return callback && (0, _utils2.isFunction)(callback) && callback.params.length === 1 + callbackArgIndex;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
return false;
|
|
@@ -85,23 +85,23 @@ const isPromiseMethodThatUsesValue = (node, identifier) => {
|
|
|
85
85
|
return false;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
if (node.argument.type ===
|
|
89
|
-
const nodeName = (0,
|
|
88
|
+
if (node.argument.type === _utils.AST_NODE_TYPES.CallExpression && node.argument.arguments.length > 0) {
|
|
89
|
+
const nodeName = (0, _utils2.getNodeName)(node.argument);
|
|
90
90
|
|
|
91
91
|
if (['Promise.all', 'Promise.allSettled'].includes(nodeName)) {
|
|
92
92
|
const [firstArg] = node.argument.arguments;
|
|
93
93
|
|
|
94
|
-
if (firstArg.type ===
|
|
94
|
+
if (firstArg.type === _utils.AST_NODE_TYPES.ArrayExpression && firstArg.elements.some(nod => (0, _utils2.isIdentifier)(nod, name))) {
|
|
95
95
|
return true;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
if (['Promise.resolve', 'Promise.reject'].includes(nodeName) && node.argument.arguments.length === 1) {
|
|
100
|
-
return (0,
|
|
100
|
+
return (0, _utils2.isIdentifier)(node.argument.arguments[0], name);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
return (0,
|
|
104
|
+
return (0, _utils2.isIdentifier)(node.argument, name);
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
107
|
* Attempts to determine if the runtime value represented by the given `identifier`
|
|
@@ -111,11 +111,11 @@ const isPromiseMethodThatUsesValue = (node, identifier) => {
|
|
|
111
111
|
|
|
112
112
|
const isValueAwaitedInElements = (name, elements) => {
|
|
113
113
|
for (const element of elements) {
|
|
114
|
-
if (element.type ===
|
|
114
|
+
if (element.type === _utils.AST_NODE_TYPES.AwaitExpression && (0, _utils2.isIdentifier)(element.argument, name)) {
|
|
115
115
|
return true;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
if (element.type ===
|
|
118
|
+
if (element.type === _utils.AST_NODE_TYPES.ArrayExpression && isValueAwaitedInElements(name, element.elements)) {
|
|
119
119
|
return true;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
@@ -132,7 +132,7 @@ const isValueAwaitedInArguments = (name, call) => {
|
|
|
132
132
|
let node = call;
|
|
133
133
|
|
|
134
134
|
while (node) {
|
|
135
|
-
if (node.type ===
|
|
135
|
+
if (node.type === _utils.AST_NODE_TYPES.CallExpression) {
|
|
136
136
|
if (isValueAwaitedInElements(name, node.arguments)) {
|
|
137
137
|
return true;
|
|
138
138
|
}
|
|
@@ -140,7 +140,7 @@ const isValueAwaitedInArguments = (name, call) => {
|
|
|
140
140
|
node = node.callee;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
if (node.type !==
|
|
143
|
+
if (node.type !== _utils.AST_NODE_TYPES.MemberExpression) {
|
|
144
144
|
break;
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -155,12 +155,12 @@ const getLeftMostCallExpression = call => {
|
|
|
155
155
|
let node = call;
|
|
156
156
|
|
|
157
157
|
while (node) {
|
|
158
|
-
if (node.type ===
|
|
158
|
+
if (node.type === _utils.AST_NODE_TYPES.CallExpression) {
|
|
159
159
|
leftMostCallExpression = node;
|
|
160
160
|
node = node.callee;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
if (node.type !==
|
|
163
|
+
if (node.type !== _utils.AST_NODE_TYPES.MemberExpression) {
|
|
164
164
|
break;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -187,42 +187,42 @@ const isValueAwaitedOrReturned = (identifier, body) => {
|
|
|
187
187
|
continue;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
if (node.type ===
|
|
190
|
+
if (node.type === _utils.AST_NODE_TYPES.ReturnStatement) {
|
|
191
191
|
return isPromiseMethodThatUsesValue(node, identifier);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
if (node.type ===
|
|
194
|
+
if (node.type === _utils.AST_NODE_TYPES.ExpressionStatement) {
|
|
195
195
|
// it's possible that we're awaiting the value as an argument
|
|
196
|
-
if (node.expression.type ===
|
|
196
|
+
if (node.expression.type === _utils.AST_NODE_TYPES.CallExpression) {
|
|
197
197
|
if (isValueAwaitedInArguments(name, node.expression)) {
|
|
198
198
|
return true;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
const leftMostCall = getLeftMostCallExpression(node.expression);
|
|
202
202
|
|
|
203
|
-
if ((0,
|
|
203
|
+
if ((0, _utils2.isExpectCall)(leftMostCall) && leftMostCall.arguments.length > 0 && (0, _utils2.isIdentifier)(leftMostCall.arguments[0], name)) {
|
|
204
204
|
const {
|
|
205
205
|
modifier
|
|
206
|
-
} = (0,
|
|
206
|
+
} = (0, _utils2.parseExpectCall)(leftMostCall);
|
|
207
207
|
|
|
208
|
-
if ((modifier === null || modifier === void 0 ? void 0 : modifier.name) ===
|
|
208
|
+
if ((modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.resolves || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.rejects) {
|
|
209
209
|
return true;
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
if (node.expression.type ===
|
|
214
|
+
if (node.expression.type === _utils.AST_NODE_TYPES.AwaitExpression && isPromiseMethodThatUsesValue(node.expression, identifier)) {
|
|
215
215
|
return true;
|
|
216
216
|
} // (re)assignment changes the runtime value, so if we've not found an
|
|
217
217
|
// await or return already we act as if we've reached the end of the body
|
|
218
218
|
|
|
219
219
|
|
|
220
|
-
if (node.expression.type ===
|
|
220
|
+
if (node.expression.type === _utils.AST_NODE_TYPES.AssignmentExpression) {
|
|
221
221
|
var _getNodeName;
|
|
222
222
|
|
|
223
223
|
// unless we're assigning to the same identifier, in which case
|
|
224
224
|
// we might be chaining off the existing promise value
|
|
225
|
-
if ((0,
|
|
225
|
+
if ((0, _utils2.isIdentifier)(node.expression.left, name) && (_getNodeName = (0, _utils2.getNodeName)(node.expression.right)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith(`${name}.`) && isPromiseChainCall(node.expression.right)) {
|
|
226
226
|
continue;
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -230,7 +230,7 @@ const isValueAwaitedOrReturned = (identifier, body) => {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
if (node.type ===
|
|
233
|
+
if (node.type === _utils.AST_NODE_TYPES.BlockStatement && isValueAwaitedOrReturned(identifier, node.body)) {
|
|
234
234
|
return true;
|
|
235
235
|
}
|
|
236
236
|
}
|
|
@@ -242,7 +242,7 @@ const findFirstBlockBodyUp = node => {
|
|
|
242
242
|
let parent = node;
|
|
243
243
|
|
|
244
244
|
while (parent) {
|
|
245
|
-
if (parent.type ===
|
|
245
|
+
if (parent.type === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
246
246
|
return parent.body;
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -258,11 +258,11 @@ const isDirectlyWithinTestCaseCall = node => {
|
|
|
258
258
|
let parent = node;
|
|
259
259
|
|
|
260
260
|
while (parent) {
|
|
261
|
-
if ((0,
|
|
261
|
+
if ((0, _utils2.isFunction)(parent)) {
|
|
262
262
|
var _parent;
|
|
263
263
|
|
|
264
264
|
parent = parent.parent;
|
|
265
|
-
return !!(((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.type) ===
|
|
265
|
+
return !!(((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTestCaseCall)(parent));
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
parent = parent.parent;
|
|
@@ -275,14 +275,14 @@ const isVariableAwaitedOrReturned = variable => {
|
|
|
275
275
|
const body = findFirstBlockBodyUp(variable); // it's pretty much impossible for us to track destructuring assignments,
|
|
276
276
|
// so we return true to bailout gracefully
|
|
277
277
|
|
|
278
|
-
if (!(0,
|
|
278
|
+
if (!(0, _utils2.isIdentifier)(variable.id)) {
|
|
279
279
|
return true;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
return isValueAwaitedOrReturned(variable.id, body);
|
|
283
283
|
};
|
|
284
284
|
|
|
285
|
-
var _default = (0,
|
|
285
|
+
var _default = (0, _utils2.createRule)({
|
|
286
286
|
name: __filename,
|
|
287
287
|
meta: {
|
|
288
288
|
docs: {
|
|
@@ -326,7 +326,7 @@ var _default = (0, _utils.createRule)({
|
|
|
326
326
|
// an expect call, mark the deepest chain as having an expect call
|
|
327
327
|
|
|
328
328
|
|
|
329
|
-
if (chains.length > 0 && (0,
|
|
329
|
+
if (chains.length > 0 && (0, _utils2.isExpectCall)(node)) {
|
|
330
330
|
chains[0] = true;
|
|
331
331
|
}
|
|
332
332
|
},
|
|
@@ -336,7 +336,7 @@ var _default = (0, _utils.createRule)({
|
|
|
336
336
|
// make promises containing expects safe in a test for us to be able to
|
|
337
337
|
// accurately check, so we just bail out completely if it's present
|
|
338
338
|
if (inTestCaseWithDoneCallback) {
|
|
339
|
-
if ((0,
|
|
339
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
340
340
|
inTestCaseWithDoneCallback = false;
|
|
341
341
|
}
|
|
342
342
|
|
|
@@ -368,7 +368,7 @@ var _default = (0, _utils.createRule)({
|
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
switch (parent.type) {
|
|
371
|
-
case
|
|
371
|
+
case _utils.AST_NODE_TYPES.VariableDeclarator:
|
|
372
372
|
{
|
|
373
373
|
if (isVariableAwaitedOrReturned(parent)) {
|
|
374
374
|
return;
|
|
@@ -377,20 +377,20 @@ var _default = (0, _utils.createRule)({
|
|
|
377
377
|
break;
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
-
case
|
|
380
|
+
case _utils.AST_NODE_TYPES.AssignmentExpression:
|
|
381
381
|
{
|
|
382
|
-
if (parent.left.type ===
|
|
382
|
+
if (parent.left.type === _utils.AST_NODE_TYPES.Identifier && isValueAwaitedOrReturned(parent.left, findFirstBlockBodyUp(parent))) {
|
|
383
383
|
return;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
break;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
-
case
|
|
389
|
+
case _utils.AST_NODE_TYPES.ExpressionStatement:
|
|
390
390
|
break;
|
|
391
391
|
|
|
392
|
-
case
|
|
393
|
-
case
|
|
392
|
+
case _utils.AST_NODE_TYPES.ReturnStatement:
|
|
393
|
+
case _utils.AST_NODE_TYPES.AwaitExpression:
|
|
394
394
|
default:
|
|
395
395
|
return;
|
|
396
396
|
}
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
12
|
/*
|
|
13
13
|
* This implementation is ported from from eslint-plugin-jasmine.
|
|
@@ -22,11 +22,11 @@ var _utils = require("./utils");
|
|
|
22
22
|
* @Returns CallExpressionNode
|
|
23
23
|
*/
|
|
24
24
|
const getPromiseCallExpressionNode = node => {
|
|
25
|
-
if (node.type ===
|
|
25
|
+
if (node.type === _utils.AST_NODE_TYPES.ArrayExpression && node.parent && node.parent.type === _utils.AST_NODE_TYPES.CallExpression) {
|
|
26
26
|
node = node.parent;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
if (node.type ===
|
|
29
|
+
if (node.type === _utils.AST_NODE_TYPES.CallExpression && node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.object) && (0, _utils2.getAccessorValue)(node.callee.object) === 'Promise' && node.parent) {
|
|
30
30
|
return node;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -36,7 +36,7 @@ const getPromiseCallExpressionNode = node => {
|
|
|
36
36
|
const findPromiseCallExpressionNode = node => {
|
|
37
37
|
var _node$parent;
|
|
38
38
|
|
|
39
|
-
return (_node$parent = node.parent) !== null && _node$parent !== void 0 && _node$parent.parent && [
|
|
39
|
+
return (_node$parent = node.parent) !== null && _node$parent !== void 0 && _node$parent.parent && [_utils.AST_NODE_TYPES.CallExpression, _utils.AST_NODE_TYPES.ArrayExpression].includes(node.parent.type) ? getPromiseCallExpressionNode(node.parent) : null;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const getParentIfThenified = node => {
|
|
@@ -44,7 +44,7 @@ const getParentIfThenified = node => {
|
|
|
44
44
|
|
|
45
45
|
const grandParentNode = (_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.parent;
|
|
46
46
|
|
|
47
|
-
if (grandParentNode && grandParentNode.type ===
|
|
47
|
+
if (grandParentNode && grandParentNode.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isExpectMember)(grandParentNode.callee) && ['then', 'catch'].includes((0, _utils2.getAccessorValue)(grandParentNode.callee.property)) && grandParentNode.parent) {
|
|
48
48
|
// Just in case `then`s are chained look one above.
|
|
49
49
|
return getParentIfThenified(grandParentNode);
|
|
50
50
|
}
|
|
@@ -53,18 +53,18 @@ const getParentIfThenified = node => {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
const isAcceptableReturnNode = (node, allowReturn) => {
|
|
56
|
-
if (allowReturn && node.type ===
|
|
56
|
+
if (allowReturn && node.type === _utils.AST_NODE_TYPES.ReturnStatement) {
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
if (node.type ===
|
|
60
|
+
if (node.type === _utils.AST_NODE_TYPES.ConditionalExpression && node.parent) {
|
|
61
61
|
return isAcceptableReturnNode(node.parent, allowReturn);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
return [
|
|
64
|
+
return [_utils.AST_NODE_TYPES.ArrowFunctionExpression, _utils.AST_NODE_TYPES.AwaitExpression].includes(node.type);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
const isNoAssertionsParentNode = node => node.type ===
|
|
67
|
+
const isNoAssertionsParentNode = node => node.type === _utils.AST_NODE_TYPES.ExpressionStatement || node.type === _utils.AST_NODE_TYPES.AwaitExpression && node.parent !== undefined && node.parent.type === _utils.AST_NODE_TYPES.ExpressionStatement;
|
|
68
68
|
|
|
69
69
|
const promiseArrayExceptionKey = ({
|
|
70
70
|
start,
|
|
@@ -73,7 +73,7 @@ const promiseArrayExceptionKey = ({
|
|
|
73
73
|
|
|
74
74
|
const defaultAsyncMatchers = ['toReject', 'toResolve'];
|
|
75
75
|
|
|
76
|
-
var _default = (0,
|
|
76
|
+
var _default = (0, _utils2.createRule)({
|
|
77
77
|
name: __filename,
|
|
78
78
|
meta: {
|
|
79
79
|
docs: {
|
|
@@ -146,7 +146,7 @@ var _default = (0, _utils.createRule)({
|
|
|
146
146
|
|
|
147
147
|
return {
|
|
148
148
|
CallExpression(node) {
|
|
149
|
-
if (!(0,
|
|
149
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -154,10 +154,10 @@ var _default = (0, _utils.createRule)({
|
|
|
154
154
|
expect,
|
|
155
155
|
modifier,
|
|
156
156
|
matcher
|
|
157
|
-
} = (0,
|
|
157
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
158
158
|
|
|
159
159
|
if (expect.arguments.length < minArgs) {
|
|
160
|
-
const expectLength = (0,
|
|
160
|
+
const expectLength = (0, _utils2.getAccessorValue)(expect.callee).length;
|
|
161
161
|
const loc = {
|
|
162
162
|
start: {
|
|
163
163
|
column: node.loc.start.column + expectLength,
|
|
@@ -216,7 +216,7 @@ var _default = (0, _utils.createRule)({
|
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
if ((0,
|
|
219
|
+
if ((0, _utils2.isExpectMember)(matcher.node.parent)) {
|
|
220
220
|
context.report({
|
|
221
221
|
messageId: 'modifierUnknown',
|
|
222
222
|
data: {
|
|
@@ -235,7 +235,7 @@ var _default = (0, _utils.createRule)({
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
const parentNode = matcher.node.parent;
|
|
238
|
-
const shouldBeAwaited = modifier && modifier.name !==
|
|
238
|
+
const shouldBeAwaited = modifier && modifier.name !== _utils2.ModifierName.not || asyncMatchers.includes(matcher.name);
|
|
239
239
|
|
|
240
240
|
if (!parentNode.parent || !shouldBeAwaited) {
|
|
241
241
|
return;
|
|
@@ -246,7 +246,7 @@ var _default = (0, _utils.createRule)({
|
|
|
246
246
|
*/
|
|
247
247
|
|
|
248
248
|
|
|
249
|
-
const isParentArrayExpression = parentNode.parent.type ===
|
|
249
|
+
const isParentArrayExpression = parentNode.parent.type === _utils.AST_NODE_TYPES.ArrayExpression;
|
|
250
250
|
const orReturned = alwaysAwait ? '' : ' or returned';
|
|
251
251
|
/**
|
|
252
252
|
* An async assertion can be chained with `then` or `catch` statements.
|
|
@@ -277,7 +277,7 @@ var _default = (0, _utils.createRule)({
|
|
|
277
277
|
|
|
278
278
|
// nothing called on "expect()"
|
|
279
279
|
'CallExpression:exit'(node) {
|
|
280
|
-
if ((0,
|
|
280
|
+
if ((0, _utils2.isExpectCall)(node) && isNoAssertionsParentNode(node.parent)) {
|
|
281
281
|
context.report({
|
|
282
282
|
messageId: 'matcherNotFound',
|
|
283
283
|
node
|
package/lib/rules/valid-title.js
CHANGED
|
@@ -5,25 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
12
|
const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;
|
|
13
13
|
|
|
14
14
|
const doesBinaryExpressionContainStringNode = binaryExp => {
|
|
15
|
-
if ((0,
|
|
15
|
+
if ((0, _utils2.isStringNode)(binaryExp.right)) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
if (binaryExp.left.type ===
|
|
19
|
+
if (binaryExp.left.type === _utils.AST_NODE_TYPES.BinaryExpression) {
|
|
20
20
|
return doesBinaryExpressionContainStringNode(binaryExp.left);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
return (0,
|
|
23
|
+
return (0, _utils2.isStringNode)(binaryExp.left);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
const quoteStringValue = node => node.type ===
|
|
26
|
+
const quoteStringValue = node => node.type === _utils.AST_NODE_TYPES.TemplateLiteral ? `\`${node.quasis[0].value.raw}\`` : node.raw;
|
|
27
27
|
|
|
28
28
|
const compileMatcherPattern = matcherMaybeWithMessage => {
|
|
29
29
|
const [matcher, message] = Array.isArray(matcherMaybeWithMessage) ? matcherMaybeWithMessage : [matcherMaybeWithMessage];
|
|
@@ -57,7 +57,7 @@ const MatcherAndMessageSchema = {
|
|
|
57
57
|
additionalItems: false
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
var _default = (0,
|
|
60
|
+
var _default = (0, _utils2.createRule)({
|
|
61
61
|
name: __filename,
|
|
62
62
|
meta: {
|
|
63
63
|
docs: {
|
|
@@ -130,7 +130,7 @@ var _default = (0, _utils.createRule)({
|
|
|
130
130
|
CallExpression(node) {
|
|
131
131
|
var _mustNotMatchPatterns, _mustMatchPatterns$je;
|
|
132
132
|
|
|
133
|
-
if (!(0,
|
|
133
|
+
if (!(0, _utils2.isDescribeCall)(node) && !(0, _utils2.isTestCaseCall)(node)) {
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -140,12 +140,12 @@ var _default = (0, _utils.createRule)({
|
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
if (!(0,
|
|
144
|
-
if (argument.type ===
|
|
143
|
+
if (!(0, _utils2.isStringNode)(argument)) {
|
|
144
|
+
if (argument.type === _utils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument)) {
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
if (argument.type !==
|
|
148
|
+
if (argument.type !== _utils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && (0, _utils2.isDescribeCall)(node))) {
|
|
149
149
|
context.report({
|
|
150
150
|
messageId: 'titleMustBeString',
|
|
151
151
|
loc: argument.loc
|
|
@@ -155,13 +155,13 @@ var _default = (0, _utils.createRule)({
|
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
const title = (0,
|
|
158
|
+
const title = (0, _utils2.getStringValue)(argument);
|
|
159
159
|
|
|
160
160
|
if (!title) {
|
|
161
161
|
context.report({
|
|
162
162
|
messageId: 'emptyTitle',
|
|
163
163
|
data: {
|
|
164
|
-
jestFunctionName: (0,
|
|
164
|
+
jestFunctionName: (0, _utils2.isDescribeCall)(node) ? _utils2.DescribeAlias.describe : _utils2.TestCaseName.test
|
|
165
165
|
},
|
|
166
166
|
node
|
|
167
167
|
});
|
|
@@ -191,7 +191,7 @@ var _default = (0, _utils.createRule)({
|
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
const nodeName = trimFXprefix((0,
|
|
194
|
+
const nodeName = trimFXprefix((0, _utils2.getNodeName)(node));
|
|
195
195
|
const [firstWord] = title.split(' ');
|
|
196
196
|
|
|
197
197
|
if (firstWord.toLowerCase() === nodeName) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "26.0.0",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
]
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@typescript-eslint/
|
|
85
|
+
"@typescript-eslint/utils": "^5.10.0"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@babel/cli": "^7.4.4",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"typescript": "^4.4.0"
|
|
128
128
|
},
|
|
129
129
|
"peerDependencies": {
|
|
130
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
130
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
131
131
|
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
132
132
|
},
|
|
133
133
|
"peerDependenciesMeta": {
|