eslint-plugin-jest 27.1.1 → 27.1.3

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 (60) hide show
  1. package/lib/index.js +8 -16
  2. package/lib/processors/snapshot-processor.js +3 -5
  3. package/lib/rules/consistent-test-it.js +0 -18
  4. package/lib/rules/expect-expect.js +0 -15
  5. package/lib/rules/max-expects.js +0 -16
  6. package/lib/rules/max-nested-describe.js +0 -13
  7. package/lib/rules/no-alias-methods.js +0 -9
  8. package/lib/rules/no-commented-out-tests.js +0 -10
  9. package/lib/rules/no-conditional-expect.js +0 -19
  10. package/lib/rules/no-conditional-in-test.js +0 -9
  11. package/lib/rules/no-deprecated-functions.js +2 -18
  12. package/lib/rules/no-disabled-tests.js +2 -18
  13. package/lib/rules/no-done-callback.js +1 -30
  14. package/lib/rules/no-duplicate-hooks.js +0 -12
  15. package/lib/rules/no-export.js +0 -12
  16. package/lib/rules/no-focused-tests.js +0 -15
  17. package/lib/rules/no-hooks.js +0 -7
  18. package/lib/rules/no-identical-title.js +0 -19
  19. package/lib/rules/no-if.js +0 -24
  20. package/lib/rules/no-interpolation-in-snapshots.js +0 -9
  21. package/lib/rules/no-jasmine-globals.js +0 -22
  22. package/lib/rules/no-large-snapshots.js +2 -20
  23. package/lib/rules/no-mocks-import.js +0 -12
  24. package/lib/rules/no-restricted-jest-methods.js +1 -11
  25. package/lib/rules/no-restricted-matchers.js +0 -11
  26. package/lib/rules/no-standalone-expect.js +7 -33
  27. package/lib/rules/no-test-prefixes.js +0 -12
  28. package/lib/rules/no-test-return-statement.js +0 -12
  29. package/lib/rules/prefer-called-with.js +0 -10
  30. package/lib/rules/prefer-comparison-matcher.js +8 -33
  31. package/lib/rules/prefer-each.js +0 -18
  32. package/lib/rules/prefer-equality-matcher.js +11 -23
  33. package/lib/rules/prefer-expect-assertions.js +4 -51
  34. package/lib/rules/prefer-expect-resolves.js +0 -12
  35. package/lib/rules/prefer-hooks-in-order.js +2 -16
  36. package/lib/rules/prefer-hooks-on-top.js +0 -9
  37. package/lib/rules/prefer-lowercase-title.js +0 -23
  38. package/lib/rules/prefer-mock-promise-shorthand.js +5 -26
  39. package/lib/rules/prefer-snapshot-hint.js +7 -31
  40. package/lib/rules/prefer-spy-on.js +0 -17
  41. package/lib/rules/prefer-strict-equal.js +0 -9
  42. package/lib/rules/prefer-to-be.js +1 -30
  43. package/lib/rules/prefer-to-contain.js +11 -21
  44. package/lib/rules/prefer-to-have-length.js +4 -16
  45. package/lib/rules/prefer-todo.js +2 -18
  46. package/lib/rules/require-hook.js +0 -22
  47. package/lib/rules/require-to-throw-message.js +0 -9
  48. package/lib/rules/require-top-level-describe.js +0 -15
  49. package/lib/rules/unbound-method.js +2 -21
  50. package/lib/rules/utils/accessors.js +6 -18
  51. package/lib/rules/utils/detectJestVersion.js +2 -7
  52. package/lib/rules/utils/followTypeAssertionChain.js +0 -4
  53. package/lib/rules/utils/index.js +0 -10
  54. package/lib/rules/utils/misc.js +2 -46
  55. package/lib/rules/utils/parseJestFnCall.js +39 -114
  56. package/lib/rules/valid-describe-callback.js +0 -17
  57. package/lib/rules/valid-expect-in-promise.js +27 -94
  58. package/lib/rules/valid-expect.js +5 -48
  59. package/lib/rules/valid-title.js +0 -33
  60. package/package.json +2 -2
@@ -4,57 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("@typescript-eslint/utils");
9
-
10
8
  var _utils2 = require("./utils");
