eslint-plugin-jest 26.8.7 → 27.1.6

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 (114) hide show
  1. package/README.md +82 -78
  2. package/docs/rules/consistent-test-it.md +9 -4
  3. package/docs/rules/expect-expect.md +5 -0
  4. package/docs/rules/max-expects.md +3 -1
  5. package/docs/rules/max-nested-describe.md +3 -1
  6. package/docs/rules/no-alias-methods.md +13 -2
  7. package/docs/rules/no-commented-out-tests.md +6 -1
  8. package/docs/rules/no-conditional-expect.md +7 -2
  9. package/docs/rules/no-conditional-in-test.md +3 -1
  10. package/docs/rules/no-deprecated-functions.md +14 -7
  11. package/docs/rules/no-disabled-tests.md +6 -1
  12. package/docs/rules/no-done-callback.md +9 -1
  13. package/docs/rules/no-duplicate-hooks.md +3 -1
  14. package/docs/rules/no-export.md +6 -1
  15. package/docs/rules/no-focused-tests.md +10 -1
  16. package/docs/rules/no-hooks.md +3 -1
  17. package/docs/rules/no-identical-title.md +6 -1
  18. package/docs/rules/no-if.md +4 -4
  19. package/docs/rules/no-interpolation-in-snapshots.md +6 -1
  20. package/docs/rules/no-jasmine-globals.md +10 -2
  21. package/docs/rules/no-large-snapshots.md +4 -2
  22. package/docs/rules/no-mocks-import.md +6 -1
  23. package/docs/rules/no-restricted-jest-methods.md +51 -0
  24. package/docs/rules/no-restricted-matchers.md +19 -4
  25. package/docs/rules/no-standalone-expect.md +6 -1
  26. package/docs/rules/no-test-prefixes.md +9 -1
  27. package/docs/rules/no-test-return-statement.md +2 -0
  28. package/docs/rules/prefer-called-with.md +2 -0
  29. package/docs/rules/prefer-comparison-matcher.md +5 -0
  30. package/docs/rules/prefer-each.md +56 -0
  31. package/docs/rules/prefer-equality-matcher.md +5 -0
  32. package/docs/rules/prefer-expect-assertions.md +5 -2
  33. package/docs/rules/prefer-expect-resolves.md +8 -1
  34. package/docs/rules/prefer-hooks-in-order.md +3 -1
  35. package/docs/rules/prefer-hooks-on-top.md +3 -1
  36. package/docs/rules/prefer-lowercase-title.md +5 -0
  37. package/docs/rules/prefer-mock-promise-shorthand.md +6 -1
  38. package/docs/rules/prefer-snapshot-hint.md +2 -0
  39. package/docs/rules/prefer-spy-on.md +5 -2
  40. package/docs/rules/prefer-strict-equal.md +5 -2
  41. package/docs/rules/prefer-to-be.md +8 -0
  42. package/docs/rules/prefer-to-contain.md +8 -2
  43. package/docs/rules/prefer-to-have-length.md +8 -2
  44. package/docs/rules/prefer-todo.md +5 -2
  45. package/docs/rules/require-hook.md +2 -0
  46. package/docs/rules/require-to-throw-message.md +2 -2
  47. package/docs/rules/require-top-level-describe.md +5 -1
  48. package/docs/rules/unbound-method.md +7 -2
  49. package/docs/rules/valid-describe-callback.md +6 -1
  50. package/docs/rules/valid-expect-in-promise.md +6 -1
  51. package/docs/rules/valid-expect.md +5 -2
  52. package/docs/rules/valid-title.md +9 -1
  53. package/lib/index.js +14 -25
  54. package/lib/processors/snapshot-processor.js +3 -5
  55. package/lib/rules/consistent-test-it.js +1 -19
  56. package/lib/rules/expect-expect.js +1 -18
  57. package/lib/rules/max-expects.js +0 -16
  58. package/lib/rules/max-nested-describe.js +0 -13
  59. package/lib/rules/no-alias-methods.js +1 -10
  60. package/lib/rules/no-commented-out-tests.js +0 -10
  61. package/lib/rules/no-conditional-expect.js +2 -23
  62. package/lib/rules/no-conditional-in-test.js +0 -9
  63. package/lib/rules/no-deprecated-functions.js +2 -18
  64. package/lib/rules/no-disabled-tests.js +3 -19
  65. package/lib/rules/no-done-callback.js +20 -47
  66. package/lib/rules/no-duplicate-hooks.js +0 -12
  67. package/lib/rules/no-export.js +0 -12
  68. package/lib/rules/no-focused-tests.js +1 -17
  69. package/lib/rules/no-hooks.js +0 -7
  70. package/lib/rules/no-identical-title.js +0 -19
  71. package/lib/rules/no-if.js +0 -24
  72. package/lib/rules/no-interpolation-in-snapshots.js +0 -9
  73. package/lib/rules/no-jasmine-globals.js +1 -23
  74. package/lib/rules/no-large-snapshots.js +4 -24
  75. package/lib/rules/no-mocks-import.js +0 -12
  76. package/lib/rules/no-restricted-jest-methods.js +56 -0
  77. package/lib/rules/no-restricted-matchers.js +13 -28
  78. package/lib/rules/no-standalone-expect.js +7 -33
  79. package/lib/rules/no-test-prefixes.js +1 -13
  80. package/lib/rules/no-test-return-statement.js +0 -12
  81. package/lib/rules/prefer-called-with.js +0 -10
  82. package/lib/rules/prefer-comparison-matcher.js +8 -33
  83. package/lib/rules/prefer-each.js +80 -0
  84. package/lib/rules/prefer-equality-matcher.js +12 -25
  85. package/lib/rules/prefer-expect-assertions.js +14 -60
  86. package/lib/rules/prefer-expect-resolves.js +0 -12
  87. package/lib/rules/prefer-hooks-in-order.js +2 -16
  88. package/lib/rules/prefer-hooks-on-top.js +0 -9
  89. package/lib/rules/prefer-lowercase-title.js +0 -23
  90. package/lib/rules/prefer-mock-promise-shorthand.js +5 -26
  91. package/lib/rules/prefer-snapshot-hint.js +8 -34
  92. package/lib/rules/prefer-spy-on.js +0 -17
  93. package/lib/rules/prefer-strict-equal.js +1 -11
  94. package/lib/rules/prefer-to-be.js +12 -37
  95. package/lib/rules/prefer-to-contain.js +11 -21
  96. package/lib/rules/prefer-to-have-length.js +4 -16
  97. package/lib/rules/prefer-todo.js +2 -18
  98. package/lib/rules/require-hook.js +1 -25
  99. package/lib/rules/require-to-throw-message.js +0 -9
  100. package/lib/rules/require-top-level-describe.js +1 -18
  101. package/lib/rules/unbound-method.js +3 -30
  102. package/lib/rules/utils/accessors.js +6 -18
  103. package/lib/rules/utils/detectJestVersion.js +2 -7
  104. package/lib/rules/utils/followTypeAssertionChain.js +0 -4
  105. package/lib/rules/utils/index.js +0 -10
  106. package/lib/rules/utils/misc.js +14 -47
  107. package/lib/rules/utils/parseJestFnCall.js +51 -154
  108. package/lib/rules/valid-describe-callback.js +0 -17
  109. package/lib/rules/valid-expect-in-promise.js +28 -95
  110. package/lib/rules/valid-expect.js +5 -48
  111. package/lib/rules/valid-title.js +5 -40
  112. package/package.json +20 -16
  113. package/docs/rules/no-jest-import.md +0 -20
  114. package/lib/rules/no-jest-import.js +0 -48
