eslint-plugin-jest 25.5.0 → 26.1.0-next.1
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/README.md +3 -0
- package/docs/rules/no-conditional-in-test.md +79 -0
- package/docs/rules/prefer-comparison-matcher.md +55 -0
- package/docs/rules/prefer-equality-matcher.md +29 -0
- package/docs/rules/valid-expect.md +13 -0
- 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-conditional-in-test.js +60 -0
- 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 +139 -0
- package/lib/rules/prefer-equality-matcher.js +98 -0
- 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 +29 -18
- package/lib/rules/valid-title.js +14 -14
- package/package.json +9 -7
- package/CHANGELOG.md +0 -831
|
@@ -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,25 +53,27 @@ 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,
|
|
71
71
|
end
|
|
72
72
|
}) => `${start.line}:${start.column}-${end.line}:${end.column}`;
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
const defaultAsyncMatchers = ['toReject', 'toResolve'];
|
|
75
|
+
|
|
76
|
+
var _default = (0, _utils2.createRule)({
|
|
75
77
|
name: __filename,
|
|
76
78
|
meta: {
|
|
77
79
|
docs: {
|
|
@@ -96,6 +98,12 @@ var _default = (0, _utils.createRule)({
|
|
|
96
98
|
type: 'boolean',
|
|
97
99
|
default: false
|
|
98
100
|
},
|
|
101
|
+
asyncMatchers: {
|
|
102
|
+
type: 'array',
|
|
103
|
+
items: {
|
|
104
|
+
type: 'string'
|
|
105
|
+
}
|
|
106
|
+
},
|
|
99
107
|
minArgs: {
|
|
100
108
|
type: 'number',
|
|
101
109
|
minimum: 1
|
|
@@ -110,12 +118,14 @@ var _default = (0, _utils.createRule)({
|
|
|
110
118
|
},
|
|
111
119
|
defaultOptions: [{
|
|
112
120
|
alwaysAwait: false,
|
|
121
|
+
asyncMatchers: defaultAsyncMatchers,
|
|
113
122
|
minArgs: 1,
|
|
114
123
|
maxArgs: 1
|
|
115
124
|
}],
|
|
116
125
|
|
|
117
126
|
create(context, [{
|
|
118
127
|
alwaysAwait,
|
|
128
|
+
asyncMatchers = defaultAsyncMatchers,
|
|
119
129
|
minArgs = 1,
|
|
120
130
|
maxArgs = 1
|
|
121
131
|
}]) {
|
|
@@ -136,7 +146,7 @@ var _default = (0, _utils.createRule)({
|
|
|
136
146
|
|
|
137
147
|
return {
|
|
138
148
|
CallExpression(node) {
|
|
139
|
-
if (!(0,
|
|
149
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
140
150
|
return;
|
|
141
151
|
}
|
|
142
152
|
|
|
@@ -144,10 +154,10 @@ var _default = (0, _utils.createRule)({
|
|
|
144
154
|
expect,
|
|
145
155
|
modifier,
|
|
146
156
|
matcher
|
|
147
|
-
} = (0,
|
|
157
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
148
158
|
|
|
149
159
|
if (expect.arguments.length < minArgs) {
|
|
150
|
-
const expectLength = (0,
|
|
160
|
+
const expectLength = (0, _utils2.getAccessorValue)(expect.callee).length;
|
|
151
161
|
const loc = {
|
|
152
162
|
start: {
|
|
153
163
|
column: node.loc.start.column + expectLength,
|
|
@@ -206,7 +216,7 @@ var _default = (0, _utils.createRule)({
|
|
|
206
216
|
return;
|
|
207
217
|
}
|
|
208
218
|
|
|
209
|
-
if ((0,
|
|
219
|
+
if ((0, _utils2.isExpectMember)(matcher.node.parent)) {
|
|
210
220
|
context.report({
|
|
211
221
|
messageId: 'modifierUnknown',
|
|
212
222
|
data: {
|
|
@@ -225,8 +235,9 @@ var _default = (0, _utils.createRule)({
|
|
|
225
235
|
}
|
|
226
236
|
|
|
227
237
|
const parentNode = matcher.node.parent;
|
|
238
|
+
const shouldBeAwaited = modifier && modifier.name !== _utils2.ModifierName.not || asyncMatchers.includes(matcher.name);
|
|
228
239
|
|
|
229
|
-
if (!parentNode.parent || !
|
|
240
|
+
if (!parentNode.parent || !shouldBeAwaited) {
|
|
230
241
|
return;
|
|
231
242
|
}
|
|
232
243
|
/**
|
|
@@ -235,7 +246,7 @@ var _default = (0, _utils.createRule)({
|
|
|
235
246
|
*/
|
|
236
247
|
|
|
237
248
|
|
|
238
|
-
const isParentArrayExpression = parentNode.parent.type ===
|
|
249
|
+
const isParentArrayExpression = parentNode.parent.type === _utils.AST_NODE_TYPES.ArrayExpression;
|
|
239
250
|
const orReturned = alwaysAwait ? '' : ' or returned';
|
|
240
251
|
/**
|
|
241
252
|
* An async assertion can be chained with `then` or `catch` statements.
|
|
@@ -266,7 +277,7 @@ var _default = (0, _utils.createRule)({
|
|
|
266
277
|
|
|
267
278
|
// nothing called on "expect()"
|
|
268
279
|
'CallExpression:exit'(node) {
|
|
269
|
-
if ((0,
|
|
280
|
+
if ((0, _utils2.isExpectCall)(node) && isNoAssertionsParentNode(node.parent)) {
|
|
270
281
|
context.report({
|
|
271
282
|
messageId: 'matcherNotFound',
|
|
272
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "26.1.0-next.1",
|
|
4
|
+
"description": "ESLint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
7
7
|
"eslintplugin",
|
|
@@ -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",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"eslint-plugin-node": "^11.0.0",
|
|
113
113
|
"eslint-plugin-prettier": "^3.4.1",
|
|
114
114
|
"eslint-remote-tester": "^2.1.0",
|
|
115
|
-
"eslint-remote-tester-repositories": "^0.0.
|
|
115
|
+
"eslint-remote-tester-repositories": "^0.0.4",
|
|
116
116
|
"husky": "^7.0.2",
|
|
117
117
|
"is-ci": "^3.0.0",
|
|
118
118
|
"jest": "^27.0.0",
|
|
@@ -121,13 +121,13 @@
|
|
|
121
121
|
"pinst": "^2.0.0",
|
|
122
122
|
"prettier": "^2.0.5",
|
|
123
123
|
"rimraf": "^3.0.0",
|
|
124
|
-
"semantic-release": "^
|
|
124
|
+
"semantic-release": "^19.0.0",
|
|
125
125
|
"semver": "^7.3.5",
|
|
126
126
|
"ts-node": "^10.2.1",
|
|
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": {
|
|
@@ -159,7 +159,9 @@
|
|
|
159
159
|
]
|
|
160
160
|
},
|
|
161
161
|
"resolutions": {
|
|
162
|
-
"@
|
|
162
|
+
"@semantic-release/npm/npm": "7.20.6",
|
|
163
|
+
"@typescript-eslint/experimental-utils": "^5.0.0",
|
|
164
|
+
"fsevents/node-gyp": "^7.0.0"
|
|
163
165
|
},
|
|
164
166
|
"packageManager": "yarn@3.1.1"
|
|
165
167
|
}
|