11
-
12
9
  const isString = node => {
13
10
  return (0, _utils2.isStringNode)(node) || node.type === _utils.AST_NODE_TYPES.TemplateLiteral;
14
11
  };
15
-
16
12
  const isComparingToString = expression => {
17
13
  return isString(expression.left) || isString(expression.right);
18
14
  };
19
-
20
15
  const invertOperator = operator => {
21
16
  switch (operator) {
22
17
  case '>':
23
18
  return '<=';
24
-
25
19
  case '<':
26
20
  return '>=';
27
-
28
21
  case '>=':
29
22
  return '<';
30
-
31
23
  case '<=':
32
24
  return '>';
33
25
  }
34
-
35
26
  return null;
36
27
  };
37
-
38
28
  const determineMatcher = (operator, negated) => {
39
29
  const op = negated ? invertOperator(operator) : operator;
40
-
41
30
  switch (op) {
42
31
  case '>':
43
32
  return 'toBeGreaterThan';
44
-
45
33
  case '<':
46
34
  return 'toBeLessThan';
47
-
48
35
  case '>=':
49
36
  return 'toBeGreaterThanOrEqual';
50
-
51
37
  case '<=':
52
38
  return 'toBeLessThanOrEqual';
53
39
  }
54
-
55
40
  return null;
56
41
  };
