eslint-plugin-jest 25.7.0 → 26.1.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/README.md +2 -1
- package/docs/rules/no-conditional-in-test.md +79 -0
- package/docs/rules/no-if.md +5 -0
- package/docs/rules/prefer-snapshot-hint.md +188 -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 +13 -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-snapshot-hint.js +112 -0
- 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 +9 -7
- package/CHANGELOG.md +0 -846
|
@@ -5,27 +5,27 @@ 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 findCallbackArg = (node, isJestEach) => {
|
|
13
13
|
if (isJestEach) {
|
|
14
14
|
return node.arguments[1];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if ((0,
|
|
17
|
+
if ((0, _utils2.isHook)(node) && node.arguments.length >= 1) {
|
|
18
18
|
return node.arguments[0];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
if ((0,
|
|
21
|
+
if ((0, _utils2.isTestCaseCall)(node) && node.arguments.length >= 2) {
|
|
22
22
|
return node.arguments[1];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
return null;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
var _default = (0,
|
|
28
|
+
var _default = (0, _utils2.createRule)({
|
|
29
29
|
name: __filename,
|
|
30
30
|
meta: {
|
|
31
31
|
docs: {
|
|
@@ -51,9 +51,9 @@ var _default = (0, _utils.createRule)({
|
|
|
51
51
|
var _getNodeName$endsWith, _getNodeName;
|
|
52
52
|
|
|
53
53
|
// done is the second argument for it.each, not the first
|
|
54
|
-
const isJestEach = (_getNodeName$endsWith = (_getNodeName = (0,
|
|
54
|
+
const isJestEach = (_getNodeName$endsWith = (_getNodeName = (0, _utils2.getNodeName)(node.callee)) === null || _getNodeName === void 0 ? void 0 : _getNodeName.endsWith('.each')) !== null && _getNodeName$endsWith !== void 0 ? _getNodeName$endsWith : false;
|
|
55
55
|
|
|
56
|
-
if (isJestEach && node.callee.type !==
|
|
56
|
+
if (isJestEach && node.callee.type !== _utils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
57
57
|
// isJestEach but not a TaggedTemplateExpression, so this must be
|
|
58
58
|
// the `jest.each([])()` syntax which this rule doesn't support due
|
|
59
59
|
// to its complexity (see jest-community/eslint-plugin-jest#710)
|
|
@@ -63,13 +63,13 @@ var _default = (0, _utils.createRule)({
|
|
|
63
63
|
const callback = findCallbackArg(node, isJestEach);
|
|
64
64
|
const callbackArgIndex = Number(isJestEach);
|
|
65
65
|
|
|
66
|
-
if (!callback || !(0,
|
|
66
|
+
if (!callback || !(0, _utils2.isFunction)(callback) || callback.params.length !== 1 + callbackArgIndex) {
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
const argument = callback.params[callbackArgIndex];
|
|
71
71
|
|
|
72
|
-
if (argument.type !==
|
|
72
|
+
if (argument.type !== _utils.AST_NODE_TYPES.Identifier) {
|
|
73
73
|
context.report({
|
|
74
74
|
node: argument,
|
|
75
75
|
messageId: 'noDoneCallback'
|
|
@@ -126,7 +126,7 @@ var _default = (0, _utils.createRule)({
|
|
|
126
126
|
let afterReplacement = ')';
|
|
127
127
|
let replaceBefore = true;
|
|
128
128
|
|
|
129
|
-
if (body.type ===
|
|
129
|
+
if (body.type === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
130
130
|
const keyword = 'return';
|
|
131
131
|
beforeReplacement = `${keyword} ${beforeReplacement}{`;
|
|
132
132
|
afterReplacement += '}';
|
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: {
|
|
@@ -30,6 +30,8 @@ var _default = (0, _utils.createRule)({
|
|
|
30
30
|
messages: {
|
|
31
31
|
conditionalInTest: 'Test should not contain {{ condition }} statements.'
|
|
32
32
|
},
|
|
33
|
+
deprecated: true,
|
|
34
|
+
replacedBy: ['no-conditional-in-test'],
|
|
33
35
|
schema: [],
|
|
34
36
|
type: 'suggestion'
|
|
35
37
|
},
|
|
@@ -56,10 +58,10 @@ var _default = (0, _utils.createRule)({
|
|
|
56
58
|
|
|
57
59
|
return {
|
|
58
60
|
CallExpression(node) {
|
|
59
|
-
if ((0,
|
|
61
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
60
62
|
stack.push(true);
|
|
61
63
|
|
|
62
|
-
if ((0,
|
|
64
|
+
if ((0, _utils2.getNodeName)(node).endsWith('each')) {
|
|
63
65
|
stack.push(true);
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -71,7 +73,7 @@ var _default = (0, _utils.createRule)({
|
|
|
71
73
|
|
|
72
74
|
FunctionDeclaration(node) {
|
|
73
75
|
const declaredVariables = context.getDeclaredVariables(node);
|
|
74
|
-
const testCallExpressions = (0,
|
|
76
|
+
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
|
75
77
|
stack.push(testCallExpressions.length > 0);
|
|
76
78
|
},
|
|
77
79
|
|
|
@@ -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',
|
|
@@ -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;
|