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.
Files changed (38) hide show
  1. package/README.md +2 -1
  2. package/docs/rules/no-conditional-in-test.md +79 -0
  3. package/docs/rules/no-if.md +5 -0
  4. package/docs/rules/prefer-snapshot-hint.md +188 -0
  5. package/lib/rules/consistent-test-it.js +20 -20
  6. package/lib/rules/expect-expect.js +9 -9
  7. package/lib/rules/max-nested-describe.js +5 -5
  8. package/lib/rules/no-conditional-expect.js +9 -9
  9. package/lib/rules/no-conditional-in-test.js +60 -0
  10. package/lib/rules/no-deprecated-functions.js +6 -6
  11. package/lib/rules/no-done-callback.js +10 -10
  12. package/lib/rules/no-export.js +6 -6
  13. package/lib/rules/no-focused-tests.js +11 -11
  14. package/lib/rules/no-if.js +13 -11
  15. package/lib/rules/no-interpolation-in-snapshots.js +6 -6
  16. package/lib/rules/no-jasmine-globals.js +10 -10
  17. package/lib/rules/no-large-snapshots.js +8 -8
  18. package/lib/rules/no-standalone-expect.js +14 -14
  19. package/lib/rules/no-test-prefixes.js +6 -6
  20. package/lib/rules/no-test-return-statement.js +8 -8
  21. package/lib/rules/prefer-comparison-matcher.js +10 -10
  22. package/lib/rules/prefer-equality-matcher.js +10 -10
  23. package/lib/rules/prefer-expect-assertions.js +12 -12
  24. package/lib/rules/prefer-expect-resolves.js +4 -4
  25. package/lib/rules/prefer-snapshot-hint.js +112 -0
  26. package/lib/rules/prefer-spy-on.js +9 -9
  27. package/lib/rules/prefer-to-be.js +15 -15
  28. package/lib/rules/prefer-to-contain.js +11 -11
  29. package/lib/rules/prefer-to-have-length.js +6 -6
  30. package/lib/rules/prefer-todo.js +9 -9
  31. package/lib/rules/require-hook.js +12 -12
  32. package/lib/rules/utils.js +27 -27
  33. package/lib/rules/valid-describe-callback.js +9 -9
  34. package/lib/rules/valid-expect-in-promise.js +44 -44
  35. package/lib/rules/valid-expect.js +18 -18
  36. package/lib/rules/valid-title.js +14 -14
  37. package/package.json +9 -7
  38. package/CHANGELOG.md +0 -846
@@ -5,33 +5,33 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _experimentalUtils = require("@typescript-eslint/experimental-utils");
8
+ var _utils = require("@typescript-eslint/utils");
9
9
 
10
- var _utils = require("./utils");
10
+ var _utils2 = require("./utils");
11
11
 
12
12
  const isJestFnCall = node => {
13
13
  var _getNodeName;
14
14
 
15
- if ((0, _utils.isDescribeCall)(node) || (0, _utils.isTestCaseCall)(node) || (0, _utils.isHook)(node)) {
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, _utils.getNodeName)(node)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith('jest.'));
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 === _experimentalUtils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils.isIdentifier)(node, 'undefined');
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 _experimentalUtils.AST_NODE_TYPES.ExpressionStatement:
28
+ case _utils.AST_NODE_TYPES.ExpressionStatement:
29
29
  return shouldBeInHook(node.expression, allowedFunctionCalls);
30
30
 
31
- case _experimentalUtils.AST_NODE_TYPES.CallExpression:
32
- return !(isJestFnCall(node) || allowedFunctionCalls.includes((0, _utils.getNodeName)(node)));
31
+ case _utils.AST_NODE_TYPES.CallExpression:
32
+ return !(isJestFnCall(node) || allowedFunctionCalls.includes((0, _utils2.getNodeName)(node)));
33
33
 
34
- case _experimentalUtils.AST_NODE_TYPES.VariableDeclaration:
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, _utils.createRule)({
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, _utils.isDescribeCall)(node) || node.arguments.length < 2) {
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, _utils.isFunction)(testFn) || testFn.body.type !== _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
109
+ if (!(0, _utils2.isFunction)(testFn) || testFn.body.type !== _utils.AST_NODE_TYPES.BlockStatement) {
110
110
  return;
111
111
  }
112
112
 
@@ -9,20 +9,20 @@ exports.scopeHasLocalReference = exports.parseExpectCall = exports.isTestCaseCal
9
9
 
10
10
  var _path = require("path");
11
11
 
