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
package/lib/rules/no-export.js
CHANGED
|
@@ -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: {
|
|
@@ -41,7 +41,7 @@ var _default = (0, _utils.createRule)({
|
|
|
41
41
|
},
|
|
42
42
|
|
|
43
43
|
CallExpression(node) {
|
|
44
|
-
if ((0,
|
|
44
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
45
45
|
hasTestCase = true;
|
|
46
46
|
}
|
|
47
47
|
},
|
|
@@ -56,14 +56,14 @@ var _default = (0, _utils.createRule)({
|
|
|
56
56
|
property
|
|
57
57
|
} = node;
|
|
58
58
|
|
|
59
|
-
if (object.type ===
|
|
59
|
+
if (object.type === _utils.AST_NODE_TYPES.MemberExpression) {
|
|
60
60
|
({
|
|
61
61
|
object,
|
|
62
62
|
property
|
|
63
63
|
} = object);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
if ('name' in object && object.name === 'module' && property.type ===
|
|
66
|
+
if ('name' in object && object.name === 'module' && property.type === _utils.AST_NODE_TYPES.Identifier && /^exports?$/u.test(property.name)) {
|
|
67
67
|
exportNodes.push(node);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -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 findOnlyNode = node => {
|
|
13
|
-
const callee = node.callee.type ===
|
|
13
|
+
const callee = node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
|
|
14
14
|
|
|
15
|
-
if (callee.type ===
|
|
16
|
-
if (callee.object.type ===
|
|
17
|
-
if ((0,
|
|
15
|
+
if (callee.type === _utils.AST_NODE_TYPES.MemberExpression) {
|
|
16
|
+
if (callee.object.type === _utils.AST_NODE_TYPES.MemberExpression) {
|
|
17
|
+
if ((0, _utils2.isSupportedAccessor)(callee.object.property, 'only')) {
|
|
18
18
|
return callee.object.property;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
if ((0,
|
|
22
|
+
if ((0, _utils2.isSupportedAccessor)(callee.property, 'only')) {
|
|
23
23
|
return callee.property;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -27,7 +27,7 @@ const findOnlyNode = node => {
|
|
|
27
27
|
return null;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
var _default = (0,
|
|
30
|
+
var _default = (0, _utils2.createRule)({
|
|
31
31
|
name: __filename,
|
|
32
32
|
meta: {
|
|
33
33
|
docs: {
|
|
@@ -47,11 +47,11 @@ var _default = (0, _utils.createRule)({
|
|
|
47
47
|
defaultOptions: [],
|
|
48
48
|
create: context => ({
|
|
49
49
|
CallExpression(node) {
|
|
50
|
-
if (!(0,
|
|
50
|
+
if (!(0, _utils2.isDescribeCall)(node) && !(0, _utils2.isTestCaseCall)(node)) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
if ((0,
|
|
54
|
+
if ((0, _utils2.getNodeName)(node).startsWith('f')) {
|
|
55
55
|
context.report({
|
|
56
56
|
messageId: 'focusedTest',
|
|
57
57
|
node,
|
|
@@ -74,7 +74,7 @@ var _default = (0, _utils.createRule)({
|
|
|
74
74
|
node: onlyNode,
|
|
75
75
|
suggest: [{
|
|
76
76
|
messageId: 'suggestRemoveFocus',
|
|
77
|
-
fix: fixer => fixer.removeRange([onlyNode.range[0] - 1, onlyNode.range[1] + Number(onlyNode.type !==
|
|
77
|
+
fix: fixer => fixer.removeRange([onlyNode.range[0] - 1, onlyNode.range[1] + Number(onlyNode.type !== _utils.AST_NODE_TYPES.Identifier)])
|
|
78
78
|
}]
|
|
79
79
|
});
|
|
80
80
|
}
|
package/lib/rules/no-if.js
CHANGED
|
@@ -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
|
-
const testCaseNames = new Set([...Object.keys(
|
|
12
|
+
const testCaseNames = new Set([...Object.keys(_utils2.TestCaseName), 'it.only', 'it.concurrent.only', 'it.skip', 'it.concurrent.skip', 'test.only', 'test.concurrent.only', 'test.skip', 'test.concurrent.skip', 'fit.concurrent']);
|
|
13
13
|
|
|
14
|
-
const isTestFunctionExpression = node => node.parent !== undefined && node.parent.type ===
|
|
14
|
+
const isTestFunctionExpression = node => node.parent !== undefined && node.parent.type === _utils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils2.getNodeName)(node.parent.callee));
|
|
15
15
|
|
|
16
16
|
const conditionName = {
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
17
|
+
[_utils.AST_NODE_TYPES.ConditionalExpression]: 'conditional',
|
|
18
|
+
[_utils.AST_NODE_TYPES.SwitchStatement]: 'switch',
|
|
19
|
+
[_utils.AST_NODE_TYPES.IfStatement]: 'if'
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
var _default = (0,
|
|
22
|
+
var _default = (0, _utils2.createRule)({
|
|
23
23
|
name: __filename,
|
|
24
24
|
meta: {
|
|
25
25
|
docs: {
|
|
@@ -56,10 +56,10 @@ var _default = (0, _utils.createRule)({
|
|
|
56
56
|
|
|
57
57
|
return {
|
|
58
58
|
CallExpression(node) {
|
|
59
|
-
if ((0,
|
|
59
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
60
60
|
stack.push(true);
|
|
61
61
|
|
|
62
|
-
if ((0,
|
|
62
|
+
if ((0, _utils2.getNodeName)(node).endsWith('each')) {
|
|
63
63
|
stack.push(true);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -71,7 +71,7 @@ var _default = (0, _utils.createRule)({
|
|
|
71
71
|
|
|
72
72
|
FunctionDeclaration(node) {
|
|
73
73
|
const declaredVariables = context.getDeclaredVariables(node);
|
|
74
|
-
const testCallExpressions = (0,
|
|
74
|
+
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
|
75
75
|
stack.push(testCallExpressions.length > 0);
|
|
76
76
|
},
|
|
77
77
|
|
|
@@ -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: {
|
|
@@ -28,13 +28,13 @@ var _default = (0, _utils.createRule)({
|
|
|
28
28
|
create(context) {
|
|
29
29
|
return {
|
|
30
30
|
CallExpression(node) {
|
|
31
|
-
if (!(0,
|
|
31
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const {
|
|
36
36
|
matcher
|
|
37
|
-
} = (0,
|
|
37
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
38
38
|
|
|
39
39
|
if (!matcher) {
|
|
40
40
|
return;
|
|
@@ -45,7 +45,7 @@ var _default = (0, _utils.createRule)({
|
|
|
45
45
|
|
|
46
46
|
// Check all since the optional 'propertyMatchers' argument might be present
|
|
47
47
|
(_matcher$arguments = matcher.arguments) === null || _matcher$arguments === void 0 ? void 0 : _matcher$arguments.forEach(argument => {
|
|
48
|
-
if (argument.type ===
|
|
48
|
+
if (argument.type === _utils.AST_NODE_TYPES.TemplateLiteral && argument.expressions.length > 0) {
|
|
49
49
|
context.report({
|
|
50
50
|
messageId: 'noInterpolation',
|
|
51
51
|
node: argument
|
|
@@ -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: {
|
|
@@ -36,14 +36,14 @@ var _default = (0, _utils.createRule)({
|
|
|
36
36
|
const {
|
|
37
37
|
callee
|
|
38
38
|
} = node;
|
|
39
|
-
const calleeName = (0,
|
|
39
|
+
const calleeName = (0, _utils2.getNodeName)(callee);
|
|
40
40
|
|
|
41
41
|
if (!calleeName) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (calleeName === 'spyOn' || calleeName === 'spyOnProperty' || calleeName === 'fail' || calleeName === 'pending') {
|
|
46
|
-
if ((0,
|
|
46
|
+
if ((0, _utils2.scopeHasLocalReference)(context.getScope(), calleeName)) {
|
|
47
47
|
// It's a local variable, not a jasmine global.
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
@@ -79,7 +79,7 @@ var _default = (0, _utils.createRule)({
|
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
if (callee.type ===
|
|
82
|
+
if (callee.type === _utils.AST_NODE_TYPES.MemberExpression && calleeName.startsWith('jasmine.')) {
|
|
83
83
|
const functionName = calleeName.replace('jasmine.', '');
|
|
84
84
|
|
|
85
85
|
if (functionName === 'any' || functionName === 'anything' || functionName === 'arrayContaining' || functionName === 'objectContaining' || functionName === 'stringMatching') {
|
|
@@ -127,19 +127,19 @@ var _default = (0, _utils.createRule)({
|
|
|
127
127
|
},
|
|
128
128
|
|
|
129
129
|
MemberExpression(node) {
|
|
130
|
-
if ((0,
|
|
130
|
+
if ((0, _utils2.isSupportedAccessor)(node.object, 'jasmine')) {
|
|
131
131
|
const {
|
|
132
132
|
parent,
|
|
133
133
|
property
|
|
134
134
|
} = node;
|
|
135
135
|
|
|
136
|
-
if (parent && parent.type ===
|
|
137
|
-
if ((0,
|
|
136
|
+
if (parent && parent.type === _utils.AST_NODE_TYPES.AssignmentExpression) {
|
|
137
|
+
if ((0, _utils2.isSupportedAccessor)(property, 'DEFAULT_TIMEOUT_INTERVAL')) {
|
|
138
138
|
const {
|
|
139
139
|
right
|
|
140
140
|
} = parent;
|
|
141
141
|
|
|
142
|
-
if (right.type ===
|
|
142
|
+
if (right.type === _utils.AST_NODE_TYPES.Literal) {
|
|
143
143
|
context.report({
|
|
144
144
|
fix: fixer => [fixer.replaceText(parent, `jest.setTimeout(${right.value})`)],
|
|
145
145
|
node,
|
|
@@ -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',
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
|
+
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
|
+
|
|
12
|
+
const isBooleanLiteral = node => node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the given `ParsedExpectMatcher` is a call to one of the equality matchers,
|
|
16
|
+
* with a boolean literal as the sole argument.
|
|
17
|
+
*
|
|
18
|
+
* @example javascript
|
|
19
|
+
* toBe(true);
|
|
20
|
+
* toEqual(false);
|
|
21
|
+
*
|
|
22
|
+
* @param {ParsedExpectMatcher} matcher
|
|
23
|
+
*
|
|
24
|
+
* @return {matcher is ParsedBooleanEqualityMatcher}
|
|
25
|
+
*/
|
|
26
|
+
const isBooleanEqualityMatcher = matcher => (0, _utils2.isParsedEqualityMatcherCall)(matcher) && isBooleanLiteral((0, _utils2.followTypeAssertionChain)(matcher.arguments[0]));
|
|
27
|
+
|
|
28
|
+
const isString = node => {
|
|
29
|
+
return (0, _utils2.isStringNode)(node) || node.type === _utils.AST_NODE_TYPES.TemplateLiteral;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const isComparingToString = expression => {
|
|
33
|
+
return isString(expression.left) || isString(expression.right);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const invertOperator = operator => {
|
|
37
|
+
switch (operator) {
|
|
38
|
+
case '>':
|
|
39
|
+
return '<=';
|
|
40
|
+
|
|
41
|
+
case '<':
|
|
42
|
+
return '>=';
|
|
43
|
+
|
|
44
|
+
case '>=':
|
|
45
|
+
return '<';
|
|
46
|
+
|
|
47
|
+
case '<=':
|
|
48
|
+
return '>';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const determineMatcher = (operator, negated) => {
|
|
55
|
+
const op = negated ? invertOperator(operator) : operator;
|
|
56
|
+
|
|
57
|
+
switch (op) {
|
|
58
|
+
case '>':
|
|
59
|
+
return 'toBeGreaterThan';
|
|
60
|
+
|
|
61
|
+
case '<':
|
|
62
|
+
return 'toBeLessThan';
|
|
63
|
+
|
|
64
|
+
case '>=':
|
|
65
|
+
return 'toBeGreaterThanOrEqual';
|
|
66
|
+
|
|
67
|
+
case '<=':
|
|
68
|
+
return 'toBeLessThanOrEqual';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
var _default = (0, _utils2.createRule)({
|
|
75
|
+
name: __filename,
|
|
76
|
+
meta: {
|
|
77
|
+
docs: {
|
|
78
|
+
category: 'Best Practices',
|
|
79
|
+
description: 'Suggest using the built-in comparison matchers',
|
|
80
|
+
recommended: false
|
|
81
|
+
},
|
|
82
|
+
messages: {
|
|
83
|
+
useToBeComparison: 'Prefer using `{{ preferredMatcher }}` instead'
|
|
84
|
+
},
|
|
85
|
+
fixable: 'code',
|
|
86
|
+
type: 'suggestion',
|
|
87
|
+
schema: []
|
|
88
|
+
},
|
|
89
|
+
defaultOptions: [],
|
|
90
|
+
|
|
91
|
+
create(context) {
|
|
92
|
+
return {
|
|
93
|
+
CallExpression(node) {
|
|
94
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const {
|
|
99
|
+
expect: {
|
|
100
|
+
arguments: [comparison],
|
|
101
|
+
range: [, expectCallEnd]
|
|
102
|
+
},
|
|
103
|
+
matcher,
|
|
104
|
+
modifier
|
|
105
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
106
|
+
|
|
107
|
+
if (!matcher || (comparison === null || comparison === void 0 ? void 0 : comparison.type) !== _utils.AST_NODE_TYPES.BinaryExpression || isComparingToString(comparison) || !isBooleanEqualityMatcher(matcher)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const preferredMatcher = determineMatcher(comparison.operator, (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value === !!modifier);
|
|
112
|
+
|
|
113
|
+
if (!preferredMatcher) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
context.report({
|
|
118
|
+
fix(fixer) {
|
|
119
|
+
const sourceCode = context.getSourceCode();
|
|
120
|
+
return [// replace the comparison argument with the left-hand side of the comparison
|
|
121
|
+
fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
|
|
122
|
+
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], `.${preferredMatcher}`), // replace the matcher argument with the right-hand side of the comparison
|
|
123
|
+
fixer.replaceText(matcher.arguments[0], sourceCode.getText(comparison.right))];
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
messageId: 'useToBeComparison',
|
|
127
|
+
data: {
|
|
128
|
+
preferredMatcher
|
|
129
|
+
},
|
|
130
|
+
node: (modifier || matcher).node.property
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
exports.default = _default;
|