57
-
58
42
  var _default = (0, _utils2.createRule)({
59
43
  name: __filename,
60
44
  meta: {
@@ -71,24 +55,19 @@ var _default = (0, _utils2.createRule)({
71
55
  schema: []
72
56
  },
73
57
  defaultOptions: [],
74
-
75
58
  create(context) {
76
59
  return {
77
60
  CallExpression(node) {
78
61
  const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
79
-
80
62
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'expect' || jestFnCall.args.length === 0) {
81
63
  return;
82
64
  }
83
-
84
65
  const {
85
66
  parent: expect
86
67
  } = jestFnCall.head.node;
87
-
88
68
  if ((expect === null || expect === void 0 ? void 0 : expect.type) !== _utils.AST_NODE_TYPES.CallExpression) {
89
69
  return;
90
70
  }
91
-
92
71
  const {
93
72
  arguments: [comparison],
94
73
  range: [, expectCallEnd]
@@ -97,30 +76,29 @@ var _default = (0, _utils2.createRule)({
97
76
  matcher
98
77
  } = jestFnCall;
99
78
  const matcherArg = (0, _utils2.getFirstMatcherArg)(jestFnCall);
100
-
101
79
  if ((comparison === null || comparison === void 0 ? void 0 : comparison.type) !== _utils.AST_NODE_TYPES.BinaryExpression || isComparingToString(comparison) || !_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) || !(0, _utils2.isBooleanLiteral)(matcherArg)) {
102
80
  return;
103
81
  }
104
-
105
82
  const [modifier] = jestFnCall.modifiers;
106
83
  const hasNot = jestFnCall.modifiers.some(nod => (0, _utils2.getAccessorValue)(nod) === 'not');
107
84
  const preferredMatcher = determineMatcher(comparison.operator, matcherArg.value === hasNot);
108
-
109
85
  if (!preferredMatcher) {
110
86
  return;
111
87
  }
112
-
113
88
  context.report({
114
89
  fix(fixer) {
115
- const sourceCode = context.getSourceCode(); // preserve the existing modifier if it's not a negation
90
+ const sourceCode = context.getSourceCode();
116
91
 
92
+ // preserve the existing modifier if it's not a negation
117
93
  const modifierText = modifier && (0, _utils2.getAccessorValue)(modifier) !== 'not' ? `.${(0, _utils2.getAccessorValue)(modifier)}` : '';
118
- return [// replace the comparison argument with the left-hand side of the comparison
119
- fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
120
- fixer.replaceTextRange([expectCallEnd, matcher.parent.range[1]], `${modifierText}.${preferredMatcher}`), // replace the matcher argument with the right-hand side of the comparison
94
+ return [
95
+ // replace the comparison argument with the left-hand side of the comparison
96
+ fixer.replaceText(comparison, sourceCode.getText(comparison.left)),
97
+ // replace the current matcher & modifier with the preferred matcher
98
+ fixer.replaceTextRange([expectCallEnd, matcher.parent.range[1]], `${modifierText}.${preferredMatcher}`),
99
+ // replace the matcher argument with the right-hand side of the comparison
121
100
  fixer.replaceText(matcherArg, sourceCode.getText(comparison.right))];
122
101
  },
123
-
124
102
  messageId: 'useToBeComparison',
125
103
  data: {
126
104
  preferredMatcher
@@ -128,10 +106,7 @@ var _default = (0, _utils2.createRule)({
128
106
  node: matcher
129
107
  });
130
108
  }
131
-
132
109
  };
133
110
  }
134
-
135
111
  });
136
-
137
112
  exports.default = _default;
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("./utils");
9
-
10
8
  var _default = (0, _utils.createRule)({
11
9
  name: __filename,
12
10
  meta: {
@@ -22,32 +20,25 @@ var _default = (0, _utils.createRule)({
22
20
  schema: []
23
21
  },
24
22
  defaultOptions: [],
25
-
26
23
  create(context) {
27
24
  const jestFnCalls = [];
28
25
  let inTestCaseCall = false;
29
-
30
26
  const recommendFn = () => {
31
27
  if (jestFnCalls.length === 1 && jestFnCalls[0] === 'test') {
32
28
  return 'it';
33
29
  }
34
-
35
30
  return 'describe';
36
31
  };
37
-
38
32
  const enterForLoop = () => {
39
33
  if (jestFnCalls.length === 0 || inTestCaseCall) {
40
34
  return;
41
35
  }
42
-
43
36
  jestFnCalls.length = 0;
44
37
  };
45
-
46
38
  const exitForLoop = node => {
47
39
  if (jestFnCalls.length === 0 || inTestCaseCall) {
48
40
  return;
49
41
  }
50
-
51
42
  context.report({
52
43
  node,
53
44
  messageId: 'preferEach',
@@ -57,7 +48,6 @@ var _default = (0, _utils.createRule)({
57
48
  });
58
49
  jestFnCalls.length = 0;
59
50
  };
60
-
61
51
  return {
62
52
  ForStatement: enterForLoop,
63
53
  'ForStatement:exit': exitForLoop,
@@ -65,34 +55,26 @@ var _default = (0, _utils.createRule)({
65
55
  'ForInStatement:exit': exitForLoop,
66
56
  ForOfStatement: enterForLoop,
67
57
  'ForOfStatement:exit': exitForLoop,
68
-
69
58
  CallExpression(node) {
70
59
  const {
71
60
  type: jestFnCallType
72
61
  } = (0, _utils.parseJestFnCall)(node, context) ?? {};
73
-
74
62
  if (jestFnCallType === 'hook' || jestFnCallType === 'describe' || jestFnCallType === 'test') {
75
63
  jestFnCalls.push(jestFnCallType);
76
64
  }
77
-
78
65
  if (jestFnCallType === 'test') {
79
66
  inTestCaseCall = true;
80
67
  }
81
68
  },
82
-
83
69
  'CallExpression:exit'(node) {
84
70
  const {
85
71
  type: jestFnCallType
86
72
  } = (0, _utils.parseJestFnCall)(node, context) ?? {};
87
-
88
73
  if (jestFnCallType === 'test') {
89
74
  inTestCaseCall = false;
90
75
  }
91
76
  }
92
-
93
77
  };
94
78
  }
95
-
96
79
  });
97
-
98
80
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("@typescript-eslint/utils");
9
-
10
8
  var _utils2 = require("./utils");
11
-
12
9
  var _default = (0, _utils2.createRule)({
13
10
  name: __filename,
14
11
  meta: {
@@ -26,24 +23,19 @@ var _default = (0, _utils2.createRule)({
26
23
  schema: []
27
24
  },
28
25
  defaultOptions: [],
29
-
30
26
  create(context) {
31
27
  return {
32
28
  CallExpression(node) {
33
29
  const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
34
-
35
30
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'expect' || jestFnCall.args.length === 0) {
36
31
  return;
37
32
  }
38
-
39
33
  const {
40
34
  parent: expect
41
35
  } = jestFnCall.head.node;
42
-
43
36
  if ((expect === null || expect === void 0 ? void 0 : expect.type) !== _utils.AST_NODE_TYPES.CallExpression) {
44
37
  return;
45
38
  }
46
-
47
39
  const {
48
40
  arguments: [comparison],
49
41
  range: [, expectCallEnd]
@@ -52,33 +44,32 @@ var _default = (0, _utils2.createRule)({
52
44
  matcher
53
45
  } = jestFnCall;
54
46
  const matcherArg = (0, _utils2.getFirstMatcherArg)(jestFnCall);
55
-
56
47
  if ((comparison === null || comparison === void 0 ? void 0 : comparison.type) !== _utils.AST_NODE_TYPES.BinaryExpression || comparison.operator !== '===' && comparison.operator !== '!==' || !_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) || !(0, _utils2.isBooleanLiteral)(matcherArg)) {
57
48
  return;
58
49
  }
59
-
60
50
  const matcherValue = matcherArg.value;
61
51
  const [modifier] = jestFnCall.modifiers;
62
- const hasNot = jestFnCall.modifiers.some(nod => (0, _utils2.getAccessorValue)(nod) === 'not'); // we need to negate the expectation if the current expected
63
- // value is itself negated by the "not" modifier
52
+ const hasNot = jestFnCall.modifiers.some(nod => (0, _utils2.getAccessorValue)(nod) === 'not');
64
53
 
54
+ // we need to negate the expectation if the current expected
55
+ // value is itself negated by the "not" modifier
65
56
  const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === hasNot;
66
-
67
57
  const buildFixer = equalityMatcher => fixer => {
68
- const sourceCode = context.getSourceCode(); // preserve the existing modifier if it's not a negation
58
+ const sourceCode = context.getSourceCode();
69
59
 
60
+ // preserve the existing modifier if it's not a negation
70
61
  let modifierText = modifier && (0, _utils2.getAccessorValue)(modifier) !== 'not' ? `.${(0, _utils2.getAccessorValue)(modifier)}` : '';
71
-
72
62
  if (addNotModifier) {
73
63
  modifierText += `.${_utils2.ModifierName.not}`;
74
64
  }
75
-
76
- return [// replace the comparison argument with the left-hand side of the comparison
77
- fixer.replaceText(comparison, sourceCode.getText(comparison.left)), // replace the current matcher & modifier with the preferred matcher
78
- fixer.replaceTextRange([expectCallEnd, matcher.parent.range[1]], `${modifierText}.${equalityMatcher}`), // replace the matcher argument with the right-hand side of the comparison
65
+ return [
66
+ // replace the comparison argument with the left-hand side of the comparison
67
+ fixer.replaceText(comparison, sourceCode.getText(comparison.left)),
68
+ // replace the current matcher & modifier with the preferred matcher
69
+ fixer.replaceTextRange([expectCallEnd, matcher.parent.range[1]], `${modifierText}.${equalityMatcher}`),
70
+ // replace the matcher argument with the right-hand side of the comparison
79
71
  fixer.replaceText(matcherArg, sourceCode.getText(comparison.right))];
80
72
  };
81
-
82
73
  context.report({
83
74
  messageId: 'useEqualityMatcher',
84
75
  suggest: ['toBe', 'toEqual', 'toStrictEqual'].map(equalityMatcher => ({
@@ -91,10 +82,7 @@ var _default = (0, _utils2.createRule)({
91
82
  node: matcher
92
83
  });
93
84
  }
94
-
95
85
  };
96
86
  }
97
-
98
87
  });
99
-
100
88
  exports.default = _default;
@@ -4,40 +4,31 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("@typescript-eslint/utils");
9
-
10
8
  var _utils2 = require("./utils");
11
-
12
9
  const isFirstStatement = node => {
13
10
  let parent = node;
14
-
15
11
  while (parent) {
16
12
  var _parent$parent, _parent$parent2;
17
-
18
13
  if (((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === _utils.AST_NODE_TYPES.BlockStatement) {
19
14
  return parent.parent.body[0] === parent;
20
- } // if we've hit an arrow function, then it must have a single expression
21
- // as its body, as otherwise we would have hit the block statement already
22
-
15
+ }
23
16
 
17
+ // if we've hit an arrow function, then it must have a single expression
18
+ // as its body, as otherwise we would have hit the block statement already
24
19
  if (((_parent$parent2 = parent.parent) === null || _parent$parent2 === void 0 ? void 0 : _parent$parent2.type) === _utils.AST_NODE_TYPES.ArrowFunctionExpression) {
25
20
  return true;
26
21
  }
27
-
28
22
  parent = parent.parent;
29
23
  }
30
- /* istanbul ignore next */
31
-
32
24
 
25
+ /* istanbul ignore next */
33
26
  throw new Error(`Could not find BlockStatement - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`);
34
27
  };
35
-
36
28
  const suggestRemovingExtraArguments = (args, extraArgsStartAt) => ({
37
29
  messageId: 'suggestRemovingExtraArguments',
38
30
  fix: fixer => fixer.removeRange([args[extraArgsStartAt].range[0] - Math.sign(extraArgsStartAt), args[args.length - 1].range[1]])
39
31
  });
40
-
41
32
  var _default = (0, _utils2.createRule)({
42
33
  name: __filename,
43
34
  meta: {
@@ -78,7 +69,6 @@ var _default = (0, _utils2.createRule)({
78
69
  onlyFunctionsWithExpectInLoop: false,
79
70
  onlyFunctionsWithExpectInCallback: false
80
71
  }],
81
-
82
72
  create(context, [options]) {
83
73
  let expressionDepth = 0;
84
74
  let hasExpectInCallback = false;
@@ -86,33 +76,27 @@ var _default = (0, _utils2.createRule)({
86
76
  let hasExpectAssertionsAsFirstStatement = false;
87
77
  let inTestCaseCall = false;
88
78
  let inForLoop = false;
89
-
90
79
  const shouldCheckFunction = testFunction => {
91
80
  if (!options.onlyFunctionsWithAsyncKeyword && !options.onlyFunctionsWithExpectInLoop && !options.onlyFunctionsWithExpectInCallback) {
92
81
  return true;
93
82
  }
94
-
95
83
  if (options.onlyFunctionsWithAsyncKeyword) {
96
84
  if (testFunction.async) {
97
85
  return true;
98
86
  }
99
87
  }
100
-
101
88
  if (options.onlyFunctionsWithExpectInLoop) {
102
89
  if (hasExpectInLoop) {
103
90
  return true;
104
91
  }
105
92
  }
106
-
107
93
  if (options.onlyFunctionsWithExpectInCallback) {
108
94
  if (hasExpectInCallback) {
109
95
  return true;
110
96
  }
111
97
  }
112
-
113
98
  return false;
114
99
  };
115
-
116
100
  const checkExpectHasAssertions = expectFnCall => {
117
101
  if ((0, _utils2.getAccessorValue)(expectFnCall.members[0]) === 'hasAssertions') {
118
102
  if (expectFnCall.args.length) {
@@ -122,21 +106,17 @@ var _default = (0, _utils2.createRule)({
122
106
  suggest: [suggestRemovingExtraArguments(expectFnCall.args, 0)]
123
107
  });
124
108
  }
125
-
126
109
  return;
127
110
  }
128
-
129
111
  if (expectFnCall.args.length !== 1) {
130
112
  let {
131
113
  loc
132
114
  } = expectFnCall.matcher;
133
115
  const suggest = [];
134
-
135
116
  if (expectFnCall.args.length) {
136
117
  loc = expectFnCall.args[1].loc;
137
118
  suggest.push(suggestRemovingExtraArguments(expectFnCall.args, 1));
138
119
  }
139
-
140
120
  context.report({
141
121
  messageId: 'assertionsRequiresOneArgument',
142
122
  suggest,
@@ -144,27 +124,19 @@ var _default = (0, _utils2.createRule)({
144
124
  });
145
125
  return;
146
126
  }
147
-
148
127
  const [arg] = expectFnCall.args;
149
-
150
128
  if (arg.type === _utils.AST_NODE_TYPES.Literal && typeof arg.value === 'number' && Number.isInteger(arg.value)) {
151
129
  return;
152
130
  }
153
-
154
131
  context.report({
155
132
  messageId: 'assertionsRequiresNumberArgument',
156
133
  node: arg
157
134
  });
158
135
  };
159
-
160
136
  const enterExpression = () => inTestCaseCall && expressionDepth++;
161
-
162
137
  const exitExpression = () => inTestCaseCall && expressionDepth--;
163
-
164
138
  const enterForLoop = () => inForLoop = true;
165
-
166
139
  const exitForLoop = () => inForLoop = false;
167
-
168
140
  return {
169
141
  FunctionExpression: enterExpression,
170
142
  'FunctionExpression:exit': exitExpression,
@@ -176,64 +148,48 @@ var _default = (0, _utils2.createRule)({
176
148
  'ForInStatement:exit': exitForLoop,
177
149
  ForOfStatement: enterForLoop,
178
150
  'ForOfStatement:exit': exitForLoop,
179
-
180
151
  CallExpression(node) {
181
152
  const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
182
-
183
153
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'test') {
184
154
  inTestCaseCall = true;
185
155
  return;
186
156
  }
187
-
188
157
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'expect' && inTestCaseCall) {
189
158
  var _jestFnCall$head$node;
190
-
191
159
  if (expressionDepth === 1 && isFirstStatement(node) && ((_jestFnCall$head$node = jestFnCall.head.node.parent) === null || _jestFnCall$head$node === void 0 ? void 0 : _jestFnCall$head$node.type) === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.members.length === 1 && ['assertions', 'hasAssertions'].includes((0, _utils2.getAccessorValue)(jestFnCall.members[0]))) {
192
160
  checkExpectHasAssertions(jestFnCall);
193
161
  hasExpectAssertionsAsFirstStatement = true;
194
162
  }
195
-
196
163
  if (inForLoop) {
197
164
  hasExpectInLoop = true;
198
165
  }
199
-
200
166
  if (expressionDepth > 1) {
201
167
  hasExpectInCallback = true;
202
168
  }
203
169
  }
204
170
  },
205
-
206
171
  'CallExpression:exit'(node) {
207
172
  if (!(0, _utils2.isTypeOfJestFnCall)(node, context, ['test'])) {
208
173
  return;
209
174
  }
210
-
211
175
  inTestCaseCall = false;
212
-
213
176
  if (node.arguments.length < 2) {
214
177
  return;
215
178
  }
216
-
217
179
  const [, testFn] = node.arguments;
218
-
219
180
  if (!(0, _utils2.isFunction)(testFn) || !shouldCheckFunction(testFn)) {
220
181
  return;
221
182
  }
222
-
223
183
  hasExpectInLoop = false;
224
184
  hasExpectInCallback = false;
225
-
226
185
  if (hasExpectAssertionsAsFirstStatement) {
227
186
  hasExpectAssertionsAsFirstStatement = false;
228
187
  return;
229
188
  }
230
-
231
189
  const suggestions = [];
232
-
233
190
  if (testFn.body.type === _utils.AST_NODE_TYPES.BlockStatement) {
234
191
  suggestions.push(['suggestAddingHasAssertions', 'expect.hasAssertions();'], ['suggestAddingAssertions', 'expect.assertions();']);
235
192
  }
236
-
237
193
  context.report({
238
194
  messageId: 'haveExpectAssertions',
239
195
  node,
@@ -243,10 +199,7 @@ var _default = (0, _utils2.createRule)({
243
199
  }))
244
200
  });
245
201
  }
246
-
247
202
  };
248
203
  }
249
-
250
204
  });
251
-
252
205
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("@typescript-eslint/utils");
9
-
10
8
  var _utils2 = require("./utils");
11
-
12
9
  var _default = (0, _utils2.createRule)({
13
10
  name: __filename,
14
11
  meta: {
@@ -28,35 +25,26 @@ var _default = (0, _utils2.createRule)({
28
25
  create: context => ({
29
26
  CallExpression(node) {
30
27
  const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
31
-
32
28
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'expect') {
33
29
  return;
34
30
  }
35
-
36
31
  const {
37
32
  parent
38
33
  } = jestFnCall.head.node;
39
-
40
34
  if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression) {
41
35
  return;
42
36
  }
43
-
44
37
  const [awaitNode] = parent.arguments;
45
-
46
38
  if ((awaitNode === null || awaitNode === void 0 ? void 0 : awaitNode.type) === _utils.AST_NODE_TYPES.AwaitExpression) {
47
39
  context.report({
48
40
  node: awaitNode,
49
41
  messageId: 'expectResolves',
50
-
51
42
  fix(fixer) {
52
43
  return [fixer.insertTextBefore(parent, 'await '), fixer.removeRange([awaitNode.range[0], awaitNode.argument.range[0]]), fixer.insertTextAfter(parent, '.resolves')];
53
44
  }
54
-
55
45
  });
56
46
  }
57
47
  }
58
-
59
48
  })
60
49
  });
61
-
62
50
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("./utils");
9
-
10
8
  const HooksOrder = ['beforeAll', 'beforeEach', 'afterEach', 'afterAll'];
11
-
12
9
  var _default = (0, _utils.createRule)({
13
10
  name: __filename,
14
11
  meta: {
@@ -24,7 +21,6 @@ var _default = (0, _utils.createRule)({
24
21
  type: 'suggestion'
25
22
  },
26
23
  defaultOptions: [],
27
-
28
24
  create(context) {
29
25
  let previousHookIndex = -1;
30
26
  let inHook = false;
@@ -34,19 +30,15 @@ var _default = (0, _utils.createRule)({
34
30
  // Ignore everything that is passed into a hook
35
31
  return;
36
32
  }
37
-
38
33
  const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
39
-
40
34
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'hook') {
41
35
  // Reset the previousHookIndex when encountering something different from a hook
42
36
  previousHookIndex = -1;
43
37
  return;
44
38
  }
45
-
46
39
  inHook = true;
47
40
  const currentHook = jestFnCall.name;
48
41
  const currentHookIndex = HooksOrder.indexOf(currentHook);
49
-
50
42
  if (currentHookIndex < previousHookIndex) {
51
43
  context.report({
52
44
  messageId: 'reorderHooks',
@@ -58,27 +50,21 @@ var _default = (0, _utils.createRule)({
58
50
  });
59
51
  return;
60
52
  }
61
-
62
53
  previousHookIndex = currentHookIndex;
63
54
  },
64
-
65
55
  'CallExpression:exit'(node) {
66
56
  if ((0, _utils.isTypeOfJestFnCall)(node, context, ['hook'])) {
67
57
  inHook = false;
68
58
  return;
69
59
  }
70
-
71
60
  if (inHook) {
72
61
  return;
73
- } // Reset the previousHookIndex when encountering something different from a hook
74
-
62
+ }
75
63
 
64
+ // Reset the previousHookIndex when encountering something different from a hook
76
65
  previousHookIndex = -1;
77
66
  }
78
-
79
67
  };
80
68
  }
81
-
82
69
  });
83
-
84
70
  exports.default = _default;
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("./utils");
9
-
10
8
  var _default = (0, _utils.createRule)({
11
9
  name: __filename,
12
10
  meta: {
@@ -22,7 +20,6 @@ var _default = (0, _utils.createRule)({
22
20
  type: 'suggestion'
23
21
  },
24
22
  defaultOptions: [],
25
-
26
23
  create(context) {
27
24
  const hooksContext = [false];
28
25
  return {
@@ -30,24 +27,18 @@ var _default = (0, _utils.createRule)({
30
27
  if ((0, _utils.isTypeOfJestFnCall)(node, context, ['test'])) {
31
28
  hooksContext[hooksContext.length - 1] = true;
32
29
  }
33
-
34
30
  if (hooksContext[hooksContext.length - 1] && (0, _utils.isTypeOfJestFnCall)(node, context, ['hook'])) {
35
31
  context.report({
36
32
  messageId: 'noHookOnTop',
37
33
  node
38
34
  });
39
35
  }
40
-
41
36
  hooksContext.push(false);
42
37
  },
43
-
44
38
  'CallExpression:exit'() {
45
39
  hooksContext.pop();
46
40
  }
47
-
48
41
  };
49
42
  }
50
-
51
43
  });
52
-
53
44
  exports.default = _default;