eslint-plugin-jest 26.1.3 → 26.2.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 (41) hide show
  1. package/README.md +30 -2
  2. package/docs/rules/no-conditional-expect.md +1 -1
  3. package/docs/rules/no-deprecated-functions.md +1 -2
  4. package/docs/rules/no-identical-title.md +1 -1
  5. package/docs/rules/no-jasmine-globals.md +2 -2
  6. package/docs/rules/no-jest-import.md +1 -1
  7. package/docs/rules/no-large-snapshots.md +2 -2
  8. package/docs/rules/no-standalone-expect.md +1 -1
  9. package/docs/rules/prefer-comparison-matcher.md +1 -1
  10. package/docs/rules/prefer-equality-matcher.md +1 -1
  11. package/docs/rules/prefer-expect-assertions.md +1 -1
  12. package/docs/rules/prefer-hooks-on-top.md +1 -1
  13. package/docs/rules/prefer-lowercase-title.md +2 -2
  14. package/docs/rules/valid-expect.md +2 -2
  15. package/lib/rules/consistent-test-it.js +5 -4
  16. package/lib/rules/expect-expect.js +3 -2
  17. package/lib/rules/max-nested-describe.js +3 -2
  18. package/lib/rules/no-conditional-expect.js +4 -3
  19. package/lib/rules/no-conditional-in-test.js +3 -2
  20. package/lib/rules/no-done-callback.js +5 -4
  21. package/lib/rules/no-duplicate-hooks.js +4 -3
  22. package/lib/rules/no-export.js +2 -1
  23. package/lib/rules/no-focused-tests.js +30 -25
  24. package/lib/rules/no-hooks.js +2 -1
  25. package/lib/rules/no-identical-title.js +5 -4
  26. package/lib/rules/no-if.js +3 -2
  27. package/lib/rules/no-standalone-expect.js +6 -5
  28. package/lib/rules/no-test-prefixes.js +2 -1
  29. package/lib/rules/no-test-return-statement.js +3 -2
  30. package/lib/rules/prefer-expect-assertions.js +5 -2
  31. package/lib/rules/prefer-hooks-on-top.js +3 -2
  32. package/lib/rules/prefer-lowercase-title.js +6 -5
  33. package/lib/rules/prefer-snapshot-hint.js +16 -0
  34. package/lib/rules/prefer-todo.js +3 -2
  35. package/lib/rules/require-hook.js +8 -7
  36. package/lib/rules/require-top-level-describe.js +5 -4
  37. package/lib/rules/utils.js +187 -50
  38. package/lib/rules/valid-describe-callback.js +2 -1
  39. package/lib/rules/valid-expect-in-promise.js +8 -7
  40. package/lib/rules/valid-title.js +4 -3
  41. package/package.json +6 -9
package/README.md CHANGED
@@ -59,6 +59,34 @@ doing:
59
59
  This is included in all configs shared by this plugin, so can be omitted if
60
60
  extending them.
61
61
 
62
+ ### Running rules only on test-related files
63
+
64
+ The rules provided by this plugin assume that the files they are checking are
65
+ test-related. This means it's generally not suitable to include them in your
66
+ top-level configuration as that applies to all files being linted which can
67
+ include source files.
68
+
69
+ You can use
70
+ [overrides](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work)
71
+ to have ESLint apply additional rules to specific files:
72
+
73
+ ```json
74
+ {
75
+ "extends": ["eslint:recommended"],
76
+ "overrides": [
77
+ {
78
+ "files": ["test/**"],
79
+ "plugins": ["jest"],
80
+ "extends": ["plugin:jest/recommended"],
81
+ "rules": { "jest/prefer-expect-assertions": "off" }
82
+ }
83
+ ],
84
+ "rules": {
85
+ "indent": ["error", 2]
86
+ }
87
+ }
88
+ ```
89
+
62
90
  ### Jest `version` setting
63
91
 
64
92
  The behaviour of some rules (specifically [`no-deprecated-functions`][]) change