12
- var _experimentalUtils = require("@typescript-eslint/experimental-utils");
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 = _experimentalUtils.ESLintUtils.RuleCreator(name => {
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 === _experimentalUtils.AST_NODE_TYPES.TSAsExpression || node.type === _experimentalUtils.AST_NODE_TYPES.TSTypeAssertion;
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 === _experimentalUtils.AST_NODE_TYPES.Literal && typeof node.value === 'string' && (value === undefined || node.value === value);
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 === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1 && ( // bail out if not simple
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 === _experimentalUtils.AST_NODE_TYPES.Identifier && (name === undefined || node.name === name);
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 === _experimentalUtils.AST_NODE_TYPES.Identifier ? accessor.name : getStringValue(accessor);
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 === _experimentalUtils.AST_NODE_TYPES.CallExpression && isSupportedAccessor(node.callee, 'expect') && node.parent !== undefined;
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 === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.property, name);
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 === _experimentalUtils.AST_NODE_TYPES.CallExpression ? parsedMember.node.parent.arguments : null
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 _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression:
369
+ case _utils.AST_NODE_TYPES.TaggedTemplateExpression:
370
370
  return getNodeName(node.tag);
371
371
 
372
- case _experimentalUtils.AST_NODE_TYPES.MemberExpression:
372
+ case _utils.AST_NODE_TYPES.MemberExpression:
373
373
  return joinNames(getNodeName(node.object), getNodeName(node.property));
374
374
 
375
- case _experimentalUtils.AST_NODE_TYPES.NewExpression:
376
- case _experimentalUtils.AST_NODE_TYPES.CallExpression:
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 === _experimentalUtils.AST_NODE_TYPES.FunctionExpression || node.type === _experimentalUtils.AST_NODE_TYPES.ArrowFunctionExpression;
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 === _experimentalUtils.AST_NODE_TYPES.Identifier && HookName.hasOwnProperty(node.callee.name);
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 === _experimentalUtils.AST_NODE_TYPES.CallExpression && isTestCaseCall(node))), []);
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 === _experimentalUtils.AST_NODE_TYPES.Identifier && TestCaseName.hasOwnProperty(node.name);
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 === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
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 === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isTestCaseProperty(callee.property)) {
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 !== _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression && node.callee.type !== _experimentalUtils.AST_NODE_TYPES.CallExpression) {
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 === _experimentalUtils.AST_NODE_TYPES.MemberExpression ? isTestCaseName(callee.object.object) : isTestCaseName(callee.object);
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 === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.name);
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 === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
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 === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isDescribeProperty(callee.property)) {
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 !== _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression && node.callee.type !== _experimentalUtils.AST_NODE_TYPES.CallExpression) {
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 === _experimentalUtils.AST_NODE_TYPES.MemberExpression ? isDescribeAlias(callee.object.object) : isDescribeAlias(callee.object);
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 _experimentalUtils = require("@typescript-eslint/experimental-utils");
8
+ var _utils = require("@typescript-eslint/utils");
9
9
 
10
- var _utils = require("./utils");
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, _utils.createRule)({
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, _utils.isDescribeCall)(node)) {
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, _utils.isFunction)(callback)) {
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, _utils.getNodeName)(node).endsWith('each') && callback.params.length) {
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 === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
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 === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
94
+ if (callback.body.type === _utils.AST_NODE_TYPES.BlockStatement) {
95
95
  callback.body.body.forEach(node => {
96
- if (node.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement) {
96
+ if (node.type === _utils.AST_NODE_TYPES.ReturnStatement) {
97
97
  context.report({
98
98
  messageId: 'unexpectedReturnInDescribe',
99
99
  node
@@ -5,18 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _experimentalUtils = require("@typescript-eslint/experimental-utils");
8
+ var _utils = require("@typescript-eslint/utils");
9
9
 
10
- var _utils = require("./utils");
10
+ var _utils2 = require("./utils");
11
11
 
12
12
  const isPromiseChainCall = node => {
13
- if (node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(node.callee.property)) {
13
+ if (node.type === _utils.AST_NODE_TYPES.CallExpression && node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property)) {
14
14
  // promise methods should have at least 1 argument
15
15
  if (node.arguments.length === 0) {
16
16
  return false;
17
17
  }
18
18
 
19
- switch ((0, _utils.getAccessorValue)(node.callee.property)) {
19
+ switch ((0, _utils2.getAccessorValue)(node.callee.property)) {
20
20
  case 'then':
21
21
  return node.arguments.length < 3;
22
22
 
@@ -36,13 +36,13 @@ const findTopMostCallExpression = node => {
36
36
  } = node;
37
37
 
38
38
  while (parent) {
39
- if (parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
39
+ if (parent.type === _utils.AST_NODE_TYPES.CallExpression) {
40
40
  topMostCallExpression = parent;
41
41
  parent = parent.parent;
42
42
  continue;
43
43
  }
44
44
 
45
- if (parent.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
45
+ if (parent.type !== _utils.AST_NODE_TYPES.MemberExpression) {
46
46
  break;
47
47
  }
48
48
 
@@ -53,13 +53,13 @@ const findTopMostCallExpression = node => {
53
53
  };
54
54
 
55
55
  const isTestCaseCallWithCallbackArg = node => {
56
- if (!(0, _utils.isTestCaseCall)(node)) {
56
+ if (!(0, _utils2.isTestCaseCall)(node)) {
57
57
  return false;
58
58
  }
59
59
 
60
- const isJestEach = (0, _utils.getNodeName)(node).endsWith('.each');
60
+ const isJestEach = (0, _utils2.getNodeName)(node).endsWith('.each');
61
61
 
62
- if (isJestEach && node.callee.type !== _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
62
+ if (isJestEach && node.callee.type !== _utils.AST_NODE_TYPES.TaggedTemplateExpression) {
63
63
  // isJestEach but not a TaggedTemplateExpression, so this must be
64
64
  // the `jest.each([])()` syntax which this rule doesn't support due
65
65
  // to its complexity (see jest-community/eslint-plugin-jest#710)
@@ -70,7 +70,7 @@ const isTestCaseCallWithCallbackArg = node => {
70
70
  if (isJestEach || node.arguments.length >= 2) {
71
71
  const [, callback] = node.arguments;
72
72
  const callbackArgIndex = Number(isJestEach);
73
- return callback && (0, _utils.isFunction)(callback) && callback.params.length === 1 + callbackArgIndex;
73
+ return callback && (0, _utils2.isFunction)(callback) && callback.params.length === 1 + callbackArgIndex;
74
74
  }
75
75
 
76
76
  return false;
@@ -85,23 +85,23 @@ const isPromiseMethodThatUsesValue = (node, identifier) => {
85
85
  return false;
86
86
  }
87
87
 
88
- if (node.argument.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && node.argument.arguments.length > 0) {
89
- const nodeName = (0, _utils.getNodeName)(node.argument);
88
+ if (node.argument.type === _utils.AST_NODE_TYPES.CallExpression && node.argument.arguments.length > 0) {
89
+ const nodeName = (0, _utils2.getNodeName)(node.argument);
90
90
 
91
91
  if (['Promise.all', 'Promise.allSettled'].includes(nodeName)) {
92
92
  const [firstArg] = node.argument.arguments;
93
93
 
94
- if (firstArg.type === _experimentalUtils.AST_NODE_TYPES.ArrayExpression && firstArg.elements.some(nod => (0, _utils.isIdentifier)(nod, name))) {
94
+ if (firstArg.type === _utils.AST_NODE_TYPES.ArrayExpression && firstArg.elements.some(nod => (0, _utils2.isIdentifier)(nod, name))) {
95
95
  return true;
96
96
  }
97
97
  }
98
98
 
99
99
  if (['Promise.resolve', 'Promise.reject'].includes(nodeName) && node.argument.arguments.length === 1) {
100
- return (0, _utils.isIdentifier)(node.argument.arguments[0], name);
100
+ return (0, _utils2.isIdentifier)(node.argument.arguments[0], name);
101
101
  }
102
102
  }
103
103
 
104
- return (0, _utils.isIdentifier)(node.argument, name);
104
+ return (0, _utils2.isIdentifier)(node.argument, name);
105
105
  };
106
106
  /**
107
107
  * Attempts to determine if the runtime value represented by the given `identifier`
@@ -111,11 +111,11 @@ const isPromiseMethodThatUsesValue = (node, identifier) => {
111
111
 
112
112
  const isValueAwaitedInElements = (name, elements) => {
113
113
  for (const element of elements) {
114
- if (element.type === _experimentalUtils.AST_NODE_TYPES.AwaitExpression && (0, _utils.isIdentifier)(element.argument, name)) {
114
+ if (element.type === _utils.AST_NODE_TYPES.AwaitExpression && (0, _utils2.isIdentifier)(element.argument, name)) {
115
115
  return true;
116
116
  }
117
117
 
118
- if (element.type === _experimentalUtils.AST_NODE_TYPES.ArrayExpression && isValueAwaitedInElements(name, element.elements)) {
118
+ if (element.type === _utils.AST_NODE_TYPES.ArrayExpression && isValueAwaitedInElements(name, element.elements)) {
119
119
  return true;
120
120
  }
121
121
  }
@@ -132,7 +132,7 @@ const isValueAwaitedInArguments = (name, call) => {
132
132
  let node = call;
133
133
 
134
134
  while (node) {
135
- if (node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
135
+ if (node.type === _utils.AST_NODE_TYPES.CallExpression) {
136
136
  if (isValueAwaitedInElements(name, node.arguments)) {
137
137
  return true;
138
138
  }
@@ -140,7 +140,7 @@ const isValueAwaitedInArguments = (name, call) => {
140
140
  node = node.callee;
141
141
  }
142
142
 
143
- if (node.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
143
+ if (node.type !== _utils.AST_NODE_TYPES.MemberExpression) {
144
144
  break;
145
145
  }
146
146
 
@@ -155,12 +155,12 @@ const getLeftMostCallExpression = call => {
155
155
  let node = call;
156
156
 
157
157
  while (node) {
158
- if (node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
158
+ if (node.type === _utils.AST_NODE_TYPES.CallExpression) {
159
159
  leftMostCallExpression = node;
160
160
  node = node.callee;
161
161
  }
162
162
 
163
- if (node.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
163
+ if (node.type !== _utils.AST_NODE_TYPES.MemberExpression) {
164
164
  break;
165
165
  }
166
166
 
@@ -187,42 +187,42 @@ const isValueAwaitedOrReturned = (identifier, body) => {
187
187
  continue;
188
188
  }
189
189
 
190
- if (node.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement) {
190
+ if (node.type === _utils.AST_NODE_TYPES.ReturnStatement) {
191
191
  return isPromiseMethodThatUsesValue(node, identifier);
192
192
  }
193
193
 
194
- if (node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement) {
194
+ if (node.type === _utils.AST_NODE_TYPES.ExpressionStatement) {
195
195
  // it's possible that we're awaiting the value as an argument
196
- if (node.expression.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
196
+ if (node.expression.type === _utils.AST_NODE_TYPES.CallExpression) {
197
197
  if (isValueAwaitedInArguments(name, node.expression)) {
198
198
  return true;
199
199
  }
200
200
 
201
201
  const leftMostCall = getLeftMostCallExpression(node.expression);
202
202
 
203
- if ((0, _utils.isExpectCall)(leftMostCall) && leftMostCall.arguments.length > 0 && (0, _utils.isIdentifier)(leftMostCall.arguments[0], name)) {
203
+ if ((0, _utils2.isExpectCall)(leftMostCall) && leftMostCall.arguments.length > 0 && (0, _utils2.isIdentifier)(leftMostCall.arguments[0], name)) {
204
204
  const {
205
205
  modifier
206
- } = (0, _utils.parseExpectCall)(leftMostCall);
206
+ } = (0, _utils2.parseExpectCall)(leftMostCall);
207
207
 
208
- if ((modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.resolves || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils.ModifierName.rejects) {
208
+ if ((modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.resolves || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.rejects) {
209
209
  return true;
210
210
  }
211
211
  }
212
212
  }
213
213
 
214
- if (node.expression.type === _experimentalUtils.AST_NODE_TYPES.AwaitExpression && isPromiseMethodThatUsesValue(node.expression, identifier)) {
214
+ if (node.expression.type === _utils.AST_NODE_TYPES.AwaitExpression && isPromiseMethodThatUsesValue(node.expression, identifier)) {
215
215
  return true;
216
216
  } // (re)assignment changes the runtime value, so if we've not found an
217
217
  // await or return already we act as if we've reached the end of the body
218
218
 
219
219
 
220
- if (node.expression.type === _experimentalUtils.AST_NODE_TYPES.AssignmentExpression) {
220
+ if (node.expression.type === _utils.AST_NODE_TYPES.AssignmentExpression) {
221
221
  var _getNodeName;
222
222
 
223
223
  // unless we're assigning to the same identifier, in which case
224
224
  // we might be chaining off the existing promise value
225
- if ((0, _utils.isIdentifier)(node.expression.left, name) && (_getNodeName = (0, _utils.getNodeName)(node.expression.right)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith(`${name}.`) && isPromiseChainCall(node.expression.right)) {
225
+ if ((0, _utils2.isIdentifier)(node.expression.left, name) && (_getNodeName = (0, _utils2.getNodeName)(node.expression.right)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith(`${name}.`) && isPromiseChainCall(node.expression.right)) {
226
226
  continue;
227
227
  }
228
228
 
@@ -230,7 +230,7 @@ const isValueAwaitedOrReturned = (identifier, body) => {
230
230
  }
231
231
  }
232
232
 
233
- if (node.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement && isValueAwaitedOrReturned(identifier, node.body)) {
233
+ if (node.type === _utils.AST_NODE_TYPES.BlockStatement && isValueAwaitedOrReturned(identifier, node.body)) {
234
234
  return true;
235
235
  }
236
236
  }
@@ -242,7 +242,7 @@ const findFirstBlockBodyUp = node => {
242
242
  let parent = node;
243
243
 
244
244
  while (parent) {
245
- if (parent.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
245
+ if (parent.type === _utils.AST_NODE_TYPES.BlockStatement) {
246
246
  return parent.body;
247
247
  }
248
248
 
@@ -258,11 +258,11 @@ const isDirectlyWithinTestCaseCall = node => {
258
258
  let parent = node;
259
259
 
260
260
  while (parent) {
261
- if ((0, _utils.isFunction)(parent)) {
261
+ if ((0, _utils2.isFunction)(parent)) {
262
262
  var _parent;
263
263
 
264
264
  parent = parent.parent;
265
- return !!(((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isTestCaseCall)(parent));
265
+ return !!(((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTestCaseCall)(parent));
266
266
  }
267
267
 
268
268
  parent = parent.parent;
@@ -275,14 +275,14 @@ const isVariableAwaitedOrReturned = variable => {
275
275
  const body = findFirstBlockBodyUp(variable); // it's pretty much impossible for us to track destructuring assignments,
276
276
  // so we return true to bailout gracefully
277
277
 
278
- if (!(0, _utils.isIdentifier)(variable.id)) {
278
+ if (!(0, _utils2.isIdentifier)(variable.id)) {
279
279
  return true;
280
280
  }
281
281
 
282
282
  return isValueAwaitedOrReturned(variable.id, body);
283
283
  };
284
284
 
285
- var _default = (0, _utils.createRule)({
285
+ var _default = (0, _utils2.createRule)({
286
286
  name: __filename,
287
287
  meta: {
288
288
  docs: {
@@ -326,7 +326,7 @@ var _default = (0, _utils.createRule)({
326
326
  // an expect call, mark the deepest chain as having an expect call
327
327
 
328
328
 
329
- if (chains.length > 0 && (0, _utils.isExpectCall)(node)) {
329
+ if (chains.length > 0 && (0, _utils2.isExpectCall)(node)) {
330
330
  chains[0] = true;
331
331
  }
332
332
  },
@@ -336,7 +336,7 @@ var _default = (0, _utils.createRule)({
336
336
  // make promises containing expects safe in a test for us to be able to
337
337
  // accurately check, so we just bail out completely if it's present
338
338
  if (inTestCaseWithDoneCallback) {
339
- if ((0, _utils.isTestCaseCall)(node)) {
339
+ if ((0, _utils2.isTestCaseCall)(node)) {
340
340
  inTestCaseWithDoneCallback = false;
341
341
  }
342
342
 
@@ -368,7 +368,7 @@ var _default = (0, _utils.createRule)({
368
368
  }
369
369
 
370
370
  switch (parent.type) {
371
- case _experimentalUtils.AST_NODE_TYPES.VariableDeclarator:
371
+ case _utils.AST_NODE_TYPES.VariableDeclarator:
372
372
  {
373
373
  if (isVariableAwaitedOrReturned(parent)) {
374
374
  return;
@@ -377,20 +377,20 @@ var _default = (0, _utils.createRule)({
377
377
  break;
378
378
  }
379
379
 
380
- case _experimentalUtils.AST_NODE_TYPES.AssignmentExpression:
380
+ case _utils.AST_NODE_TYPES.AssignmentExpression:
381
381
  {
382
- if (parent.left.type === _experimentalUtils.AST_NODE_TYPES.Identifier && isValueAwaitedOrReturned(parent.left, findFirstBlockBodyUp(parent))) {
382
+ if (parent.left.type === _utils.AST_NODE_TYPES.Identifier && isValueAwaitedOrReturned(parent.left, findFirstBlockBodyUp(parent))) {
383
383
  return;
384
384
  }
385
385
 
386
386
  break;
387
387
  }
388
388
 
389
- case _experimentalUtils.AST_NODE_TYPES.ExpressionStatement:
389
+ case _utils.AST_NODE_TYPES.ExpressionStatement:
390
390
  break;
391
391
 
392
- case _experimentalUtils.AST_NODE_TYPES.ReturnStatement:
393
- case _experimentalUtils.AST_NODE_TYPES.AwaitExpression:
392
+ case _utils.AST_NODE_TYPES.ReturnStatement:
393
+ case _utils.AST_NODE_TYPES.AwaitExpression:
394
394
  default:
395
395
  return;
396
396
  }