@@ -4,49 +4,37 @@ 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 isJestFnCall = (node, context) => {
13
10
  var _getNodeName;
14
-
15
11
  if ((0, _utils2.parseJestFnCall)(node, context)) {
16
12
  return true;
17
13
  }
18
-
19
14
  return !!((_getNodeName = (0, _utils2.getNodeName)(node)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith('jest.'));
20
15
  };
21
-
22
16
  const isNullOrUndefined = node => {
23
17
  return node.type === _utils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils2.isIdentifier)(node, 'undefined');
24
18
  };
25
-
26
19
  const shouldBeInHook = (node, context, allowedFunctionCalls = []) => {
27
20
  switch (node.type) {
28
21
  case _utils.AST_NODE_TYPES.ExpressionStatement:
29
22
  return shouldBeInHook(node.expression, context, allowedFunctionCalls);
30
-
31
23
  case _utils.AST_NODE_TYPES.CallExpression:
32
24
  return !(isJestFnCall(node, context) || allowedFunctionCalls.includes((0, _utils2.getNodeName)(node)));
33
-
34
25
  case _utils.AST_NODE_TYPES.VariableDeclaration:
35
26
  {
36
27
  if (node.kind === 'const') {
37
28
  return false;
38
29
  }
39
-
40
30
  return node.declarations.some(({
41
31
  init
42
32
  }) => init !== null && !isNullOrUndefined(init));
43
33
  }
44
-
45
34
  default:
46
35
  return false;
47
36
  }
48
37
  };