@@ -211,8 +239,8 @@ adjust your eslint config as outlined
211
239
 
212
240
  Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
213
241
  the rules here will fallback to doing nothing if type information is not
214
- available, meaning its safe to include them in shared configs that could be used
215
- on JavaScript and TypeScript projects.
242
+ available, meaning it's safe to include them in shared configs that could be
243
+ used on JavaScript and TypeScript projects.
216
244
 
217
245
  Also note that `unbound-method` depends on `@typescript-eslint/eslint-plugin`,
218
246
  as it extends the original `unbound-method` rule from that plugin.
@@ -107,7 +107,7 @@ While you can use `expect.assertions` & `expect.hasAssertions` for these
107
107
  situations, they only work with `expect`.
108
108
 
109
109
  A better way to handle this situation is to introduce a wrapper to handle the
110
- catching, and otherwise returns a specific "no error thrown" error if nothing is
110
+ catching, and otherwise return a specific "no error thrown" error if nothing is
111
111
  thrown by the wrapped function:
112
112
 
113
113
  ```typescript
@@ -37,8 +37,7 @@ Originally, the `requireActual` & `requireMock` the `requireActual`&
37
37
 
38
38
  These functions were later moved onto the `jest` object in order to be easier
39
39
  for type checkers to handle, and their use via `require` deprecated. Finally,
40
- the release of Jest 26 saw them removed from the `require` function all
41
- together.
40
+ the release of Jest 26 saw them removed from the `require` function altogether.
42
41
 
43
42
  ### `jest.runTimersToTime`
44
43
 
@@ -7,7 +7,7 @@ fix.
7
7
 
8
8
  ## Rule Details
9
9
 
10
- This rule looks at the title of every test and test suites. It will report when
10
+ This rule looks at the title of every test and test suite. It will report when
11
11
  two test suites or two test cases at the same level of a test suite have the
12
12
  same title.
13
13
 
@@ -9,8 +9,8 @@ API.
9
9
 
10
10
  ### Rule details
11
11
 
12
- This rule reports on any usage of Jasmine globals which is not ported to Jest,
13
- and suggests alternative from Jest's own API.
12
+ This rule reports on any usage of Jasmine globals, which is not ported to Jest,
13
+ and suggests alternatives from Jest's own API.
14
14
 
15
15
  ### Default configuration
16
16
 
@@ -17,4 +17,4 @@ first place.
17
17
 
18
18
  ## Further Reading
19
19
 
20
- \*[The Jest Object](https://facebook.github.io/jest/docs/en/jest-object.html)
20
+ - [The Jest Object](https://facebook.github.io/jest/docs/en/jest-object.html)
@@ -118,8 +118,8 @@ External). Use `inlineMaxSize` for
118
118
  [Inline Snapshots](https://jestjs.io/docs/en/snapshot-testing#inline-snapshots)
119
119
  size and `maxSize` for
120
120
  [External Snapshots](https://jestjs.io/docs/en/snapshot-testing#snapshot-testing-with-jest).
121
- If only `maxSize` is provided on options, the value of `maxSize` will be used to
122
- both snapshot types (Inline and External).
121
+ If only `maxSize` is provided on options, the value of `maxSize` will be used
122
+ for both snapshot types (Inline and External).
123
123
 
124
124
  Since `eslint-disable` comments are not preserved by Jest when updating
125
125
  snapshots, you can use the `allowedSnapshots` option to have specific snapshots
@@ -61,7 +61,7 @@ describe('a test', () => {
61
61
  ```
62
62
 
63
63
  \*Note that this rule will not trigger if the helper function is never used even
64
- thought the `expect` will not execute. Rely on a rule like no-unused-vars for
64
+ though the `expect` will not execute. Rely on a rule like no-unused-vars for
65
65
  this case.
66
66
 
67
67
  ### Options
@@ -1,6 +1,6 @@
1
1
  # Suggest using the built-in comparison matchers (`prefer-comparison-matcher`)
