eslint-plugin-jest 24.4.2 → 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 +75 -50
- package/docs/rules/expect-expect.md +42 -1
- package/docs/rules/max-nested-describe.md +4 -5
- package/docs/rules/no-conditional-expect.md +57 -3
- package/docs/rules/no-conditional-in-test.md +79 -0
- package/docs/rules/no-deprecated-functions.md +5 -0
- package/docs/rules/no-done-callback.md +3 -3
- package/docs/rules/no-if.md +5 -0
- package/docs/rules/no-standalone-expect.md +3 -3
- package/docs/rules/no-test-return-statement.md +1 -2
- package/docs/rules/prefer-comparison-matcher.md +55 -0
- package/docs/rules/prefer-equality-matcher.md +29 -0
- package/docs/rules/prefer-expect-assertions.md +126 -0
- package/docs/rules/prefer-expect-resolves.md +53 -0
- package/docs/rules/prefer-hooks-on-top.md +72 -48
- package/docs/rules/{lowercase-name.md → prefer-lowercase-title.md} +7 -7
- package/docs/rules/prefer-snapshot-hint.md +188 -0
- package/docs/rules/prefer-to-be.md +53 -0
- package/docs/rules/require-hook.md +187 -0
- package/docs/rules/require-top-level-describe.md +28 -0
- package/docs/rules/{valid-describe.md → valid-describe-callback.md} +1 -1
- package/docs/rules/valid-expect-in-promise.md +55 -14
- package/docs/rules/valid-expect.md +13 -0
- package/docs/rules/valid-title.md +30 -2
- package/lib/index.js +2 -3
- package/lib/processors/snapshot-processor.js +1 -1
- package/lib/rules/consistent-test-it.js +20 -20
- package/lib/rules/detectJestVersion.js +29 -0
- package/lib/rules/expect-expect.js +25 -11
- 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 +14 -32
- 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-identical-title.js +3 -3
- 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 +11 -11
- 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 +93 -11
- package/lib/rules/prefer-expect-resolves.js +48 -0
- package/lib/rules/prefer-hooks-on-top.js +1 -1
- package/lib/rules/{lowercase-name.js → prefer-lowercase-title.js} +20 -1
- 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 +136 -0
- package/lib/rules/prefer-to-contain.js +19 -67
- package/lib/rules/prefer-to-have-length.js +9 -14
- package/lib/rules/prefer-todo.js +9 -9
- package/lib/rules/require-hook.js +121 -0
- package/lib/rules/require-top-level-describe.js +40 -6
- package/lib/rules/utils.js +34 -30
- package/lib/rules/{valid-describe.js → valid-describe-callback.js} +9 -9
- package/lib/rules/valid-expect-in-promise.js +336 -67
- package/lib/rules/valid-expect.js +36 -19
- package/lib/rules/valid-title.js +61 -61
- package/package.json +40 -27
- package/CHANGELOG.md +0 -513
- package/docs/rules/no-expect-resolves.md +0 -47
- package/docs/rules/no-truthy-falsy.md +0 -53
- package/docs/rules/no-try-expect.md +0 -63
- package/docs/rules/prefer-inline-snapshots.md +0 -51
- package/docs/rules/prefer-to-be-null.md +0 -33
- package/docs/rules/prefer-to-be-undefined.md +0 -33
- package/lib/rules/no-expect-resolves.js +0 -40
- package/lib/rules/no-truthy-falsy.js +0 -58
- package/lib/rules/no-try-expect.js +0 -89
- package/lib/rules/prefer-inline-snapshots.js +0 -69
- package/lib/rules/prefer-to-be-null.js +0 -67
- package/lib/rules/prefer-to-be-undefined.js +0 -67
|
@@ -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 isCatchCall = node => node.callee.type ===
|
|
12
|
+
const isCatchCall = node => node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property, 'catch');
|
|
13
13
|
|
|
14
|
-
var _default = (0,
|
|
14
|
+
var _default = (0, _utils2.createRule)({
|
|
15
15
|
name: __filename,
|
|
16
16
|
meta: {
|
|
17
17
|
docs: {
|
|
@@ -39,7 +39,7 @@ var _default = (0, _utils.createRule)({
|
|
|
39
39
|
return {
|
|
40
40
|
FunctionDeclaration(node) {
|
|
41
41
|
const declaredVariables = context.getDeclaredVariables(node);
|
|
42
|
-
const testCallExpressions = (0,
|
|
42
|
+
const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
|
|
43
43
|
|
|
44
44
|
if (testCallExpressions.length > 0) {
|
|
45
45
|
inTestCase = true;
|
|
@@ -47,7 +47,7 @@ var _default = (0, _utils.createRule)({
|
|
|
47
47
|
},
|
|
48
48
|
|
|
49
49
|
CallExpression(node) {
|
|
50
|
-
if ((0,
|
|
50
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
51
51
|
inTestCase = true;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -55,14 +55,14 @@ var _default = (0, _utils.createRule)({
|
|
|
55
55
|
inPromiseCatch = true;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
if (inTestCase && (0,
|
|
58
|
+
if (inTestCase && (0, _utils2.isExpectCall)(node) && conditionalDepth > 0) {
|
|
59
59
|
context.report({
|
|
60
60
|
messageId: 'conditionalExpect',
|
|
61
61
|
node
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
if (inPromiseCatch && (0,
|
|
65
|
+
if (inPromiseCatch && (0, _utils2.isExpectCall)(node)) {
|
|
66
66
|
context.report({
|
|
67
67
|
messageId: 'conditionalExpect',
|
|
68
68
|
node
|
|
@@ -71,7 +71,7 @@ var _default = (0, _utils.createRule)({
|
|
|
71
71
|
},
|
|
72
72
|
|
|
73
73
|
'CallExpression:exit'(node) {
|
|
74
|
-
if ((0,
|
|
74
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
75
75
|
inTestCase = false;
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
|
|
10
|
+
var _default = (0, _utils.createRule)({
|
|
11
|
+
name: __filename,
|
|
12
|
+
meta: {
|
|
13
|
+
docs: {
|
|
14
|
+
description: 'Disallow conditional logic in tests',
|
|
15
|
+
category: 'Best Practices',
|
|
16
|
+
recommended: false
|
|
17
|
+
},
|
|
18
|
+
messages: {
|
|
19
|
+
conditionalInTest: 'Avoid having conditionals in tests'
|
|
20
|
+
},
|
|
21
|
+
type: 'problem',
|
|
22
|
+
schema: []
|
|
23
|
+
},
|
|
24
|
+
defaultOptions: [],
|
|
25
|
+
|
|
26
|
+
create(context) {
|
|
27
|
+
let inTestCase = false;
|
|
28
|
+
|
|
29
|
+
const maybeReportConditional = node => {
|
|
30
|
+
if (inTestCase) {
|
|
31
|
+
context.report({
|
|
32
|
+
messageId: 'conditionalInTest',
|
|
33
|
+
node
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
CallExpression(node) {
|
|
40
|
+
if ((0, _utils.isTestCaseCall)(node)) {
|
|
41
|
+
inTestCase = true;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
'CallExpression:exit'(node) {
|
|
46
|
+
if ((0, _utils.isTestCaseCall)(node)) {
|
|
47
|
+
inTestCase = false;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
IfStatement: maybeReportConditional,
|
|
52
|
+
SwitchStatement: maybeReportConditional,
|
|
53
|
+
ConditionalExpression: maybeReportConditional,
|
|
54
|
+
LogicalExpression: maybeReportConditional
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
exports.default = _default;
|
|
@@ -3,42 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _detectJestVersion = require("./detectJestVersion");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
/** @internal */
|
|
12
|
+
var _utils2 = require("./utils");
|
|
14
13
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const detectJestVersion = () => {
|
|
20
|
-
if (cachedJestVersion) {
|
|
21
|
-
return cachedJestVersion;
|
|
14
|
+
const parseJestVersion = rawVersion => {
|
|
15
|
+
if (typeof rawVersion === 'number') {
|
|
16
|
+
return rawVersion;
|
|
22
17
|
}
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
paths: [process.cwd()]
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const jestPackageJson = // eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
30
|
-
require(jestPath);
|
|
31
|
-
|
|
32
|
-
if (jestPackageJson.version) {
|
|
33
|
-
const [majorVersion] = jestPackageJson.version.split('.');
|
|
34
|
-
return cachedJestVersion = parseInt(majorVersion, 10);
|
|
35
|
-
}
|
|
36
|
-
} catch {}
|
|
37
|
-
|
|
38
|
-
throw new Error('Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly');
|
|
19
|
+
const [majorVersion] = rawVersion.split('.');
|
|
20
|
+
return parseInt(majorVersion, 10);
|
|
39
21
|
};
|
|
40
22
|
|
|
41
|
-
var _default = (0,
|
|
23
|
+
var _default = (0, _utils2.createRule)({
|
|
42
24
|
name: __filename,
|
|
43
25
|
meta: {
|
|
44
26
|
docs: {
|
|
@@ -58,7 +40,7 @@ var _default = (0, _utils.createRule)({
|
|
|
58
40
|
create(context) {
|
|
59
41
|
var _context$settings, _context$settings$jes;
|
|
60
42
|
|
|
61
|
-
const jestVersion = ((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || detectJestVersion();
|
|
43
|
+
const jestVersion = parseJestVersion(((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || (0, _detectJestVersion.detectJestVersion)());
|
|
62
44
|
const deprecations = { ...(jestVersion >= 15 && {
|
|
63
45
|
'jest.resetModuleRegistry': 'jest.resetModules'
|
|
64
46
|
}),
|
|
@@ -78,11 +60,11 @@ var _default = (0, _utils.createRule)({
|
|
|
78
60
|
};
|
|
79
61
|
return {
|
|
80
62
|
CallExpression(node) {
|
|
81
|
-
if (node.callee.type !==
|
|
63
|
+
if (node.callee.type !== _utils.AST_NODE_TYPES.MemberExpression) {
|
|
82
64
|
return;
|
|
83
65
|
}
|
|
84
66
|
|
|
85
|
-
const deprecation = (0,
|
|
67
|
+
const deprecation = (0, _utils2.getNodeName)(node);
|
|
86
68
|
|
|
87
69
|
if (!deprecation || !(deprecation in deprecations)) {
|
|
88
70
|
return;
|
|
@@ -103,7 +85,7 @@ var _default = (0, _utils.createRule)({
|
|
|
103
85
|
fix(fixer) {
|
|
104
86
|
let [name, func] = replacement.split('.');
|
|
105
87
|
|
|
106
|
-
if (callee.property.type ===
|
|
88
|
+
if (callee.property.type === _utils.AST_NODE_TYPES.Literal) {
|
|
107
89
|
func = `'${func}'`;
|
|
108
90
|
}
|
|
109
91
|
|
|
@@ -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
|
}
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _experimentalUtils = require("@typescript-eslint/experimental-utils");
|
|
9
|
-
|
|
10
8
|
var _utils = require("./utils");
|
|
11
9
|
|
|
12
10
|
const newDescribeContext = () => ({
|
|
@@ -35,13 +33,15 @@ var _default = (0, _utils.createRule)({
|
|
|
35
33
|
const contexts = [newDescribeContext()];
|
|
36
34
|
return {
|
|
37
35
|
CallExpression(node) {
|
|
36
|
+
var _getNodeName;
|
|
37
|
+
|
|
38
38
|
const currentLayer = contexts[contexts.length - 1];
|
|
39
39
|
|
|
40
40
|
if ((0, _utils.isDescribeCall)(node)) {
|
|
41
41
|
contexts.push(newDescribeContext());
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if (node.callee
|
|
44
|
+
if ((_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 && _getNodeName.endsWith('.each')) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
|
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: {
|
|
@@ -100,24 +100,24 @@ var _default = (0, _utils.createRule)({
|
|
|
100
100
|
|
|
101
101
|
return {
|
|
102
102
|
CallExpression(node) {
|
|
103
|
-
var _matcher$
|
|
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 :
|
|
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
|
|
|
117
|
-
if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name)) {
|
|
117
|
+
if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name) && (_matcher$arguments = matcher.arguments) !== null && _matcher$arguments !== void 0 && _matcher$arguments.length) {
|
|
118
118
|
var _options$inlineMaxSiz;
|
|
119
119
|
|
|
120
|
-
reportOnViolation(context, matcher.
|
|
120
|
+
reportOnViolation(context, matcher.arguments[0], { ...options,
|
|
121
121
|
maxSize: (_options$inlineMaxSiz = options.inlineMaxSize) !== null && _options$inlineMaxSiz !== void 0 ? _options$inlineMaxSiz : options.maxSize
|
|
122
122
|
});
|
|
123
123
|
}
|