49
-
50
38
  var _default = (0, _utils2.createRule)({
51
39
  name: __filename,
52
40
  meta: {
@@ -75,14 +63,10 @@ var _default = (0, _utils2.createRule)({
75
63
  defaultOptions: [{
76
64
  allowedFunctionCalls: []
77
65
  }],
78
-
79
66
  create(context) {
80
- var _context$options$;
81
-
82
67
  const {
83
68
  allowedFunctionCalls
84
- } = (_context$options$ = context.options[0]) !== null && _context$options$ !== void 0 ? _context$options$ : {};
85
-
69
+ } = context.options[0] ?? {};
86
70
  const checkBlockBody = body => {
87
71
  for (const statement of body) {
88
72
  if (shouldBeInHook(statement, context, allowedFunctionCalls)) {
@@ -93,29 +77,21 @@ var _default = (0, _utils2.createRule)({
93
77
  }
94
78
  }
95
79
  };
96
-
97
80
  return {
98
81
  Program(program) {
99
82
  checkBlockBody(program.body);
100
83
  },
101
-
102
84
  CallExpression(node) {
103
85
  if (!(0, _utils2.isTypeOfJestFnCall)(node, context, ['describe']) || node.arguments.length < 2) {
104
86
  return;
105
87
  }
106
-
107
88
  const [, testFn] = node.arguments;
108
-
109
89
  if (!(0, _utils2.isFunction)(testFn) || testFn.body.type !== _utils.AST_NODE_TYPES.BlockStatement) {
110
90
  return;
111
91
  }
112
-
113
92
  checkBlockBody(testFn.body.body);
114
93
  }
115
-
116
94
  };
117
95
  }
118
-
119
96
  });
120
-
121
97
  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,21 +20,17 @@ var _default = (0, _utils.createRule)({
22
20
  schema: []
23
21
  },
24
22
  defaultOptions: [],
25
-
26
23
  create(context) {
27
24
  return {
28
25
  CallExpression(node) {
29
26
  const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
30
-
31
27
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'expect') {
32
28
  return;
33
29
  }
34
-
35
30
  const {
36
31
  matcher
37
32
  } = jestFnCall;
38
33
  const matcherName = (0, _utils.getAccessorValue)(matcher);
39
-
40
34
  if (jestFnCall.args.length === 0 && ['toThrow', 'toThrowError'].includes(matcherName) && !jestFnCall.modifiers.some(nod => (0, _utils.getAccessorValue)(nod) === 'not')) {
41
35
  // Look for `toThrow` calls with no arguments.
42
36
  context.report({
@@ -48,10 +42,7 @@ var _default = (0, _utils.createRule)({
48
42
  });
49
43
  }
50
44
  }
51
-
52
45
  };
53
46
  }
54
-
55
47
  });
56
-
57
48
  exports.default = _default;
@@ -4,15 +4,12 @@ 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 messages = {
11
9
  tooManyDescribes: 'There should not be more than {{ max }} describe{{ s }} at the top level',
12
10
  unexpectedTestCase: 'All test cases must be wrapped in a describe block.',
13
11
  unexpectedHook: 'All hooks must be wrapped in a describe block.'
14
12
  };
15
-
16
13
  var _default = (0, _utils.createRule)({
17
14
  name: __filename,
18
15
  meta: {
@@ -35,29 +32,22 @@ var _default = (0, _utils.createRule)({
35
32
  }]
36
33
  },
37
34
  defaultOptions: [{}],
38
-
39
35
  create(context) {
40
- var _context$options$;
41
-
42
36
  const {
43
37
  maxNumberOfTopLevelDescribes = Infinity
44
- } = (_context$options$ = context.options[0]) !== null && _context$options$ !== void 0 ? _context$options$ : {};
38
+ } = context.options[0] ?? {};
45
39
  let numberOfTopLevelDescribeBlocks = 0;
46
40
  let numberOfDescribeBlocks = 0;
47
41
  return {
48
42
  CallExpression(node) {
49
43
  const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
50
-
51
44
  if (!jestFnCall) {
52
45
  return;
53
46
  }
54
-
55
47
  if (jestFnCall.type === 'describe') {
56
48
  numberOfDescribeBlocks++;
57
-
58
49
  if (numberOfDescribeBlocks === 1) {
59
50
  numberOfTopLevelDescribeBlocks++;
60
-
61
51
  if (numberOfTopLevelDescribeBlocks > maxNumberOfTopLevelDescribes) {
62
52
  context.report({
63
53
  node,
@@ -69,10 +59,8 @@ var _default = (0, _utils.createRule)({
69
59
  });
70
60
  }
71
61
  }
72
-
73
62
  return;
74
63
  }
75
-
76
64
  if (numberOfDescribeBlocks === 0) {
77
65
  if (jestFnCall.type === 'test') {
78
66
  context.report({
@@ -81,7 +69,6 @@ var _default = (0, _utils.createRule)({
81
69
  });
82
70
  return;
83
71
  }
84
-
85
72
  if (jestFnCall.type === 'hook') {
86
73
  context.report({
87
74
  node,
@@ -91,16 +78,12 @@ var _default = (0, _utils.createRule)({
91
78
  }
92
79
  }
93
80
  },
94
-
95
81
  'CallExpression:exit'(node) {
96
82
  if ((0, _utils.isTypeOfJestFnCall)(node, context, ['describe'])) {
97
83
  numberOfDescribeBlocks--;
98
84
  }
99
85
  }
100
-
101
86
  };
102
87
  }
103
-
104
88
  });
105
-
106
89
  exports.default = _default;
@@ -4,40 +4,23 @@ 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 toThrowMatchers = ['toThrow', 'toThrowError', 'toThrowErrorMatchingSnapshot', 'toThrowErrorMatchingInlineSnapshot'];
13
-
14
10
  const baseRule = (() => {
15
11
  try {
16
12
  // eslint-disable-next-line @typescript-eslint/no-require-imports
17
13
  const TSESLintPlugin = require('@typescript-eslint/eslint-plugin');
18
-
19
14
  return TSESLintPlugin.rules['unbound-method'];
20
15
  } catch (e) {
21
16
  const error = e;
22
-
23
17
  if (error.code === 'MODULE_NOT_FOUND') {
24
18
  return null;
25
19
  }
26
-
27
20
  throw error;
28
21
  }
29
22
  })();
30
-
31
- const tryCreateBaseRule = context => {
32
- try {
33
- return baseRule === null || baseRule === void 0 ? void 0 : baseRule.create(context);
34
- } catch {
35
- return null;
36
- }
37
- };
38
-
39
23
  const DEFAULT_MESSAGE = 'This rule requires `@typescript-eslint/eslint-plugin`';
40
-
41
24
  var _default = (0, _utils2.createRule)({
42
25
  defaultOptions: [{
43
26
  ignoreStatic: false
@@ -60,39 +43,29 @@ var _default = (0, _utils2.createRule)({
60
43
  recommended: false
61
44
  }
62
45
  },
63
-
64
46
  create(context) {
65
- const baseSelectors = tryCreateBaseRule(context);
66
-
47
+ const baseSelectors = baseRule === null || baseRule === void 0 ? void 0 : baseRule.create(context);
67
48
  if (!baseSelectors) {
68
49
  return {};
69
50
  }
70
-
71
- return { ...baseSelectors,
72
-
51
+ return {
52
+ ...baseSelectors,
73
53
  MemberExpression(node) {
74
54
  var _node$parent, _baseSelectors$Member;
75
-
76
55
  if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === _utils.AST_NODE_TYPES.CallExpression) {
77
56
  const jestFnCall = (0, _utils2.parseJestFnCall)((0, _utils2.findTopMostCallExpression)(node.parent), context);
78
-
79
57
  if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'expect') {
80
58
  const {
81
59
  matcher
82
60
  } = jestFnCall;
83
-
84
61
  if (!toThrowMatchers.includes((0, _utils2.getAccessorValue)(matcher))) {
85
62
  return;
86
63
  }
87
64
  }
88
65
  }
89
-
90
66
  (_baseSelectors$Member = baseSelectors.MemberExpression) === null || _baseSelectors$Member === void 0 ? void 0 : _baseSelectors$Member.call(baseSelectors, node);
91
67
  }
92
-
93
68
  };
94
69
  }
95
-
96
70
  });
97
-
98
71
  exports.default = _default;
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isSupportedAccessor = exports.isStringNode = exports.isIdentifier = exports.getStringValue = exports.getAccessorValue = void 0;
7
-
8
7
  var _utils = require("@typescript-eslint/utils");
9
-
10
8
  /**
11
9
  * Checks if the given `node` is a `StringLiteral`.
12
10
  *
@@ -21,7 +19,6 @@ var _utils = require("@typescript-eslint/utils");
21
19
  * @template V
22
20
  */
23
21
  const isStringLiteral = (node, value) => node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'string' && (value === undefined || node.value === value);
24
-
25
22
  /**
26
23
  * Checks if the given `node` is a `TemplateLiteral`.
27
24
  *
@@ -37,9 +34,9 @@ const isStringLiteral = (node, value) => node.type === _utils.AST_NODE_TYPES.Lit
37
34
  *
38
35
  * @template V
39
36
  */
40
- const isTemplateLiteral = (node, value) => node.type === _utils.AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1 && ( // bail out if not simple
37
+ const isTemplateLiteral = (node, value) => node.type === _utils.AST_NODE_TYPES.TemplateLiteral && node.quasis.length === 1 && (
38
+ // bail out if not simple
41
39
  value === undefined || node.quasis[0].value.raw === value);
42
-
43
40
  /**
44
41
  * Checks if the given `node` is a {@link StringNode}.
45
42
  *
@@ -51,6 +48,7 @@ value === undefined || node.quasis[0].value.raw === value);
51
48
  * @template V
52
49
  */
53
50
  const isStringNode = (node, specifics) => isStringLiteral(node, specifics) || isTemplateLiteral(node, specifics);
51
+
54
52
  /**
55
53
  * Gets the value of the given `StringNode`.
56
54
  *
@@ -63,18 +61,13 @@ const isStringNode = (node, specifics) => isStringLiteral(node, specifics) || is
63
61
  *
64
62
  * @template S
65
63
  */
66
-
67
-
68
64
  exports.isStringNode = isStringNode;
69
-
70
65
  const getStringValue = node => isTemplateLiteral(node) ? node.quasis[0].value.raw : node.value;
66
+
71
67
  /**
72
68
  * An `Identifier` with a known `name` value - i.e `expect`.
73
69
  */
74
-
75
-
76
70
  exports.getStringValue = getStringValue;
77
-
78
71
  /**
79
72
  * Checks if the given `node` is an `Identifier`.
80
73
  *
@@ -89,6 +82,7 @@ exports.getStringValue = getStringValue;
89
82
  * @template V
90
83
  */
91
84
  const isIdentifier = (node, name) => node.type === _utils.AST_NODE_TYPES.Identifier && (name === undefined || node.name === name);
85
+
92
86
  /**
93
87
  * Checks if the given `node` is a "supported accessor".
94
88
  *
@@ -111,11 +105,9 @@ const isIdentifier = (node, name) => node.type === _utils.AST_NODE_TYPES.Identif
111
105
  *
112
106
  * @template V
113
107
  */
114
-
115
-
116
108
  exports.isIdentifier = isIdentifier;
117
-
118
109
  const isSupportedAccessor = (node, value) => isIdentifier(node, value) || isStringNode(node, value);
110
+
119
111
  /**
120
112
  * Gets the value of the given `AccessorNode`,
121
113
  * account for the different node types.
@@ -126,10 +118,6 @@ const isSupportedAccessor = (node, value) => isIdentifier(node, value) || isStri
126
118
  *
127
119
  * @template S
128
120
  */
129
-
130
-
131
121
  exports.isSupportedAccessor = isSupportedAccessor;
132
-
133
122
  const getAccessorValue = accessor => accessor.type === _utils.AST_NODE_TYPES.Identifier ? accessor.name : getStringValue(accessor);
134
-
135
123
  exports.getAccessorValue = getAccessorValue;
@@ -5,25 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.detectJestVersion = void 0;
7
7
  let cachedJestVersion = null;
8
-
9
8
  const detectJestVersion = () => {
10
9
  if (cachedJestVersion) {
11
10
  return cachedJestVersion;
12
11
  }
13
-
14
12
  try {
15
13
  const jestPath = require.resolve('jest/package.json');
16
-
17
- const jestPackageJson = // eslint-disable-next-line @typescript-eslint/no-require-imports
14
+ const jestPackageJson =
15
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
18
16
  require(jestPath);
19
-
20
17
  if (jestPackageJson.version) {
21
18
  const [majorVersion] = jestPackageJson.version.split('.');
22
19
  return cachedJestVersion = parseInt(majorVersion, 10);
23
20
  }
24
21
  } catch {}
25
-
26
22
  throw new Error('Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly');
27
23
  };
28
-
29
24
  exports.detectJestVersion = detectJestVersion;
@@ -4,11 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.followTypeAssertionChain = void 0;
7
-
8
7
  var _utils = require("@typescript-eslint/utils");
9
-
10
8
  const isTypeCastExpression = node => node.type === _utils.AST_NODE_TYPES.TSAsExpression || node.type === _utils.AST_NODE_TYPES.TSTypeAssertion;
11
-
12
9
  const followTypeAssertionChain = expression => isTypeCastExpression(expression) ? followTypeAssertionChain(expression.expression) : expression;
13
-
14
10
  exports.followTypeAssertionChain = followTypeAssertionChain;
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _accessors = require("./accessors");
8
-
9
7
  Object.keys(_accessors).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _accessors[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_accessors).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _detectJestVersion = require("./detectJestVersion");
21
-
22
18
  Object.keys(_detectJestVersion).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _detectJestVersion[key]) return;
@@ -29,9 +25,7 @@ Object.keys(_detectJestVersion).forEach(function (key) {
29
25
  }
30
26
  });
31
27
  });
32
-
33
28
  var _followTypeAssertionChain = require("./followTypeAssertionChain");
34
-
35
29
  Object.keys(_followTypeAssertionChain).forEach(function (key) {
36
30
  if (key === "default" || key === "__esModule") return;
37
31
  if (key in exports && exports[key] === _followTypeAssertionChain[key]) return;
@@ -42,9 +36,7 @@ Object.keys(_followTypeAssertionChain).forEach(function (key) {
42
36
  }
43
37
  });
44
38
  });
45
-
46
39
  var _misc = require("./misc");
47
-
48
40
  Object.keys(_misc).forEach(function (key) {
49
41
  if (key === "default" || key === "__esModule") return;
50
42
  if (key in exports && exports[key] === _misc[key]) return;
@@ -55,9 +47,7 @@ Object.keys(_misc).forEach(function (key) {
55
47
  }
56
48
  });
57
49
  });
58
-
59
50
  var _parseJestFnCall = require("./parseJestFnCall");
60
-
61
51
  Object.keys(_parseJestFnCall).forEach(function (key) {
62
52
  if (key === "default" || key === "__esModule") return;
63
53
  if (key in exports && exports[key] === _parseJestFnCall[key]) return;
@@ -5,33 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getFirstMatcherArg = exports.findTopMostCallExpression = exports.createRule = exports.TestCaseName = exports.ModifierName = exports.HookName = exports.EqualityMatcher = exports.DescribeAlias = void 0;
7
7
  exports.getNodeName = getNodeName;
8
- exports.replaceAccessorFixer = exports.isFunction = exports.isBooleanLiteral = exports.hasOnlyOneArgument = exports.getTestCallExpressionsFromDeclaredVariables = void 0;
9
-
8
+ exports.replaceAccessorFixer = exports.removeExtraArgumentsFixer = exports.isFunction = exports.isBooleanLiteral = exports.hasOnlyOneArgument = exports.getTestCallExpressionsFromDeclaredVariables = void 0;
10
9
  var _path = require("path");
11
-
12
10
  var _utils = require("@typescript-eslint/utils");
13
-
14
11
  var _package = require("../../../package.json");
15
-
16
12
  var _accessors = require("./accessors");
17
-
18
13
  var _followTypeAssertionChain = require("./followTypeAssertionChain");
19
-
20
14
  var _parseJestFnCall = require("./parseJestFnCall");
21
-
22
15
  const REPO_URL = 'https://github.com/jest-community/eslint-plugin-jest';
23
-
24
16
  const createRule = _utils.ESLintUtils.RuleCreator(name => {
25
17
  const ruleName = (0, _path.parse)(name).name;
26
18
  return `${REPO_URL}/blob/v${_package.version}/docs/rules/${ruleName}.md`;
27
19
  });
20
+
28
21
  /**
29
22
  * Represents a `MemberExpression` with a "known" `property`.
30
23
  */
31
-
32
-
33
24
  exports.createRule = createRule;
34
-
35
25
  /**
36
26
  * Guards that the given `call` has only one `argument`.
37
27
  *
@@ -40,20 +30,16 @@ exports.createRule = createRule;
40
30
  * @return {call is CallExpressionWithSingleArgument}
41
31
  */
42
32
  const hasOnlyOneArgument = call => call.arguments.length === 1;
43
-
44
33
  exports.hasOnlyOneArgument = hasOnlyOneArgument;
45
34
  let DescribeAlias;
46
35
  exports.DescribeAlias = DescribeAlias;
47
-
48
36
  (function (DescribeAlias) {
49
37
  DescribeAlias["describe"] = "describe";
50
38
  DescribeAlias["fdescribe"] = "fdescribe";
51
39
  DescribeAlias["xdescribe"] = "xdescribe";
52
40
  })(DescribeAlias || (exports.DescribeAlias = DescribeAlias = {}));
53
-
54
41
  let TestCaseName;
55
42
  exports.TestCaseName = TestCaseName;
56
-
57
43
  (function (TestCaseName) {
58
44
  TestCaseName["fit"] = "fit";
59
45
  TestCaseName["it"] = "it";
@@ -61,61 +47,46 @@ exports.TestCaseName = TestCaseName;
61
47
  TestCaseName["xit"] = "xit";
62
48
  TestCaseName["xtest"] = "xtest";
63
49
  })(TestCaseName || (exports.TestCaseName = TestCaseName = {}));
64
-
65
50
  let HookName;
66
51
  exports.HookName = HookName;
67
-
68
52
  (function (HookName) {
69
53
  HookName["beforeAll"] = "beforeAll";
70
54
  HookName["beforeEach"] = "beforeEach";
71
55
  HookName["afterAll"] = "afterAll";
72
56
  HookName["afterEach"] = "afterEach";
73
57
  })(HookName || (exports.HookName = HookName = {}));
74
-
75
58
  let ModifierName;
76
59
  exports.ModifierName = ModifierName;
77
-
78
60
  (function (ModifierName) {
79
61
  ModifierName["not"] = "not";
80
62
  ModifierName["rejects"] = "rejects";
81
63
  ModifierName["resolves"] = "resolves";
82
64
  })(ModifierName || (exports.ModifierName = ModifierName = {}));
83
-
84
65
  let EqualityMatcher;
85
66
  exports.EqualityMatcher = EqualityMatcher;
86
-
87
67
  (function (EqualityMatcher) {
88
68
  EqualityMatcher["toBe"] = "toBe";
89
69
  EqualityMatcher["toEqual"] = "toEqual";
90
70
  EqualityMatcher["toStrictEqual"] = "toStrictEqual";
91
71
  })(EqualityMatcher || (exports.EqualityMatcher = EqualityMatcher = {}));
92
-
93
72
  const joinNames = (a, b) => a && b ? `${a}.${b}` : null;
94
-
95
73
  function getNodeName(node) {
96
74
  if ((0, _accessors.isSupportedAccessor)(node)) {
97
75
  return (0, _accessors.getAccessorValue)(node);
98
76
  }
99
-
100
77
  switch (node.type) {
101
78
  case _utils.AST_NODE_TYPES.TaggedTemplateExpression:
102
79
  return getNodeName(node.tag);
103
-
104
80
  case _utils.AST_NODE_TYPES.MemberExpression:
105
81
  return joinNames(getNodeName(node.object), getNodeName(node.property));
106
-
107
82
  case _utils.AST_NODE_TYPES.NewExpression:
108
83
  case _utils.AST_NODE_TYPES.CallExpression:
109
84
  return getNodeName(node.callee);
110
85
  }
111
-
112
86
  return null;
113
87
  }
114
-
115
88
  const isFunction = node => node.type === _utils.AST_NODE_TYPES.FunctionExpression || node.type === _utils.AST_NODE_TYPES.ArrowFunctionExpression;
116
-
117
89
  exports.isFunction = isFunction;
118
-
119
90
  const getTestCallExpressionsFromDeclaredVariables = (declaredVariables, context) => {
120
91
  return declaredVariables.reduce((acc, {
121
92
  references
@@ -123,59 +94,55 @@ const getTestCallExpressionsFromDeclaredVariables = (declaredVariables, context)
123
94
  identifier
124
95
  }) => identifier.parent).filter(node => (node === null || node === void 0 ? void 0 : node.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _parseJestFnCall.isTypeOfJestFnCall)(node, context, ['test']))), []);
125
96
  };
97
+
126
98
  /**
127
99
  * Replaces an accessor node with the given `text`, surrounding it in quotes if required.
128
100
  *
129
101
  * This ensures that fixes produce valid code when replacing both dot-based and
130
102
  * bracket-based property accessors.
131
103
  */
132
-
133
-
134
104
  exports.getTestCallExpressionsFromDeclaredVariables = getTestCallExpressionsFromDeclaredVariables;
135
-
136
105
  const replaceAccessorFixer = (fixer, node, text) => {
137
106
  return fixer.replaceText(node, node.type === _utils.AST_NODE_TYPES.Identifier ? text : `'${text}'`);
138
107
  };
139
-
140
108
  exports.replaceAccessorFixer = replaceAccessorFixer;
141
-
109
+ const removeExtraArgumentsFixer = (fixer, context, func, from) => {
110
+ const firstArg = func.arguments[from];
111
+ const lastArg = func.arguments[func.arguments.length - 1];
112
+ const sourceCode = context.getSourceCode();
113
+ let tokenAfterLastParam = sourceCode.getTokenAfter(lastArg);
114
+ if (tokenAfterLastParam.value === ',') {
115
+ tokenAfterLastParam = sourceCode.getTokenAfter(tokenAfterLastParam);
116
+ }
117
+ return fixer.removeRange([firstArg.range[0], tokenAfterLastParam.range[0]]);
118
+ };
119
+ exports.removeExtraArgumentsFixer = removeExtraArgumentsFixer;
142
120
  const findTopMostCallExpression = node => {
143
121
  let topMostCallExpression = node;
144
122
  let {
145
123
  parent
146
124
  } = node;
147
-
148
125
  while (parent) {
149
126
  if (parent.type === _utils.AST_NODE_TYPES.CallExpression) {
150
127
  topMostCallExpression = parent;
151
128
  parent = parent.parent;
152
129
  continue;
153
130
  }
154
-
155
131
  if (parent.type !== _utils.AST_NODE_TYPES.MemberExpression) {
156
132
  break;
157
133
  }
158
-
159
134
  parent = parent.parent;
160
135
  }
161
-
162
136
  return topMostCallExpression;
163
137
  };
164
-
165
138
  exports.findTopMostCallExpression = findTopMostCallExpression;
166
-
167
139
  const isBooleanLiteral = node => node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
168
-
169
140
  exports.isBooleanLiteral = isBooleanLiteral;
170
-
171
141
  const getFirstMatcherArg = expectFnCall => {
172
142
  const [firstArg] = expectFnCall.args;
173
-
174
143
  if (firstArg.type === _utils.AST_NODE_TYPES.SpreadElement) {
175
144
  return firstArg;
176
145
  }
177
-
178
146
  return (0, _followTypeAssertionChain.followTypeAssertionChain)(firstArg);
179
147
  };
180
-
181
148
  exports.getFirstMatcherArg = getFirstMatcherArg;