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
|
@@ -7,9 +7,9 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _path = require("path");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils = require("@typescript-eslint/utils");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _utils2 = require("./utils");
|
|
13
13
|
|
|
14
14
|
const reportOnViolation = (context, node, {
|
|
15
15
|
maxSize: lineLimit = 50,
|
|
@@ -26,12 +26,12 @@ const reportOnViolation = (context, node, {
|
|
|
26
26
|
|
|
27
27
|
let isAllowed = false;
|
|
28
28
|
|
|
29
|
-
if (node.type ===
|
|
29
|
+
if (node.type === _utils.AST_NODE_TYPES.ExpressionStatement && 'left' in node.expression && (0, _utils2.isExpectMember)(node.expression.left)) {
|
|
30
30
|
const fileName = context.getFilename();
|
|
31
31
|
const allowedSnapshotsInFile = allowedSnapshots[fileName];
|
|
32
32
|
|
|
33
33
|
if (allowedSnapshotsInFile) {
|
|
34
|
-
const snapshotName = (0,
|
|
34
|
+
const snapshotName = (0, _utils2.getAccessorValue)(node.expression.left.property);
|
|
35
35
|
isAllowed = allowedSnapshotsInFile.some(name => {
|
|
36
36
|
if (name instanceof RegExp) {
|
|
37
37
|
return name.test(snapshotName);
|
|
@@ -54,7 +54,7 @@ const reportOnViolation = (context, node, {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
var _default = (0,
|
|
57
|
+
var _default = (0, _utils2.createRule)({
|
|
58
58
|
name: __filename,
|
|
59
59
|
meta: {
|
|
60
60
|
docs: {
|
|
@@ -102,15 +102,15 @@ var _default = (0, _utils.createRule)({
|
|
|
102
102
|
CallExpression(node) {
|
|
103
103
|
var _matcher$arguments;
|
|
104
104
|
|
|
105
|
-
if (!(0,
|
|
105
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const {
|
|
110
110
|
matcher
|
|
111
|
-
} = (0,
|
|
111
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
112
112
|
|
|
113
|
-
if ((matcher === null || matcher === void 0 ? void 0 : matcher.node.parent.type) !==
|
|
113
|
+
if ((matcher === null || matcher === void 0 ? void 0 : matcher.node.parent.type) !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -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
|
const getBlockType = statement => {
|
|
13
13
|
const func = statement.parent;
|
|
@@ -18,19 +18,19 @@ const getBlockType = statement => {
|
|
|
18
18
|
} // functionDeclaration: function func() {}
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
if (func.type ===
|
|
21
|
+
if (func.type === _utils.AST_NODE_TYPES.FunctionDeclaration) {
|
|
22
22
|
return 'function';
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
if ((0,
|
|
25
|
+
if ((0, _utils2.isFunction)(func) && func.parent) {
|
|
26
26
|
const expr = func.parent; // arrow function or function expr
|
|
27
27
|
|
|
28
|
-
if (expr.type ===
|
|
28
|
+
if (expr.type === _utils.AST_NODE_TYPES.VariableDeclarator) {
|
|
29
29
|
return 'function';
|
|
30
30
|
} // if it's not a variable, it will be callExpr, we only care about describe
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
if (expr.type ===
|
|
33
|
+
if (expr.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isDescribeCall)(expr)) {
|
|
34
34
|
return 'describe';
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -38,7 +38,7 @@ const getBlockType = statement => {
|
|
|
38
38
|
return null;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
var _default = (0,
|
|
41
|
+
var _default = (0, _utils2.createRule)({
|
|
42
42
|
name: __filename,
|
|
43
43
|
meta: {
|
|
44
44
|
docs: {
|
|
@@ -71,16 +71,16 @@ var _default = (0, _utils.createRule)({
|
|
|
71
71
|
}]) {
|
|
72
72
|
const callStack = [];
|
|
73
73
|
|
|
74
|
-
const isCustomTestBlockFunction = node => additionalTestBlockFunctions.includes((0,
|
|
74
|
+
const isCustomTestBlockFunction = node => additionalTestBlockFunctions.includes((0, _utils2.getNodeName)(node) || '');
|
|
75
75
|
|
|
76
|
-
const isTestBlock = node => (0,
|
|
76
|
+
const isTestBlock = node => (0, _utils2.isTestCaseCall)(node) || isCustomTestBlockFunction(node);
|
|
77
77
|
|
|
78
78
|
return {
|
|
79
79
|
CallExpression(node) {
|
|
80
|
-
if ((0,
|
|
80
|
+
if ((0, _utils2.isExpectCall)(node)) {
|
|
81
81
|
const parent = callStack[callStack.length - 1];
|
|
82
82
|
|
|
83
|
-
if (!parent || parent ===
|
|
83
|
+
if (!parent || parent === _utils2.DescribeAlias.describe) {
|
|
84
84
|
context.report({
|
|
85
85
|
node,
|
|
86
86
|
messageId: 'unexpectedExpect'
|
|
@@ -94,7 +94,7 @@ var _default = (0, _utils.createRule)({
|
|
|
94
94
|
callStack.push('test');
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
if (node.callee.type ===
|
|
97
|
+
if (node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
98
98
|
callStack.push('template');
|
|
99
99
|
}
|
|
100
100
|
},
|
|
@@ -102,7 +102,7 @@ var _default = (0, _utils.createRule)({
|
|
|
102
102
|
'CallExpression:exit'(node) {
|
|
103
103
|
const top = callStack[callStack.length - 1];
|
|
104
104
|
|
|
105
|
-
if (top === 'test' && isTestBlock(node) && node.callee.type !==
|
|
105
|
+
if (top === 'test' && isTestBlock(node) && node.callee.type !== _utils.AST_NODE_TYPES.MemberExpression || top === 'template' && node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
106
106
|
callStack.pop();
|
|
107
107
|
}
|
|
108
108
|
},
|
|
@@ -124,7 +124,7 @@ var _default = (0, _utils.createRule)({
|
|
|
124
124
|
ArrowFunctionExpression(node) {
|
|
125
125
|
var _node$parent;
|
|
126
126
|
|
|
127
|
-
if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) !==
|
|
127
|
+
if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
128
128
|
callStack.push('arrow');
|
|
129
129
|
}
|
|
130
130
|
},
|
|
@@ -5,11 +5,11 @@ 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
|
-
var _default = (0,
|
|
12
|
+
var _default = (0, _utils2.createRule)({
|
|
13
13
|
name: __filename,
|
|
14
14
|
meta: {
|
|
15
15
|
docs: {
|
|
@@ -29,11 +29,11 @@ var _default = (0, _utils.createRule)({
|
|
|
29
29
|
create(context) {
|
|
30
30
|
return {
|
|
31
31
|
CallExpression(node) {
|
|
32
|
-
const nodeName = (0,
|
|
33
|
-
if (!nodeName || !(0,
|
|
32
|
+
const nodeName = (0, _utils2.getNodeName)(node.callee);
|
|
33
|
+
if (!nodeName || !(0, _utils2.isDescribeCall)(node) && !(0, _utils2.isTestCaseCall)(node)) return;
|
|
34
34
|
const preferredNodeName = getPreferredNodeName(nodeName);
|
|
35
35
|
if (!preferredNodeName) return;
|
|
36
|
-
const funcNode = node.callee.type ===
|
|
36
|
+
const funcNode = node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
|
37
37
|
context.report({
|
|
38
38
|
messageId: 'usePreferredName',
|
|
39
39
|
node: node.callee,
|
|
@@ -5,21 +5,21 @@ 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 getBody = args => {
|
|
13
13
|
const [, secondArg] = args;
|
|
14
14
|
|
|
15
|
-
if (secondArg && (0,
|
|
15
|
+
if (secondArg && (0, _utils2.isFunction)(secondArg) && secondArg.body.type === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
16
16
|
return secondArg.body.body;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
return [];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
var _default = (0,
|
|
22
|
+
var _default = (0, _utils2.createRule)({
|
|
23
23
|
name: __filename,
|
|
24
24
|
meta: {
|
|
25
25
|
docs: {
|
|
@@ -38,9 +38,9 @@ var _default = (0, _utils.createRule)({
|
|
|
38
38
|
create(context) {
|
|
39
39
|
return {
|
|
40
40
|
CallExpression(node) {
|
|
41
|
-
if (!(0,
|
|
41
|
+
if (!(0, _utils2.isTestCaseCall)(node)) return;
|
|
42
42
|
const body = getBody(node.arguments);
|
|
43
|
-
const returnStmt = body.find(t => t.type ===
|
|
43
|
+
const returnStmt = body.find(t => t.type === _utils.AST_NODE_TYPES.ReturnStatement);
|
|
44
44
|
if (!returnStmt) return;
|
|
45
45
|
context.report({
|
|
46
46
|
messageId: 'noReturnValue',
|
|
@@ -50,9 +50,9 @@ var _default = (0, _utils.createRule)({
|
|
|
50
50
|
|
|
51
51
|
FunctionDeclaration(node) {
|
|
52
52
|
const declaredVariables = context.getDeclaredVariables(node);
|
|
53
|
-
const testCallExpressions = (0,
|
|
53
|
+
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
|
54
54
|
if (testCallExpressions.length === 0) return;
|
|
55
|
-
const returnStmt = node.body.body.find(t => t.type ===
|
|
55
|
+
const returnStmt = node.body.body.find(t => t.type === _utils.AST_NODE_TYPES.ReturnStatement);
|
|
56
56
|
if (!returnStmt) return;
|
|
57
57
|
context.report({
|
|
58
58
|
messageId: 'noReturnValue',
|
|
@@ -5,11 +5,11 @@ 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
|
-
const isBooleanLiteral = node => node.type ===
|
|
12
|
+
const isBooleanLiteral = node => node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Checks if the given `ParsedExpectMatcher` is a call to one of the equality matchers,
|
|
@@ -23,10 +23,10 @@ const isBooleanLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES
|
|
|
23
23
|
*
|
|
24
24
|
* @return {matcher is ParsedBooleanEqualityMatcher}
|
|
25
25
|
*/
|
|
26
|
-
const isBooleanEqualityMatcher = matcher => (0,
|
|
26
|
+
const isBooleanEqualityMatcher = matcher => (0, _utils2.isParsedEqualityMatcherCall)(matcher) && isBooleanLiteral((0, _utils2.followTypeAssertionChain)(matcher.arguments[0]));
|
|
27
27
|
|
|
28
28
|
const isString = node => {
|
|
29
|
-
return (0,
|
|
29
|
+
return (0, _utils2.isStringNode)(node) || node.type === _utils.AST_NODE_TYPES.TemplateLiteral;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
const isComparingToString = expression => {
|
|
@@ -71,7 +71,7 @@ const determineMatcher = (operator, negated) => {
|
|
|
71
71
|
return null;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
var _default = (0,
|
|
74
|
+
var _default = (0, _utils2.createRule)({
|
|
75
75
|
name: __filename,
|
|
76
76
|
meta: {
|
|
77
77
|
docs: {
|
|
@@ -91,7 +91,7 @@ var _default = (0, _utils.createRule)({
|
|
|
91
91
|
create(context) {
|
|
92
92
|
return {
|
|
93
93
|
CallExpression(node) {
|
|
94
|
-
if (!(0,
|
|
94
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -102,13 +102,13 @@ var _default = (0, _utils.createRule)({
|
|
|
102
102
|
},
|
|
103
103
|
matcher,
|
|
104
104
|
modifier
|
|
105
|
-
} = (0,
|
|
105
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
106
106
|
|
|
107
|
-
if (!matcher || (comparison === null || comparison === void 0 ? void 0 : comparison.type) !==
|
|
107
|
+
if (!matcher || (comparison === null || comparison === void 0 ? void 0 : comparison.type) !== _utils.AST_NODE_TYPES.BinaryExpression || isComparingToString(comparison) || !isBooleanEqualityMatcher(matcher)) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
const preferredMatcher = determineMatcher(comparison.operator, (0,
|
|
111
|
+
const preferredMatcher = determineMatcher(comparison.operator, (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value === !!modifier);
|
|
112
112
|
|
|
113
113
|
if (!preferredMatcher) {
|
|
114
114
|
return;
|
|
@@ -5,11 +5,11 @@ 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
|
-
const isBooleanLiteral = node => node.type ===
|
|
12
|
+
const isBooleanLiteral = node => node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Checks if the given `ParsedExpectMatcher` is a call to one of the equality matchers,
|
|
@@ -23,9 +23,9 @@ const isBooleanLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES
|
|
|
23
23
|
*
|
|
24
24
|
* @return {matcher is ParsedBooleanEqualityMatcher}
|
|
25
25
|
*/
|
|
26
|
-
const isBooleanEqualityMatcher = matcher => (0,
|
|
26
|
+
const isBooleanEqualityMatcher = matcher => (0, _utils2.isParsedEqualityMatcherCall)(matcher) && isBooleanLiteral((0, _utils2.followTypeAssertionChain)(matcher.arguments[0]));
|
|
27
27
|
|
|
28
|
-
var _default = (0,
|
|
28
|
+
var _default = (0, _utils2.createRule)({
|
|
29
29
|
name: __filename,
|
|
30
30
|
meta: {
|
|
31
31
|
docs: {
|
|
@@ -47,7 +47,7 @@ var _default = (0, _utils.createRule)({
|
|
|
47
47
|
create(context) {
|
|
48
48
|
return {
|
|
49
49
|
CallExpression(node) {
|
|
50
|
-
if (!(0,
|
|
50
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -58,13 +58,13 @@ var _default = (0, _utils.createRule)({
|
|
|
58
58
|
},
|
|
59
59
|
matcher,
|
|
60
60
|
modifier
|
|
61
|
-
} = (0,
|
|
61
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
62
62
|
|
|
63
|
-
if (!matcher || (comparison === null || comparison === void 0 ? void 0 : comparison.type) !==
|
|
63
|
+
if (!matcher || (comparison === null || comparison === void 0 ? void 0 : comparison.type) !== _utils.AST_NODE_TYPES.BinaryExpression || comparison.operator !== '===' && comparison.operator !== '!==' || !isBooleanEqualityMatcher(matcher)) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const matcherValue = (0,
|
|
67
|
+
const matcherValue = (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value; // we need to negate the expectation if the current expected
|
|
68
68
|
// value is itself negated by the "not" modifier
|
|
69
69
|
|
|
70
70
|
const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === !!modifier;
|
|
@@ -73,7 +73,7 @@ var _default = (0, _utils.createRule)({
|
|
|
73
73
|
const sourceCode = context.getSourceCode();
|
|
74
74
|
return [// replace the comparison argument with the left-hand side of the comparison
|
|
75
75
|
fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
|
|
76
|
-
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${
|
|
76
|
+
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${_utils2.ModifierName.not}.${equalityMatcher}` : `.${equalityMatcher}`), // replace the matcher argument with the right-hand side of the comparison
|
|
77
77
|
fixer.replaceText(matcher.arguments[0], sourceCode.getText(comparison.right))];
|
|
78
78
|
};
|
|
79
79
|
|
|
@@ -5,13 +5,13 @@ 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
|
-
const isExpectAssertionsOrHasAssertionsCall = expression => expression.type ===
|
|
12
|
+
const isExpectAssertionsOrHasAssertionsCall = expression => expression.type === _utils.AST_NODE_TYPES.CallExpression && expression.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(expression.callee.object, 'expect') && (0, _utils2.isSupportedAccessor)(expression.callee.property) && ['assertions', 'hasAssertions'].includes((0, _utils2.getAccessorValue)(expression.callee.property));
|
|
13
13
|
|
|
14
|
-
const isFirstLineExprStmt = functionBody => functionBody[0] && functionBody[0].type ===
|
|
14
|
+
const isFirstLineExprStmt = functionBody => functionBody[0] && functionBody[0].type === _utils.AST_NODE_TYPES.ExpressionStatement;
|
|
15
15
|
|
|
16
16
|
const suggestRemovingExtraArguments = (args, extraArgsStartAt) => ({
|
|
17
17
|
messageId: 'suggestRemovingExtraArguments',
|
|
@@ -20,7 +20,7 @@ const suggestRemovingExtraArguments = (args, extraArgsStartAt) => ({
|
|
|
20
20
|
|
|
21
21
|
const suggestions = [['suggestAddingHasAssertions', 'expect.hasAssertions();'], ['suggestAddingAssertions', 'expect.assertions();']];
|
|
22
22
|
|
|
23
|
-
var _default = (0,
|
|
23
|
+
var _default = (0, _utils2.createRule)({
|
|
24
24
|
name: __filename,
|
|
25
25
|
meta: {
|
|
26
26
|
docs: {
|
|
@@ -116,12 +116,12 @@ var _default = (0, _utils.createRule)({
|
|
|
116
116
|
'ForOfStatement:exit': exitForLoop,
|
|
117
117
|
|
|
118
118
|
CallExpression(node) {
|
|
119
|
-
if ((0,
|
|
119
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
120
120
|
inTestCaseCall = true;
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
if ((0,
|
|
124
|
+
if ((0, _utils2.isExpectCall)(node) && inTestCaseCall) {
|
|
125
125
|
if (inForLoop) {
|
|
126
126
|
hasExpectInLoop = true;
|
|
127
127
|
}
|
|
@@ -133,7 +133,7 @@ var _default = (0, _utils.createRule)({
|
|
|
133
133
|
},
|
|
134
134
|
|
|
135
135
|
'CallExpression:exit'(node) {
|
|
136
|
-
if (!(0,
|
|
136
|
+
if (!(0, _utils2.isTestCaseCall)(node)) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -143,7 +143,7 @@ var _default = (0, _utils.createRule)({
|
|
|
143
143
|
|
|
144
144
|
const [, testFn] = node.arguments;
|
|
145
145
|
|
|
146
|
-
if (!(0,
|
|
146
|
+
if (!(0, _utils2.isFunction)(testFn) || testFn.body.type !== _utils.AST_NODE_TYPES.BlockStatement) {
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -181,7 +181,7 @@ var _default = (0, _utils.createRule)({
|
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
if ((0,
|
|
184
|
+
if ((0, _utils2.isSupportedAccessor)(testFuncFirstLine.callee.property, 'hasAssertions')) {
|
|
185
185
|
if (testFuncFirstLine.arguments.length) {
|
|
186
186
|
context.report({
|
|
187
187
|
messageId: 'hasAssertionsTakesNoArguments',
|
|
@@ -193,7 +193,7 @@ var _default = (0, _utils.createRule)({
|
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
if (!(0,
|
|
196
|
+
if (!(0, _utils2.hasOnlyOneArgument)(testFuncFirstLine)) {
|
|
197
197
|
let {
|
|
198
198
|
loc
|
|
199
199
|
} = testFuncFirstLine.callee.property;
|
|
@@ -214,7 +214,7 @@ var _default = (0, _utils.createRule)({
|
|
|
214
214
|
|
|
215
215
|
const [arg] = testFuncFirstLine.arguments;
|
|
216
216
|
|
|
217
|
-
if (arg.type ===
|
|
217
|
+
if (arg.type === _utils.AST_NODE_TYPES.Literal && typeof arg.value === 'number' && Number.isInteger(arg.value)) {
|
|
218
218
|
return;
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -5,11 +5,11 @@ 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
|
-
var _default = (0,
|
|
12
|
+
var _default = (0, _utils2.createRule)({
|
|
13
13
|
name: __filename,
|
|
14
14
|
meta: {
|
|
15
15
|
docs: {
|
|
@@ -29,7 +29,7 @@ var _default = (0, _utils.createRule)({
|
|
|
29
29
|
CallExpression(node) {
|
|
30
30
|
const [awaitNode] = node.arguments;
|
|
31
31
|
|
|
32
|
-
if ((0,
|
|
32
|
+
if ((0, _utils2.isExpectCall)(node) && (awaitNode === null || awaitNode === void 0 ? void 0 : awaitNode.type) === _utils.AST_NODE_TYPES.AwaitExpression) {
|
|
33
33
|
context.report({
|
|
34
34
|
node: node.arguments[0],
|
|
35
35
|
messageId: 'expectResolves',
|
|
@@ -5,16 +5,16 @@ 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 findNodeObject = node => {
|
|
13
13
|
if ('object' in node) {
|
|
14
14
|
return node.object;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (node.callee.type ===
|
|
17
|
+
if (node.callee.type === _utils.AST_NODE_TYPES.MemberExpression) {
|
|
18
18
|
return node.callee.object;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ const findNodeObject = node => {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const getJestFnCall = node => {
|
|
25
|
-
if (node.type !==
|
|
25
|
+
if (node.type !== _utils.AST_NODE_TYPES.CallExpression && node.type !== _utils.AST_NODE_TYPES.MemberExpression) {
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -32,14 +32,14 @@ const getJestFnCall = node => {
|
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
if (obj.type ===
|
|
36
|
-
return node.type ===
|
|
35
|
+
if (obj.type === _utils.AST_NODE_TYPES.Identifier) {
|
|
36
|
+
return node.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.getNodeName)(node.callee) === 'jest.fn' ? node : null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
return getJestFnCall(obj);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
var _default = (0,
|
|
42
|
+
var _default = (0, _utils2.createRule)({
|
|
43
43
|
name: __filename,
|
|
44
44
|
meta: {
|
|
45
45
|
docs: {
|
|
@@ -63,7 +63,7 @@ var _default = (0, _utils.createRule)({
|
|
|
63
63
|
left,
|
|
64
64
|
right
|
|
65
65
|
} = node;
|
|
66
|
-
if (left.type !==
|
|
66
|
+
if (left.type !== _utils.AST_NODE_TYPES.MemberExpression) return;
|
|
67
67
|
const jestFnCall = getJestFnCall(right);
|
|
68
68
|
if (!jestFnCall) return;
|
|
69
69
|
context.report({
|
|
@@ -71,7 +71,7 @@ var _default = (0, _utils.createRule)({
|
|
|
71
71
|
messageId: 'useJestSpyOn',
|
|
72
72
|
|
|
73
73
|
fix(fixer) {
|
|
74
|
-
const leftPropQuote = left.property.type ===
|
|
74
|
+
const leftPropQuote = left.property.type === _utils.AST_NODE_TYPES.Identifier ? "'" : '';
|
|
75
75
|
const [arg] = jestFnCall.arguments;
|
|
76
76
|
const argSource = arg && context.getSourceCode().getText(arg);
|
|
77
77
|
const mockImplementation = argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()';
|
|
@@ -5,11 +5,11 @@ 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
|
-
const isNullLiteral = node => node.type ===
|
|
12
|
+
const isNullLiteral = node => node.type === _utils.AST_NODE_TYPES.Literal && node.value === null;
|
|
13
13
|
/**
|
|
14
14
|
* Checks if the given `ParsedEqualityMatcherCall` is a call to one of the equality matchers,
|
|
15
15
|
* with a `null` literal as the sole argument.
|
|
@@ -18,26 +18,26 @@ const isNullLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES.Li
|
|
|
18
18
|
|
|
19
19
|
const isNullEqualityMatcher = matcher => isNullLiteral(getFirstArgument(matcher));
|
|
20
20
|
|
|
21
|
-
const isFirstArgumentIdentifier = (matcher, name) => (0,
|
|
21
|
+
const isFirstArgumentIdentifier = (matcher, name) => (0, _utils2.isIdentifier)(getFirstArgument(matcher), name);
|
|
22
22
|
|
|
23
23
|
const shouldUseToBe = matcher => {
|
|
24
24
|
const firstArg = getFirstArgument(matcher);
|
|
25
25
|
|
|
26
|
-
if (firstArg.type ===
|
|
26
|
+
if (firstArg.type === _utils.AST_NODE_TYPES.Literal) {
|
|
27
27
|
// regex literals are classed as literals, but they're actually objects
|
|
28
28
|
// which means "toBe" will give different results than other matchers
|
|
29
29
|
return !('regex' in firstArg);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return firstArg.type ===
|
|
32
|
+
return firstArg.type === _utils.AST_NODE_TYPES.TemplateLiteral;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const getFirstArgument = matcher => {
|
|
36
|
-
return (0,
|
|
36
|
+
return (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const reportPreferToBe = (context, whatToBe, matcher, modifier) => {
|
|
40
|
-
const modifierNode = (modifier === null || modifier === void 0 ? void 0 : modifier.negation) || (modifier === null || modifier === void 0 ? void 0 : modifier.name) ===
|
|
40
|
+
const modifierNode = (modifier === null || modifier === void 0 ? void 0 : modifier.negation) || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not && (modifier === null || modifier === void 0 ? void 0 : modifier.node);
|
|
41
41
|
context.report({
|
|
42
42
|
messageId: `useToBe${whatToBe}`,
|
|
43
43
|
|
|
@@ -61,7 +61,7 @@ const reportPreferToBe = (context, whatToBe, matcher, modifier) => {
|
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
var _default = (0,
|
|
64
|
+
var _default = (0, _utils2.createRule)({
|
|
65
65
|
name: __filename,
|
|
66
66
|
meta: {
|
|
67
67
|
docs: {
|
|
@@ -85,25 +85,25 @@ var _default = (0, _utils.createRule)({
|
|
|
85
85
|
create(context) {
|
|
86
86
|
return {
|
|
87
87
|
CallExpression(node) {
|
|
88
|
-
if (!(0,
|
|
88
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const {
|
|
93
93
|
matcher,
|
|
94
94
|
modifier
|
|
95
|
-
} = (0,
|
|
95
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
96
96
|
|
|
97
97
|
if (!matcher) {
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
if (((modifier === null || modifier === void 0 ? void 0 : modifier.name) ===
|
|
101
|
+
if (((modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not || modifier !== null && modifier !== void 0 && modifier.negation) && ['toBeUndefined', 'toBeDefined'].includes(matcher.name)) {
|
|
102
102
|
reportPreferToBe(context, matcher.name === 'toBeDefined' ? 'Undefined' : 'Defined', matcher, modifier);
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (!(0,
|
|
106
|
+
if (!(0, _utils2.isParsedEqualityMatcherCall)(matcher)) {
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -113,7 +113,7 @@ var _default = (0, _utils.createRule)({
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
if (isFirstArgumentIdentifier(matcher, 'undefined')) {
|
|
116
|
-
const name = (modifier === null || modifier === void 0 ? void 0 : modifier.name) ===
|
|
116
|
+
const name = (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not || modifier !== null && modifier !== void 0 && modifier.negation ? 'Defined' : 'Undefined';
|
|
117
117
|
reportPreferToBe(context, name, matcher, modifier);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
@@ -123,7 +123,7 @@ var _default = (0, _utils.createRule)({
|
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
if (shouldUseToBe(matcher) && matcher.name !==
|
|
126
|
+
if (shouldUseToBe(matcher) && matcher.name !== _utils2.EqualityMatcher.toBe) {
|
|
127
127
|
reportPreferToBe(context, '', matcher);
|
|
128
128
|
}
|
|
129
129
|
}
|