2
2
 
3
- Jest has a number of built-in matchers for comparing numbers which allow for
3
+ Jest has a number of built-in matchers for comparing numbers, which allow for
4
4
  more readable tests and error messages if an expectation fails.
5
5
 
6
6
  ## Rule details
@@ -1,6 +1,6 @@
1
1
  # Suggest using the built-in equality matchers (`prefer-equality-matcher`)
2
2
 
3
- Jest has built-in matchers for expecting equality which allow for more readable
3
+ Jest has built-in matchers for expecting equality, which allow for more readable
4
4
  tests and error messages if an expectation fails.
5
5
 
6
6
  ## Rule details
@@ -215,7 +215,7 @@ describe('getNumbers', () => {
215
215
 
216
216
  describe('/users', () => {
217
217
  it.each([1, 2, 3])('returns ok', id => {
218
- expect.assertions(3);
218
+ expect.assertions(1);
219
219
 
220
220
  client.get(`/users/${id}`, response => {
221
221
  expect(response.status).toBe(200);
@@ -1,7 +1,7 @@
1
1
  # Suggest having hooks before any test cases (`prefer-hooks-on-top`)
2
2
 
3
3
  While hooks can be setup anywhere in a test file, they are always called in a
4
- specific order which means it can be confusing if they're intermixed with test
4
+ specific order, which means it can be confusing if they're intermixed with test
5
5
  cases.
6
6
 
7
7
  This rule helps to ensure that hooks are always defined before test cases.
@@ -73,8 +73,8 @@ it('Uppercase description');
73
73
 
74
74
  ### `allowedPrefixes`
75
75
 
76
- This array option allows specifying prefixes which contain capitals that titles
77
- can start with. This can be useful when writing tests for api endpoints, where
76
+ This array option allows specifying prefixes, which contain capitals that titles
77
+ can start with. This can be useful when writing tests for API endpoints, where
78
78
  you'd like to prefix with the HTTP method.
79
79
 
80
80
  By default, nothing is allowed (the equivalent of `{ "allowedPrefixes": [] }`).
@@ -136,9 +136,9 @@ test('all the things', async () => {
136
136
  await Promise.resolve(
137
137
  expect(Promise.resolve('hello')).resolves.toEqual('hello'),
138
138
  );
139
- await Promise.all(
139
+ await Promise.all([
140
140
  expect(Promise.resolve('hello')).resolves.toEqual('hello'),
141
141
  expect(Promise.resolve('hi')).resolves.toEqual('hi'),
142
- );
142
+ ]);
143
143
  });
144
144
  ```
@@ -44,6 +44,7 @@ var _default = (0, _utils2.createRule)({
44
44
  }],
45
45
 
46
46
  create(context) {
47
+ const scope = context.getScope();
47
48
  const configObj = context.options[0] || {};
48
49
  const testKeyword = configObj.fn || _utils2.TestCaseName.test;
49
50
  const testKeywordWithinDescribe = configObj.withinDescribe || configObj.fn || _utils2.TestCaseName.it;
@@ -56,13 +57,13 @@ var _default = (0, _utils2.createRule)({
56
57
  return;
57
58
  }
58
59
 
59
- if ((0, _utils2.isDescribeCall)(node)) {
60
+ if ((0, _utils2.isDescribeCall)(node, scope)) {
60
61
  describeNestingLevel++;
61
62
  }
62
63
 
63
64
  const funcNode = node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
64
65
 
65
- if ((0, _utils2.isTestCaseCall)(node) && describeNestingLevel === 0 && !nodeName.includes(testKeyword)) {
66
+ if ((0, _utils2.isTestCaseCall)(node, scope) && describeNestingLevel === 0 && !nodeName.includes(testKeyword)) {
66
67
  const oppositeTestKeyword = getOppositeTestKeyword(testKeyword);
67
68
  context.report({
68
69
  messageId: 'consistentMethod',
@@ -75,7 +76,7 @@ var _default = (0, _utils2.createRule)({
75
76
  });
76
77
  }
77
78
 
78
- if ((0, _utils2.isTestCaseCall)(node) && describeNestingLevel > 0 && !nodeName.includes(testKeywordWithinDescribe)) {
79
+ if ((0, _utils2.isTestCaseCall)(node, scope) && describeNestingLevel > 0 && !nodeName.includes(testKeywordWithinDescribe)) {
79
80
  const oppositeTestKeyword = getOppositeTestKeyword(testKeywordWithinDescribe);
80
81
  context.report({
81
82
  messageId: 'consistentMethodWithinDescribe',
@@ -90,7 +91,7 @@ var _default = (0, _utils2.createRule)({
90
91
  },
91
92
 
92
93
  'CallExpression:exit'(node) {
93
- if ((0, _utils2.isDescribeCall)(node)) {
94
+ if ((0, _utils2.isDescribeCall)(node, scope)) {
94
95
  describeNestingLevel--;
95
96
  }
96
97
  }
@@ -68,6 +68,7 @@ var _default = (0, _utils2.createRule)({
68
68
  assertFunctionNames = ['expect'],
69
69
  additionalTestBlockFunctions = []
70
70
  }]) {
71
+ const scope = context.getScope();
71
72
  const unchecked = [];
72
73
 
73
74
  function checkCallExpressionUsed(nodes) {
@@ -76,7 +77,7 @@ var _default = (0, _utils2.createRule)({
76
77
 
77
78
  if (node.type === _utils.AST_NODE_TYPES.FunctionDeclaration) {
78
79
  const declaredVariables = context.getDeclaredVariables(node);
79
- const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
80
+ const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, scope);
80
81
  checkCallExpressionUsed(testCallExpressions);
81
82
  }
82
83
 
@@ -93,7 +94,7 @@ var _default = (0, _utils2.createRule)({
93
94
 
94
95
  const name = (_getNodeName = (0, _utils2.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 ? _getNodeName : '';
95
96
 
96
- if ((0, _utils2.isTestCaseCall)(node) || additionalTestBlockFunctions.includes(name)) {
97
+ if ((0, _utils2.isTestCaseCall)(node, scope) || additionalTestBlockFunctions.includes(name)) {
97
98
  if (node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property, 'todo')) {
98
99
  return;
99
100
  }
@@ -39,6 +39,7 @@ var _default = (0, _utils2.createRule)({
39
39
  create(context, [{
40
40
  max
41
41
  }]) {
42
+ const scope = context.getScope();
42
43
  const describeCallbackStack = [];
43
44
 
44
45
  function pushDescribeCallback(node) {
@@ -46,7 +47,7 @@ var _default = (0, _utils2.createRule)({
46
47
  parent
47
48
  } = node;
48
49
 
49
- if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.isDescribeCall)(parent)) {
50
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.isDescribeCall)(parent, scope)) {
50
51
  return;
51
52
  }
52
53
 
@@ -69,7 +70,7 @@ var _default = (0, _utils2.createRule)({
69
70
  parent
70
71
  } = node;
71
72
 
72
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isDescribeCall)(parent)) {
73
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isDescribeCall)(parent, scope)) {
73
74
  describeCallbackStack.pop();
74
75
  }
75
76
  }
@@ -28,6 +28,7 @@ var _default = (0, _utils2.createRule)({
28
28
  defaultOptions: [],
29
29
 
30
30
  create(context) {
31
+ const scope = context.getScope();
31
32
  let conditionalDepth = 0;
32
33
  let inTestCase = false;
33
34
  let inPromiseCatch = false;
@@ -39,7 +40,7 @@ var _default = (0, _utils2.createRule)({
39
40
  return {
40
41
  FunctionDeclaration(node) {
41
42
  const declaredVariables = context.getDeclaredVariables(node);
42
- const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
43
+ const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, scope);
43
44
 
44
45
  if (testCallExpressions.length > 0) {
45
46
  inTestCase = true;
@@ -47,7 +48,7 @@ var _default = (0, _utils2.createRule)({
47
48
  },
48
49
 
49
50
  CallExpression(node) {
50
- if ((0, _utils2.isTestCaseCall)(node)) {
51
+ if ((0, _utils2.isTestCaseCall)(node, scope)) {
51
52
  inTestCase = true;
52
53
  }
53
54
 
@@ -71,7 +72,7 @@ var _default = (0, _utils2.createRule)({
71
72
  },
72
73
 
73
74
  'CallExpression:exit'(node) {
74
- if ((0, _utils2.isTestCaseCall)(node)) {
75
+ if ((0, _utils2.isTestCaseCall)(node, scope)) {
75
76
  inTestCase = false;
76
77
  }
77
78
 
@@ -24,6 +24,7 @@ var _default = (0, _utils.createRule)({
24
24
  defaultOptions: [],
25
25
 
26
26
  create(context) {
27
+ const scope = context.getScope();
27
28
  let inTestCase = false;
28
29
 
29
30
  const maybeReportConditional = node => {
@@ -37,13 +38,13 @@ var _default = (0, _utils.createRule)({
37
38
 
38
39
  return {
39
40
  CallExpression(node) {
40
- if ((0, _utils.isTestCaseCall)(node)) {
41
+ if ((0, _utils.isTestCaseCall)(node, scope)) {
41
42
  inTestCase = true;
42
43
  }
43
44
  },
44
45
 
45
46
  'CallExpression:exit'(node) {
46
- if ((0, _utils.isTestCaseCall)(node)) {
47
+ if ((0, _utils.isTestCaseCall)(node, scope)) {
47
48
  inTestCase = false;
48
49
  }
49
50
  },
@@ -9,16 +9,16 @@ var _utils = require("@typescript-eslint/utils");
9
9
 
10
10
  var _utils2 = require("./utils");
11
11
 
12
- const findCallbackArg = (node, isJestEach) => {
12
+ const findCallbackArg = (node, isJestEach, scope) => {
13
13
  if (isJestEach) {
14
14
  return node.arguments[1];
15
15
  }
16
16
 
17
- if ((0, _utils2.isHook)(node) && node.arguments.length >= 1) {
17
+ if ((0, _utils2.isHookCall)(node, scope) && node.arguments.length >= 1) {
18
18
  return node.arguments[0];
19
19
  }
20
20
 
21
- if ((0, _utils2.isTestCaseCall)(node) && node.arguments.length >= 2) {
21
+ if ((0, _utils2.isTestCaseCall)(node, scope) && node.arguments.length >= 2) {
22
22
  return node.arguments[1];
23
23
  }
24
24
 
@@ -46,6 +46,7 @@ var _default = (0, _utils2.createRule)({
46
46
  defaultOptions: [],
47
47
 
48
48
  create(context) {
49
+ const scope = context.getScope();
49
50
  return {
50
51
  CallExpression(node) {
51
52
  var _getNodeName$endsWith, _getNodeName;
@@ -60,7 +61,7 @@ var _default = (0, _utils2.createRule)({
60
61
  return;
61
62
  }
62
63
 
63
- const callback = findCallbackArg(node, isJestEach);
64
+ const callback = findCallbackArg(node, isJestEach, scope);
64
65
  const callbackArgIndex = Number(isJestEach);
65
66
 
66
67
  if (!callback || !(0, _utils2.isFunction)(callback) || callback.params.length !== 1 + callbackArgIndex) {
@@ -31,14 +31,15 @@ var _default = (0, _utils.createRule)({
31
31
  defaultOptions: [],
32
32
 
33
33
  create(context) {
34
+ const scope = context.getScope();
34
35
  const hookContexts = [newHookContext()];
35
36
  return {
36
37
  CallExpression(node) {
37
- if ((0, _utils.isDescribeCall)(node)) {
38
+ if ((0, _utils.isDescribeCall)(node, scope)) {
38
39
  hookContexts.push(newHookContext());
39
40
  }
40
41
 
41
- if ((0, _utils.isHook)(node)) {
42
+ if ((0, _utils.isHookCall)(node, scope)) {
42
43
  const currentLayer = hookContexts[hookContexts.length - 1];
43
44
  currentLayer[node.callee.name] += 1;
44
45
 
@@ -55,7 +56,7 @@ var _default = (0, _utils.createRule)({
55
56
  },
56
57
 
57
58
  'CallExpression:exit'(node) {
58
- if ((0, _utils.isDescribeCall)(node)) {
59
+ if ((0, _utils.isDescribeCall)(node, scope)) {
59
60
  hookContexts.pop();
60
61
  }
61
62
  }
@@ -26,6 +26,7 @@ var _default = (0, _utils2.createRule)({
26
26
  defaultOptions: [],
27
27
 
28
28
  create(context) {
29
+ const scope = context.getScope();
29
30
  const exportNodes = [];
30
31
  let hasTestCase = false;
31
32
  return {
@@ -41,7 +42,7 @@ var _default = (0, _utils2.createRule)({
41
42
  },
42
43
 
43
44
  CallExpression(node) {
44
- if ((0, _utils2.isTestCaseCall)(node)) {
45
+ if ((0, _utils2.isTestCaseCall)(node, scope)) {
45
46
  hasTestCase = true;
46
47
  }
47
48
  },
@@ -45,41 +45,46 @@ var _default = (0, _utils2.createRule)({
45
45
  hasSuggestions: true
46
46
  },
47
47
  defaultOptions: [],
48
- create: context => ({
49
- CallExpression(node) {
50
- if (!(0, _utils2.isDescribeCall)(node) && !(0, _utils2.isTestCaseCall)(node)) {
51
- return;
52
- }
53
48
 
54
- if ((0, _utils2.getNodeName)(node).startsWith('f')) {
49
+ create(context) {
50
+ const scope = context.getScope();
51
+ return {
52
+ CallExpression(node) {
53
+ if (!(0, _utils2.isDescribeCall)(node, scope) && !(0, _utils2.isTestCaseCall)(node, scope)) {
54
+ return;
55
+ }
56
+
57
+ if ((0, _utils2.getNodeName)(node).startsWith('f')) {
58
+ context.report({
59
+ messageId: 'focusedTest',
60
+ node,
61
+ suggest: [{
62
+ messageId: 'suggestRemoveFocus',
63
+ fix: fixer => fixer.removeRange([node.range[0], node.range[0] + 1])
64
+ }]
65
+ });
66
+ return;
67
+ }
68
+
69
+ const onlyNode = findOnlyNode(node);
70
+
71
+ if (!onlyNode) {
72
+ return;
73
+ }
74
+
55
75
  context.report({
56
76
  messageId: 'focusedTest',
57
- node,
77
+ node: onlyNode,
58
78
  suggest: [{
59
79
  messageId: 'suggestRemoveFocus',
60
- fix: fixer => fixer.removeRange([node.range[0], node.range[0] + 1])
80
+ fix: fixer => fixer.removeRange([onlyNode.range[0] - 1, onlyNode.range[1] + Number(onlyNode.type !== _utils.AST_NODE_TYPES.Identifier)])
61
81
  }]
62
82
  });
63
- return;
64
83
  }
65
84
 
66
- const onlyNode = findOnlyNode(node);
67
-
68
- if (!onlyNode) {
69
- return;
70
- }
71
-
72
- context.report({
73
- messageId: 'focusedTest',
74
- node: onlyNode,
75
- suggest: [{
76
- messageId: 'suggestRemoveFocus',
77
- fix: fixer => fixer.removeRange([onlyNode.range[0] - 1, onlyNode.range[1] + Number(onlyNode.type !== _utils.AST_NODE_TYPES.Identifier)])
78
- }]
79
- });
80
- }
85
+ };
86
+ }
81
87
 
82
- })
83
88
  });
84
89
 
85
90
  exports.default = _default;
@@ -37,9 +37,10 @@ var _default = (0, _utils.createRule)({
37
37
  create(context, [{
38
38
  allow = []
39
39
  }]) {
40
+ const scope = context.getScope();
40
41
  return {
41
42
  CallExpression(node) {
42
- if ((0, _utils.isHook)(node) && !allow.includes(node.callee.name)) {
43
+ if ((0, _utils.isHookCall)(node, scope) && !allow.includes(node.callee.name)) {
43
44
  context.report({
44
45
  node,
45
46
  messageId: 'unexpectedHook',
@@ -30,6 +30,7 @@ var _default = (0, _utils.createRule)({
30
30
  defaultOptions: [],
31
31
 
32
32
  create(context) {
33
+ const scope = context.getScope();
33
34
  const contexts = [newDescribeContext()];
34
35
  return {
35
36
  CallExpression(node) {
@@ -37,7 +38,7 @@ var _default = (0, _utils.createRule)({
37
38
 
38
39
  const currentLayer = contexts[contexts.length - 1];
39
40
 
40
- if ((0, _utils.isDescribeCall)(node)) {
41
+ if ((0, _utils.isDescribeCall)(node, scope)) {
41
42
  contexts.push(newDescribeContext());
42
43
  }
43
44
 
@@ -53,7 +54,7 @@ var _default = (0, _utils.createRule)({
53
54
 
54
55
  const title = (0, _utils.getStringValue)(argument);
55
56
 
56
- if ((0, _utils.isTestCaseCall)(node)) {
57
+ if ((0, _utils.isTestCaseCall)(node, scope)) {
57
58
  if (currentLayer.testTitles.includes(title)) {
58
59
  context.report({
59
60
  messageId: 'multipleTestTitle',
@@ -64,7 +65,7 @@ var _default = (0, _utils.createRule)({
64
65
  currentLayer.testTitles.push(title);
65
66
  }
66
67
 
67
- if (!(0, _utils.isDescribeCall)(node)) {
68
+ if (!(0, _utils.isDescribeCall)(node, scope)) {
68
69
  return;
69
70
  }
70
71
 
@@ -79,7 +80,7 @@ var _default = (0, _utils.createRule)({
79
80
  },
80
81
 
81
82
  'CallExpression:exit'(node) {
82
- if ((0, _utils.isDescribeCall)(node)) {
83
+ if ((0, _utils.isDescribeCall)(node, scope)) {
83
84
  contexts.pop();
84
85
  }
85
86
  }
@@ -38,6 +38,7 @@ var _default = (0, _utils2.createRule)({
38
38
  defaultOptions: [],
39
39
 
40
40
  create(context) {
41
+ const scope = context.getScope();
41
42
  const stack = [];
42
43
 
43
44
  function validate(node) {
@@ -58,7 +59,7 @@ var _default = (0, _utils2.createRule)({
58
59
 
59
60
  return {
60
61
  CallExpression(node) {
61
- if ((0, _utils2.isTestCaseCall)(node)) {
62
+ if ((0, _utils2.isTestCaseCall)(node, scope)) {
62
63
  stack.push(true);
63
64
 
64
65
  if ((0, _utils2.getNodeName)(node).endsWith('each')) {
@@ -73,7 +74,7 @@ var _default = (0, _utils2.createRule)({
73
74
 
74
75
  FunctionDeclaration(node) {
75
76
  const declaredVariables = context.getDeclaredVariables(node);
76
- const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
77
+ const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, scope);
77
78
  stack.push(testCallExpressions.length > 0);
78
79
  },
79
80
 
@@ -9,7 +9,7 @@ var _utils = require("@typescript-eslint/utils");
9
9
 
10
10
  var _utils2 = require("./utils");
11
11
 
12
- const getBlockType = statement => {
12
+ const getBlockType = (statement, scope) => {
13
13
  const func = statement.parent;
14
14
  /* istanbul ignore if */
15
15
 
@@ -30,7 +30,7 @@ const getBlockType = statement => {
30
30
  } // if it's not a variable, it will be callExpr, we only care about describe
31
31
 
32
32
 
33
- if (expr.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isDescribeCall)(expr)) {
33
+ if (expr.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isDescribeCall)(expr, scope)) {
34
34
  return 'describe';
35
35
  }
36
36
  }
@@ -69,11 +69,12 @@ var _default = (0, _utils2.createRule)({
69
69
  create(context, [{
70
70
  additionalTestBlockFunctions = []
71
71
  }]) {
72
+ const scope = context.getScope();
72
73
  const callStack = [];
73
74
 
74
75
  const isCustomTestBlockFunction = node => additionalTestBlockFunctions.includes((0, _utils2.getNodeName)(node) || '');
75
76
 
76
- const isTestBlock = node => (0, _utils2.isTestCaseCall)(node) || isCustomTestBlockFunction(node);
77
+ const isTestBlock = node => (0, _utils2.isTestCaseCall)(node, scope) || isCustomTestBlockFunction(node);
77
78
 
78
79
  return {
79
80
  CallExpression(node) {
@@ -108,7 +109,7 @@ var _default = (0, _utils2.createRule)({
108
109
  },
109
110
 
110
111
  BlockStatement(statement) {
111
- const blockType = getBlockType(statement);
112
+ const blockType = getBlockType(statement, scope);
112
113
 
113
114
  if (blockType) {
114
115
  callStack.push(blockType);
@@ -116,7 +117,7 @@ var _default = (0, _utils2.createRule)({
116
117
  },
117
118
 
118
119
  'BlockStatement:exit'(statement) {
119
- if (callStack[callStack.length - 1] === getBlockType(statement)) {
120
+ if (callStack[callStack.length - 1] === getBlockType(statement, scope)) {
120
121
  callStack.pop();
121
122
  }
122
123
  },
@@ -27,10 +27,11 @@ var _default = (0, _utils2.createRule)({
27
27
  defaultOptions: [],
28
28
 
29
29
  create(context) {
30
+ const scope = context.getScope();
30
31
  return {
31
32
  CallExpression(node) {
32
33
  const nodeName = (0, _utils2.getNodeName)(node.callee);
33
- if (!nodeName || !(0, _utils2.isDescribeCall)(node) && !(0, _utils2.isTestCaseCall)(node)) return;
34
+ if (!nodeName || !(0, _utils2.isDescribeCall)(node, scope) && !(0, _utils2.isTestCaseCall)(node, scope)) return;
34
35
  const preferredNodeName = getPreferredNodeName(nodeName);
35
36
  if (!preferredNodeName) return;
36
37
  const funcNode = node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression ? node.callee.tag : node.callee.type === _utils.AST_NODE_TYPES.CallExpression ? node.callee.callee : node.callee;
@@ -36,9 +36,10 @@ var _default = (0, _utils2.createRule)({
36
36
  defaultOptions: [],
37
37
 
38
38
  create(context) {
39
+ const scope = context.getScope();
39
40
  return {
40
41
  CallExpression(node) {
41
- if (!(0, _utils2.isTestCaseCall)(node)) return;
42
+ if (!(0, _utils2.isTestCaseCall)(node, scope)) return;
42
43
  const body = getBody(node.arguments);
43
44
  const returnStmt = body.find(t => t.type === _utils.AST_NODE_TYPES.ReturnStatement);
44
45
  if (!returnStmt) return;
@@ -50,7 +51,7 @@ var _default = (0, _utils2.createRule)({
50
51
 
51
52
  FunctionDeclaration(node) {
52
53
  const declaredVariables = context.getDeclaredVariables(node);
53
- const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables);
54
+ const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, scope);
54
55
  if (testCallExpressions.length === 0) return;
55
56
  const returnStmt = node.body.body.find(t => t.type === _utils.AST_NODE_TYPES.ReturnStatement);
56
57
  if (!returnStmt) return;