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
|
@@ -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,7 +23,7 @@ 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
|
/**
|
|
29
29
|
* Checks if the given `node` is a `CallExpression` representing the calling
|
|
@@ -33,10 +33,10 @@ const isBooleanEqualityMatcher = matcher => (0, _utils.isParsedEqualityMatcherCa
|
|
|
33
33
|
*
|
|
34
34
|
* @return {node is FixableIncludesCallExpression}
|
|
35
35
|
*/
|
|
36
|
-
const isFixableIncludesCallExpression = node => node.type ===
|
|
36
|
+
const isFixableIncludesCallExpression = node => node.type === _utils.AST_NODE_TYPES.CallExpression && node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property, 'includes') && (0, _utils2.hasOnlyOneArgument)(node); // expect(array.includes(<value>)[not.]{toBe,toEqual}(<boolean>)
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
var _default = (0,
|
|
39
|
+
var _default = (0, _utils2.createRule)({
|
|
40
40
|
name: __filename,
|
|
41
41
|
meta: {
|
|
42
42
|
docs: {
|
|
@@ -56,7 +56,7 @@ var _default = (0, _utils.createRule)({
|
|
|
56
56
|
create(context) {
|
|
57
57
|
return {
|
|
58
58
|
CallExpression(node) {
|
|
59
|
-
if (!(0,
|
|
59
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -67,9 +67,9 @@ var _default = (0, _utils.createRule)({
|
|
|
67
67
|
},
|
|
68
68
|
matcher,
|
|
69
69
|
modifier
|
|
70
|
-
} = (0,
|
|
70
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
71
71
|
|
|
72
|
-
if (!matcher || !includesCall || modifier && modifier.name !==
|
|
72
|
+
if (!matcher || !includesCall || modifier && modifier.name !== _utils2.ModifierName.not || !isBooleanEqualityMatcher(matcher) || !isFixableIncludesCallExpression(includesCall)) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -78,10 +78,10 @@ var _default = (0, _utils.createRule)({
|
|
|
78
78
|
const sourceCode = context.getSourceCode(); // we need to negate the expectation if the current expected
|
|
79
79
|
// value is itself negated by the "not" modifier
|
|
80
80
|
|
|
81
|
-
const addNotModifier = (0,
|
|
81
|
+
const addNotModifier = (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value === !!modifier;
|
|
82
82
|
return [// remove the "includes" call entirely
|
|
83
83
|
fixer.removeRange([includesCall.callee.property.range[0] - 1, includesCall.range[1]]), // replace the current matcher with "toContain", adding "not" if needed
|
|
84
|
-
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${
|
|
84
|
+
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${_utils2.ModifierName.not}.toContain` : '.toContain'), // replace the matcher argument with the value from the "includes"
|
|
85
85
|
fixer.replaceText(matcher.arguments[0], sourceCode.getText(includesCall.arguments[0]))];
|
|
86
86
|
},
|
|
87
87
|
|
|
@@ -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
|
create(context) {
|
|
30
30
|
return {
|
|
31
31
|
CallExpression(node) {
|
|
32
|
-
if (!(0,
|
|
32
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -38,9 +38,9 @@ var _default = (0, _utils.createRule)({
|
|
|
38
38
|
arguments: [argument]
|
|
39
39
|
},
|
|
40
40
|
matcher
|
|
41
|
-
} = (0,
|
|
41
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
42
42
|
|
|
43
|
-
if (!matcher || !(0,
|
|
43
|
+
if (!matcher || !(0, _utils2.isParsedEqualityMatcherCall)(matcher) || (argument === null || argument === void 0 ? void 0 : argument.type) !== _utils.AST_NODE_TYPES.MemberExpression || !(0, _utils2.isSupportedAccessor)(argument.property, 'length')) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
|
package/lib/rules/prefer-todo.js
CHANGED
|
@@ -5,26 +5,26 @@ 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
|
function isEmptyFunction(node) {
|
|
13
|
-
if (!(0,
|
|
13
|
+
if (!(0, _utils2.isFunction)(node)) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
return node.body.type ===
|
|
17
|
+
return node.body.type === _utils.AST_NODE_TYPES.BlockStatement && !node.body.body.length;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function createTodoFixer(node, fixer) {
|
|
21
|
-
const testName = (0,
|
|
21
|
+
const testName = (0, _utils2.getNodeName)(node).split('.').shift();
|
|
22
22
|
return fixer.replaceText(node.callee, `${testName}.todo`);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const isTargetedTestCase = node => (0,
|
|
25
|
+
const isTargetedTestCase = node => (0, _utils2.isTestCaseCall)(node) && [_utils2.TestCaseName.it, _utils2.TestCaseName.test, 'it.skip', 'test.skip'].includes((0, _utils2.getNodeName)(node));
|
|
26
26
|
|
|
27
|
-
var _default = (0,
|
|
27
|
+
var _default = (0, _utils2.createRule)({
|
|
28
28
|
name: __filename,
|
|
29
29
|
meta: {
|
|
30
30
|
docs: {
|
|
@@ -47,7 +47,7 @@ var _default = (0, _utils.createRule)({
|
|
|
47
47
|
CallExpression(node) {
|
|
48
48
|
const [title, callback] = node.arguments;
|
|
49
49
|
|
|
50
|
-
if (!title || !isTargetedTestCase(node) || !(0,
|
|
50
|
+
if (!title || !isTargetedTestCase(node) || !(0, _utils2.isStringNode)(title)) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -59,7 +59,7 @@ var _default = (0, _utils.createRule)({
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
if ((0,
|
|
62
|
+
if ((0, _utils2.hasOnlyOneArgument)(node)) {
|
|
63
63
|
context.report({
|
|
64
64
|
messageId: 'unimplementedTest',
|
|
65
65
|
node,
|
|
@@ -5,33 +5,33 @@ 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 isJestFnCall = node => {
|
|
13
13
|
var _getNodeName;
|
|
14
14
|
|
|
15
|
-
if ((0,
|
|
15
|
+
if ((0, _utils2.isDescribeCall)(node) || (0, _utils2.isTestCaseCall)(node) || (0, _utils2.isHook)(node)) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
return !!((_getNodeName = (0,
|
|
19
|
+
return !!((_getNodeName = (0, _utils2.getNodeName)(node)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith('jest.'));
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const isNullOrUndefined = node => {
|
|
23
|
-
return node.type ===
|
|
23
|
+
return node.type === _utils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils2.isIdentifier)(node, 'undefined');
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const shouldBeInHook = (node, allowedFunctionCalls = []) => {
|
|
27
27
|
switch (node.type) {
|
|
28
|
-
case
|
|
28
|
+
case _utils.AST_NODE_TYPES.ExpressionStatement:
|
|
29
29
|
return shouldBeInHook(node.expression, allowedFunctionCalls);
|
|
30
30
|
|
|
31
|
-
case
|
|
32
|
-
return !(isJestFnCall(node) || allowedFunctionCalls.includes((0,
|
|
31
|
+
case _utils.AST_NODE_TYPES.CallExpression:
|
|
32
|
+
return !(isJestFnCall(node) || allowedFunctionCalls.includes((0, _utils2.getNodeName)(node)));
|
|
33
33
|
|
|
34
|
-
case
|
|
34
|
+
case _utils.AST_NODE_TYPES.VariableDeclaration:
|
|
35
35
|
{
|
|
36
36
|
if (node.kind === 'const') {
|
|
37
37
|
return false;
|
|
@@ -47,7 +47,7 @@ const shouldBeInHook = (node, allowedFunctionCalls = []) => {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
var _default = (0,
|
|
50
|
+
var _default = (0, _utils2.createRule)({
|
|
51
51
|
name: __filename,
|
|
52
52
|
meta: {
|
|
53
53
|
docs: {
|
|
@@ -100,13 +100,13 @@ var _default = (0, _utils.createRule)({
|
|
|
100
100
|
},
|
|
101
101
|
|
|
102
102
|
CallExpression(node) {
|
|
103
|
-
if (!(0,
|
|
103
|
+
if (!(0, _utils2.isDescribeCall)(node) || node.arguments.length < 2) {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
const [, testFn] = node.arguments;
|
|
108
108
|
|
|
109
|
-
if (!(0,
|
|
109
|
+
if (!(0, _utils2.isFunction)(testFn) || testFn.body.type !== _utils.AST_NODE_TYPES.BlockStatement) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
|
package/lib/rules/utils.js
CHANGED
|
@@ -9,20 +9,20 @@ exports.scopeHasLocalReference = exports.parseExpectCall = exports.isTestCaseCal
|
|
|
9
9
|
|
|
10
10
|
var _path = require("path");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _utils = require("@typescript-eslint/utils");
|
|
13
13
|
|
|
14
14
|
var _package = require("../../package.json");
|
|
15
15
|
|
|
16
16
|
const REPO_URL = 'https://github.com/jest-community/eslint-plugin-jest';
|
|
17
17
|
|
|
18
|
-
const createRule =
|
|
18
|
+
const createRule = _utils.ESLintUtils.RuleCreator(name => {
|
|
19
19
|
const ruleName = (0, _path.parse)(name).name;
|
|
20
20
|
return `${REPO_URL}/blob/v${_package.version}/docs/rules/${ruleName}.md`;
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
exports.createRule = createRule;
|
|
24
24
|
|
|
25
|
-
const isTypeCastExpression = node => node.type ===
|
|
25
|
+
const isTypeCastExpression = node => node.type === _utils.AST_NODE_TYPES.TSAsExpression || node.type === _utils.AST_NODE_TYPES.TSTypeAssertion;
|
|
26
26
|
|
|
27
27
|
const followTypeAssertionChain = expression => isTypeCastExpression(expression) ? followTypeAssertionChain(expression.expression) : expression;
|
|
28
28
|
/**
|
|
@@ -45,7 +45,7 @@ exports.followTypeAssertionChain = followTypeAssertionChain;
|
|
|
45
45
|
*
|
|
46
46
|
* @template V
|
|
47
47
|
*/
|
|
48
|
-
const isStringLiteral = (node, value) => node.type ===
|
|
48
|
+
const isStringLiteral = (node, value) => node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'string' && (value === undefined || node.value === value);
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Checks if the given `node` is a `TemplateLiteral`.
|
|
@@ -62,7 +62,7 @@ const isStringLiteral = (node, value) => node.type === _experimentalUtils.AST_NO
|
|
|
62
62
|
*
|
|
63
63
|
* @template V
|
|
64
64
|
*/
|
|
65
|
-
const isTemplateLiteral = (node, value) => node.type ===
|
|
65
|
+
const isTemplateLiteral = (node, value) => node.type === _utils.AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1 && ( // bail out if not simple
|
|
66
66
|
value === undefined || node.quasis[0].value.raw === value);
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -128,7 +128,7 @@ exports.hasOnlyOneArgument = hasOnlyOneArgument;
|
|
|
128
128
|
*
|
|
129
129
|
* @template V
|
|
130
130
|
*/
|
|
131
|
-
const isIdentifier = (node, name) => node.type ===
|
|
131
|
+
const isIdentifier = (node, name) => node.type === _utils.AST_NODE_TYPES.Identifier && (name === undefined || node.name === name);
|
|
132
132
|
/**
|
|
133
133
|
* Checks if the given `node` is a "supported accessor".
|
|
134
134
|
*
|
|
@@ -170,7 +170,7 @@ const isSupportedAccessor = (node, value) => isIdentifier(node, value) || isStri
|
|
|
170
170
|
|
|
171
171
|
exports.isSupportedAccessor = isSupportedAccessor;
|
|
172
172
|
|
|
173
|
-
const getAccessorValue = accessor => accessor.type ===
|
|
173
|
+
const getAccessorValue = accessor => accessor.type === _utils.AST_NODE_TYPES.Identifier ? accessor.name : getStringValue(accessor);
|
|
174
174
|
|
|
175
175
|
exports.getAccessorValue = getAccessorValue;
|
|
176
176
|
|
|
@@ -186,11 +186,11 @@ exports.getAccessorValue = getAccessorValue;
|
|
|
186
186
|
*
|
|
187
187
|
* @return {node is ExpectCall}
|
|
188
188
|
*/
|
|
189
|
-
const isExpectCall = node => node.type ===
|
|
189
|
+
const isExpectCall = node => node.type === _utils.AST_NODE_TYPES.CallExpression && isSupportedAccessor(node.callee, 'expect') && node.parent !== undefined;
|
|
190
190
|
|
|
191
191
|
exports.isExpectCall = isExpectCall;
|
|
192
192
|
|
|
193
|
-
const isExpectMember = (node, name) => node.type ===
|
|
193
|
+
const isExpectMember = (node, name) => node.type === _utils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.property, name);
|
|
194
194
|
/**
|
|
195
195
|
* Represents all the jest matchers.
|
|
196
196
|
*/
|
|
@@ -235,7 +235,7 @@ const reparseAsMatcher = parsedMember => ({ ...parsedMember,
|
|
|
235
235
|
*
|
|
236
236
|
* If this matcher isn't called, this will be `null`.
|
|
237
237
|
*/
|
|
238
|
-
arguments: parsedMember.node.parent.type ===
|
|
238
|
+
arguments: parsedMember.node.parent.type === _utils.AST_NODE_TYPES.CallExpression ? parsedMember.node.parent.arguments : null
|
|
239
239
|
});
|
|
240
240
|
/**
|
|
241
241
|
* Re-parses the given `parsedMember` as a `ParsedExpectModifier`.
|
|
@@ -366,25 +366,25 @@ function getNodeName(node) {
|
|
|
366
366
|
}
|
|
367
367
|
|
|
368
368
|
switch (node.type) {
|
|
369
|
-
case
|
|
369
|
+
case _utils.AST_NODE_TYPES.TaggedTemplateExpression:
|
|
370
370
|
return getNodeName(node.tag);
|
|
371
371
|
|
|
372
|
-
case
|
|
372
|
+
case _utils.AST_NODE_TYPES.MemberExpression:
|
|
373
373
|
return joinNames(getNodeName(node.object), getNodeName(node.property));
|
|
374
374
|
|
|
375
|
-
case
|
|
376
|
-
case
|
|
375
|
+
case _utils.AST_NODE_TYPES.NewExpression:
|
|
376
|
+
case _utils.AST_NODE_TYPES.CallExpression:
|
|
377
377
|
return getNodeName(node.callee);
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
return null;
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
-
const isFunction = node => node.type ===
|
|
383
|
+
const isFunction = node => node.type === _utils.AST_NODE_TYPES.FunctionExpression || node.type === _utils.AST_NODE_TYPES.ArrowFunctionExpression;
|
|
384
384
|
|
|
385
385
|
exports.isFunction = isFunction;
|
|
386
386
|
|
|
387
|
-
const isHook = node => node.callee.type ===
|
|
387
|
+
const isHook = node => node.callee.type === _utils.AST_NODE_TYPES.Identifier && HookName.hasOwnProperty(node.callee.name);
|
|
388
388
|
|
|
389
389
|
exports.isHook = isHook;
|
|
390
390
|
|
|
@@ -393,12 +393,12 @@ const getTestCallExpressionsFromDeclaredVariables = declaredVariables => {
|
|
|
393
393
|
references
|
|
394
394
|
}) => acc.concat(references.map(({
|
|
395
395
|
identifier
|
|
396
|
-
}) => identifier.parent).filter(node => !!node && node.type ===
|
|
396
|
+
}) => identifier.parent).filter(node => !!node && node.type === _utils.AST_NODE_TYPES.CallExpression && isTestCaseCall(node))), []);
|
|
397
397
|
};
|
|
398
398
|
|
|
399
399
|
exports.getTestCallExpressionsFromDeclaredVariables = getTestCallExpressionsFromDeclaredVariables;
|
|
400
400
|
|
|
401
|
-
const isTestCaseName = node => node.type ===
|
|
401
|
+
const isTestCaseName = node => node.type === _utils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.name);
|
|
402
402
|
|
|
403
403
|
const isTestCaseProperty = node => isSupportedAccessor(node) && TestCaseProperty.hasOwnProperty(getAccessorValue(node));
|
|
404
404
|
/**
|
|
@@ -419,15 +419,15 @@ const isTestCaseCall = node => {
|
|
|
419
419
|
return true;
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
const callee = node.callee.type ===
|
|
422
|
+
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;
|
|
423
423
|
|
|
424
|
-
if (callee.type ===
|
|
424
|
+
if (callee.type === _utils.AST_NODE_TYPES.MemberExpression && isTestCaseProperty(callee.property)) {
|
|
425
425
|
// if we're an `each()`, ensure we're the outer CallExpression (i.e `.each()()`)
|
|
426
|
-
if (getAccessorValue(callee.property) === 'each' && node.callee.type !==
|
|
426
|
+
if (getAccessorValue(callee.property) === 'each' && node.callee.type !== _utils.AST_NODE_TYPES.TaggedTemplateExpression && node.callee.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
427
427
|
return false;
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
-
return callee.object.type ===
|
|
430
|
+
return callee.object.type === _utils.AST_NODE_TYPES.MemberExpression ? isTestCaseName(callee.object.object) : isTestCaseName(callee.object);
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
return false;
|
|
@@ -435,7 +435,7 @@ const isTestCaseCall = node => {
|
|
|
435
435
|
|
|
436
436
|
exports.isTestCaseCall = isTestCaseCall;
|
|
437
437
|
|
|
438
|
-
const isDescribeAlias = node => node.type ===
|
|
438
|
+
const isDescribeAlias = node => node.type === _utils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.name);
|
|
439
439
|
|
|
440
440
|
const isDescribeProperty = node => isSupportedAccessor(node) && DescribeProperty.hasOwnProperty(getAccessorValue(node));
|
|
441
441
|
/**
|
|
@@ -456,15 +456,15 @@ const isDescribeCall = node => {
|
|
|
456
456
|
return true;
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
const callee = node.callee.type ===
|
|
459
|
+
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;
|
|
460
460
|
|
|
461
|
-
if (callee.type ===
|
|
461
|
+
if (callee.type === _utils.AST_NODE_TYPES.MemberExpression && isDescribeProperty(callee.property)) {
|
|
462
462
|
// if we're an `each()`, ensure we're the outer CallExpression (i.e `.each()()`)
|
|
463
|
-
if (getAccessorValue(callee.property) === 'each' && node.callee.type !==
|
|
463
|
+
if (getAccessorValue(callee.property) === 'each' && node.callee.type !== _utils.AST_NODE_TYPES.TaggedTemplateExpression && node.callee.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
464
464
|
return false;
|
|
465
465
|
}
|
|
466
466
|
|
|
467
|
-
return callee.object.type ===
|
|
467
|
+
return callee.object.type === _utils.AST_NODE_TYPES.MemberExpression ? isDescribeAlias(callee.object.object) : isDescribeAlias(callee.object);
|
|
468
468
|
}
|
|
469
469
|
|
|
470
470
|
return false;
|
|
@@ -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 paramsLocation = params => {
|
|
13
13
|
const [first] = params;
|
|
@@ -18,7 +18,7 @@ const paramsLocation = params => {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
var _default = (0,
|
|
21
|
+
var _default = (0, _utils2.createRule)({
|
|
22
22
|
name: __filename,
|
|
23
23
|
meta: {
|
|
24
24
|
type: 'problem',
|
|
@@ -41,7 +41,7 @@ var _default = (0, _utils.createRule)({
|
|
|
41
41
|
create(context) {
|
|
42
42
|
return {
|
|
43
43
|
CallExpression(node) {
|
|
44
|
-
if (!(0,
|
|
44
|
+
if (!(0, _utils2.isDescribeCall)(node)) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -62,7 +62,7 @@ var _default = (0, _utils.createRule)({
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
if (!(0,
|
|
65
|
+
if (!(0, _utils2.isFunction)(callback)) {
|
|
66
66
|
context.report({
|
|
67
67
|
messageId: 'secondArgumentMustBeFunction',
|
|
68
68
|
loc: paramsLocation(node.arguments)
|
|
@@ -77,23 +77,23 @@ var _default = (0, _utils.createRule)({
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
if (!(0,
|
|
80
|
+
if (!(0, _utils2.getNodeName)(node).endsWith('each') && callback.params.length) {
|
|
81
81
|
context.report({
|
|
82
82
|
messageId: 'unexpectedDescribeArgument',
|
|
83
83
|
loc: paramsLocation(callback.params)
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
if (callback.body.type ===
|
|
87
|
+
if (callback.body.type === _utils.AST_NODE_TYPES.CallExpression) {
|
|
88
88
|
context.report({
|
|
89
89
|
messageId: 'unexpectedReturnInDescribe',
|
|
90
90
|
node: callback
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
if (callback.body.type ===
|
|
94
|
+
if (callback.body.type === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
95
95
|
callback.body.body.forEach(node => {
|
|
96
|
-
if (node.type ===
|
|
96
|
+
if (node.type === _utils.AST_NODE_TYPES.ReturnStatement) {
|
|
97
97
|
context.report({
|
|
98
98
|
messageId: 'unexpectedReturnInDescribe',
|
|
99
99
|
node
|