eslint-plugin-jest 26.3.0 → 26.4.2

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.
@@ -51,19 +51,20 @@ var _default = (0, _utils2.createRule)({
51
51
  return {
52
52
  CallExpression(node) {
53
53
  const scope = context.getScope();
54
- const nodeName = (0, _utils2.getNodeName)(node.callee);
54
+ const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
55
55
 
56
- if (!nodeName) {
56
+ if (!jestFnCall) {
57
57
  return;
58
58
  }
59
59
 
60
- if ((0, _utils2.isDescribeCall)(node, scope)) {
60
+ if (jestFnCall.type === 'describe') {
61
61
  describeNestingLevel++;
62
+ return;
62
63
  }
63
64
 
64
65
  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;
65
66
 
66
- if ((0, _utils2.isTestCaseCall)(node, scope) && describeNestingLevel === 0 && !nodeName.includes(testKeyword)) {
67
+ if (jestFnCall.type === 'test' && describeNestingLevel === 0 && !jestFnCall.name.endsWith(testKeyword)) {
67
68
  const oppositeTestKeyword = getOppositeTestKeyword(testKeyword);
68
69
  context.report({
69
70
  messageId: 'consistentMethod',
@@ -72,11 +73,11 @@ var _default = (0, _utils2.createRule)({
72
73
  testKeyword,
73
74
  oppositeTestKeyword
74
75
  },
75
- fix: buildFixer(funcNode, nodeName, testKeyword)
76
+ fix: buildFixer(funcNode, jestFnCall.name, testKeyword)
76
77
  });
77
78
  }
78
79
 
79
- if ((0, _utils2.isTestCaseCall)(node, scope) && describeNestingLevel > 0 && !nodeName.includes(testKeywordWithinDescribe)) {
80
+ if (jestFnCall.type === 'test' && describeNestingLevel > 0 && !jestFnCall.name.endsWith(testKeywordWithinDescribe)) {
80
81
  const oppositeTestKeyword = getOppositeTestKeyword(testKeywordWithinDescribe);
81
82
  context.report({
82
83
  messageId: 'consistentMethodWithinDescribe',
@@ -85,13 +86,13 @@ var _default = (0, _utils2.createRule)({
85
86
  testKeywordWithinDescribe,
86
87
  oppositeTestKeyword
87
88
  },
88
- fix: buildFixer(funcNode, nodeName, testKeywordWithinDescribe)
89
+ fix: buildFixer(funcNode, jestFnCall.name, testKeywordWithinDescribe)
89
90
  });
90
91
  }
91
92
  },
92
93
 
93
94
  'CallExpression:exit'(node) {
94
- if ((0, _utils2.isDescribeCall)(node, context.getScope())) {
95
+ if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
95
96
  describeNestingLevel--;
96
97
  }
97
98
  }
@@ -93,7 +93,7 @@ var _default = (0, _utils2.createRule)({
93
93
 
94
94
  const name = (_getNodeName = (0, _utils2.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 ? _getNodeName : '';
95
95
 
96
- if ((0, _utils2.isTestCaseCall)(node, context.getScope()) || additionalTestBlockFunctions.includes(name)) {
96
+ if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test']) || additionalTestBlockFunctions.includes(name)) {
97
97
  if (node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property, 'todo')) {
98
98
  return;
99
99
  }
@@ -46,7 +46,7 @@ var _default = (0, _utils2.createRule)({
46
46
  parent
47
47
  } = node;
48
48
 
49
- if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.isDescribeCall)(parent, context.getScope())) {
49
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _utils.AST_NODE_TYPES.CallExpression || !(0, _utils2.isTypeOfJestFnCall)(parent, context.getScope(), ['describe'])) {
50
50
  return;
51
51
  }
52
52
 
@@ -69,7 +69,7 @@ var _default = (0, _utils2.createRule)({
69
69
  parent
70
70
  } = node;
71
71
 
72
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isDescribeCall)(parent, context.getScope())) {
72
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(parent, context.getScope(), ['describe'])) {
73
73
  describeCallbackStack.pop();
74
74
  }
75
75
  }
@@ -47,7 +47,7 @@ var _default = (0, _utils2.createRule)({
47
47
  },
48
48
 
49
49
  CallExpression(node) {
50
- if ((0, _utils2.isTestCaseCall)(node, context.getScope())) {
50
+ if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
51
51
  inTestCase = true;
52
52
  }
53
53
 
@@ -71,7 +71,7 @@ var _default = (0, _utils2.createRule)({
71
71
  },
72
72
 
73
73
  'CallExpression:exit'(node) {
74
- if ((0, _utils2.isTestCaseCall)(node, context.getScope())) {
74
+ if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
75
75
  inTestCase = false;
76
76
  }
77
77
 
@@ -37,13 +37,13 @@ var _default = (0, _utils.createRule)({
37
37
 
38
38
  return {
39
39
  CallExpression(node) {
40
- if ((0, _utils.isTestCaseCall)(node, context.getScope())) {
40
+ if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
41
41
  inTestCase = true;
42
42
  }
43
43
  },
44
44
 
45
45
  'CallExpression:exit'(node) {
46
- if ((0, _utils.isTestCaseCall)(node, context.getScope())) {
46
+ if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
47
47
  inTestCase = false;
48
48
  }
49
49
  },
@@ -17,8 +17,6 @@ var _default = (0, _utils.createRule)({
17
17
  },
18
18
  messages: {
19
19
  missingFunction: 'Test is missing function argument',
20
- skippedTestSuite: 'Skipped test suite',
21
- skippedTest: 'Skipped test',
22
20
  pending: 'Call to pending()',
23
21
  pendingSuite: 'Call to pending() within test suite',
24
22
  pendingTest: 'Call to pending() within test',
@@ -34,51 +32,50 @@ var _default = (0, _utils.createRule)({
34
32
  let suiteDepth = 0;
35
33
  let testDepth = 0;
36
34
  return {
37
- 'CallExpression[callee.name="describe"]'() {
38
- suiteDepth++;
39
- },
40
-
41
- 'CallExpression[callee.name=/^(it|test)$/]'() {
42
- testDepth++;
43
- },
44
-
45
- 'CallExpression[callee.name=/^(it|test)$/][arguments.length<2]'(node) {
46
- context.report({
47
- messageId: 'missingFunction',
48
- node
49
- });
50
- },
51
-
52
35
  CallExpression(node) {
53
- const functionName = (0, _utils.getNodeName)(node.callee); // prevent duplicate warnings for it.each()()
36
+ const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
54
37
 
55
- if (node.callee.type === 'CallExpression') {
38
+ if (!jestFnCall) {
56
39
  return;
57
40
  }
58
41
 
59
- switch (functionName) {
60
- case 'describe.skip.each':
61
- case 'xdescribe.each':
62
- case 'describe.skip':
63
- context.report({
64
- messageId: 'skippedTestSuite',
65
- node
66
- });
67
- break;
68
-
69
- case 'it.skip':
70
- case 'it.concurrent.skip':
71
- case 'test.skip':
72
- case 'test.concurrent.skip':
73
- case 'it.skip.each':
74
- case 'test.skip.each':
75
- case 'xit.each':
76
- case 'xtest.each':
42
+ if (jestFnCall.type === 'describe') {
43
+ suiteDepth++;
44
+ }
45
+
46
+ if (jestFnCall.type === 'test') {
47
+ testDepth++;
48
+
49
+ if (node.arguments.length < 2) {
77
50
  context.report({
78
- messageId: 'skippedTest',
51
+ messageId: 'missingFunction',
79
52
  node
80
53
  });
81
- break;
54
+ }
55
+ }
56
+
57
+ if ( // the only jest functions that are with "x" are "xdescribe", "xtest", and "xit"
58
+ jestFnCall.name.startsWith('x') || jestFnCall.members.some(s => (0, _utils.getAccessorValue)(s) === 'skip')) {
59
+ context.report({
60
+ messageId: jestFnCall.type === 'describe' ? 'disabledSuite' : 'disabledTest',
61
+ node
62
+ });
63
+ }
64
+ },
65
+
66
+ 'CallExpression:exit'(node) {
67
+ const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
68
+
69
+ if (!jestFnCall) {
70
+ return;
71
+ }
72
+
73
+ if (jestFnCall.type === 'describe') {
74
+ suiteDepth--;
75
+ }
76
+
77
+ if (jestFnCall.type === 'test') {
78
+ testDepth--;
82
79
  }
83
80
  },
84
81
 
@@ -103,28 +100,6 @@ var _default = (0, _utils.createRule)({
103
100
  node
104
101
  });
105
102
  }
106
- },
107
-
108
- 'CallExpression[callee.name="xdescribe"]'(node) {
109
- context.report({
110
- messageId: 'disabledSuite',
111
- node
112
- });
113
- },
114
-
115
- 'CallExpression[callee.name=/^(xit|xtest)$/]'(node) {
116
- context.report({
117
- messageId: 'disabledTest',
118
- node
119
- });
120
- },
121
-
122
- 'CallExpression[callee.name="describe"]:exit'() {
123
- suiteDepth--;
124
- },
125
-
126
- 'CallExpression[callee.name=/^(it|test)$/]:exit'() {
127
- testDepth--;
128
103
  }
129
104
 
130
105
  };
@@ -14,11 +14,13 @@ const findCallbackArg = (node, isJestEach, scope) => {
14
14
  return node.arguments[1];
15
15
  }
16
16
 
17
- if ((0, _utils2.isHookCall)(node, scope) && node.arguments.length >= 1) {
17
+ const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
18
+
19
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'hook' && node.arguments.length >= 1) {
18
20
  return node.arguments[0];
19
21
  }
20
22
 
21
- if ((0, _utils2.isTestCaseCall)(node, scope) && node.arguments.length >= 2) {
23
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'test' && node.arguments.length >= 2) {
22
24
  return node.arguments[1];
23
25
  }
24
26
 
@@ -7,13 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("./utils");
9
9
 
10
- const newHookContext = () => ({
11
- beforeAll: 0,
12
- beforeEach: 0,
13
- afterAll: 0,
14
- afterEach: 0
15
- });
16
-
17
10
  var _default = (0, _utils.createRule)({
18
11
  name: __filename,
19
12
  meta: {
@@ -31,33 +24,39 @@ var _default = (0, _utils.createRule)({
31
24
  defaultOptions: [],
32
25
 
33
26
  create(context) {
34
- const hookContexts = [newHookContext()];
27
+ const hookContexts = [{}];
35
28
  return {
36
29
  CallExpression(node) {
30
+ var _jestFnCall$name;
31
+
37
32
  const scope = context.getScope();
33
+ const jestFnCall = (0, _utils.parseJestFnCall)(node, scope);
34
+
35
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'describe') {
36
+ hookContexts.push({});
37
+ }
38
38
 
39
- if ((0, _utils.isDescribeCall)(node, scope)) {
40
- hookContexts.push(newHookContext());
39
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'hook') {
40
+ return;
41
41
  }
42
42
 
43
- if ((0, _utils.isHookCall)(node, scope)) {
44
- const currentLayer = hookContexts[hookContexts.length - 1];
45
- currentLayer[node.callee.name] += 1;
43
+ const currentLayer = hookContexts[hookContexts.length - 1];
44
+ currentLayer[_jestFnCall$name = jestFnCall.name] || (currentLayer[_jestFnCall$name] = 0);
45
+ currentLayer[jestFnCall.name] += 1;
46
46
 
47
- if (currentLayer[node.callee.name] > 1) {
48
- context.report({
49
- messageId: 'noDuplicateHook',
50
- data: {
51
- hook: node.callee.name
52
- },
53
- node
54
- });
55
- }
47
+ if (currentLayer[jestFnCall.name] > 1) {
48
+ context.report({
49
+ messageId: 'noDuplicateHook',
50
+ data: {
51
+ hook: jestFnCall.name
52
+ },
53
+ node
54
+ });
56
55
  }
57
56
  },
58
57
 
59
58
  'CallExpression:exit'(node) {
60
- if ((0, _utils.isDescribeCall)(node, context.getScope())) {
59
+ if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
61
60
  hookContexts.pop();
62
61
  }
63
62
  }
@@ -41,7 +41,7 @@ var _default = (0, _utils2.createRule)({
41
41
  },
42
42
 
43
43
  CallExpression(node) {
44
- if ((0, _utils2.isTestCaseCall)(node, context.getScope())) {
44
+ if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
45
45
  hasTestCase = true;
46
46
  }
47
47
  },
@@ -9,24 +9,6 @@ var _utils = require("@typescript-eslint/utils");
9
9
 
10
10
  var _utils2 = require("./utils");
11
11
 
12
- const findOnlyNode = node => {
13
- 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;
14
-
15
- if (callee.type === _utils.AST_NODE_TYPES.MemberExpression) {
16
- if (callee.object.type === _utils.AST_NODE_TYPES.MemberExpression) {
17
- if ((0, _utils2.isSupportedAccessor)(callee.object.property, 'only')) {
18
- return callee.object.property;
19
- }
20
- }
21
-
22
- if ((0, _utils2.isSupportedAccessor)(callee.property, 'only')) {
23
- return callee.property;
24
- }
25
- }
26
-
27
- return null;
28
- };
29
-
30
12
  var _default = (0, _utils2.createRule)({
31
13
  name: __filename,
32
14
  meta: {
@@ -50,24 +32,34 @@ var _default = (0, _utils2.createRule)({
50
32
  return {
51
33
  CallExpression(node) {
52
34
  const scope = context.getScope();
35
+ const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
53
36
 
54
- if (!(0, _utils2.isDescribeCall)(node, scope) && !(0, _utils2.isTestCaseCall)(node, scope)) {
37
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test' && (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe') {
55
38
  return;
56
39
  }
57
40
 
58
- if ((0, _utils2.getNodeName)(node).startsWith('f')) {
41
+ if (jestFnCall.name.startsWith('f')) {
59
42
  context.report({
60
43
  messageId: 'focusedTest',
61
44
  node,
62
45
  suggest: [{
63
46
  messageId: 'suggestRemoveFocus',
64
- fix: fixer => fixer.removeRange([node.range[0], node.range[0] + 1])
47
+
48
+ fix(fixer) {
49
+ // don't apply the fixer if we're an aliased import
50
+ if (jestFnCall.head.type === 'import' && jestFnCall.name !== jestFnCall.head.local) {
51
+ return null;
52
+ }
53
+
54
+ return fixer.removeRange([node.range[0], node.range[0] + 1]);
55
+ }
56
+
65
57
  }]
66
58
  });
67
59
  return;
68
60
  }
69
61
 
70
- const onlyNode = findOnlyNode(node);
62
+ const onlyNode = jestFnCall.members.find(s => (0, _utils2.getAccessorValue)(s) === 'only');
71
63
 
72
64
  if (!onlyNode) {
73
65
  return;
@@ -39,12 +39,14 @@ var _default = (0, _utils.createRule)({
39
39
  }]) {
40
40
  return {
41
41
  CallExpression(node) {
42
- if ((0, _utils.isHookCall)(node, context.getScope()) && !allow.includes(node.callee.name)) {
42
+ const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
43
+
44
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'hook' && !allow.includes(jestFnCall.name)) {
43
45
  context.report({
44
46
  node,
45
47
  messageId: 'unexpectedHook',
46
48
  data: {
47
- hookName: node.callee.name
49
+ hookName: jestFnCall.name
48
50
  }
49
51
  });
50
52
  }
@@ -33,16 +33,19 @@ var _default = (0, _utils.createRule)({
33
33
  const contexts = [newDescribeContext()];
34
34
  return {
35
35
  CallExpression(node) {
36
- var _getNodeName;
37
-
38
36
  const scope = context.getScope();
39
37
  const currentLayer = contexts[contexts.length - 1];
38
+ const jestFnCall = (0, _utils.parseJestFnCall)(node, scope);
39
+
40
+ if (!jestFnCall) {
41
+ return;
42
+ }
40
43
 
41
- if ((0, _utils.isDescribeCall)(node, scope)) {
44
+ if (jestFnCall.type === 'describe') {
42
45
  contexts.push(newDescribeContext());
43
46
  }
44
47
 
45
- if ((_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 && _getNodeName.endsWith('.each')) {
48
+ if (jestFnCall.members.find(s => (0, _utils.isSupportedAccessor)(s, 'each'))) {
46
49
  return;
47
50
  }
48
51
 
@@ -54,7 +57,7 @@ var _default = (0, _utils.createRule)({
54
57
 
55
58
  const title = (0, _utils.getStringValue)(argument);
56
59
 
57
- if ((0, _utils.isTestCaseCall)(node, scope)) {
60
+ if (jestFnCall.type === 'test') {
58
61
  if (currentLayer.testTitles.includes(title)) {
59
62
  context.report({
60
63
  messageId: 'multipleTestTitle',
@@ -65,7 +68,7 @@ var _default = (0, _utils.createRule)({
65
68
  currentLayer.testTitles.push(title);
66
69
  }
67
70
 
68
- if (!(0, _utils.isDescribeCall)(node, scope)) {
71
+ if (jestFnCall.type !== 'describe') {
69
72
  return;
70
73
  }
71
74
 
@@ -80,7 +83,7 @@ var _default = (0, _utils.createRule)({
80
83
  },
81
84
 
82
85
  'CallExpression:exit'(node) {
83
- if ((0, _utils.isDescribeCall)(node, context.getScope())) {
86
+ if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['describe'])) {
84
87
  contexts.pop();
85
88
  }
86
89
  }
@@ -9,7 +9,7 @@ var _utils = require("@typescript-eslint/utils");
9
9
 
10
10
  var _utils2 = require("./utils");
11
11
 
12
- const testCaseNames = new Set([...Object.keys(_utils2.TestCaseName), 'it.only', 'it.concurrent.only', 'it.skip', 'it.concurrent.skip', 'test.only', 'test.concurrent.only', 'test.skip', 'test.concurrent.skip', 'fit.concurrent']);
12
+ const testCaseNames = new Set([...Object.keys(_utils2.TestCaseName), 'it.only', 'it.only', 'it.skip', 'it.skip', 'test.only', 'test.only', 'test.skip', 'test.skip', 'fit.concurrent']);
13
13
 
14
14
  const isTestFunctionExpression = node => node.parent !== undefined && node.parent.type === _utils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils2.getNodeName)(node.parent.callee));
15
15
 
@@ -58,10 +58,12 @@ var _default = (0, _utils2.createRule)({
58
58
 
59
59
  return {
60
60
  CallExpression(node) {
61
- if ((0, _utils2.isTestCaseCall)(node, context.getScope())) {
61
+ const jestFnCall = (0, _utils2.parseJestFnCall)(node, context.getScope());
62
+
63
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'test') {
62
64
  stack.push(true);
63
65
 
64
- if ((0, _utils2.getNodeName)(node).endsWith('each')) {
66
+ if (jestFnCall.members.some(s => (0, _utils2.getAccessorValue)(s) === 'each')) {
65
67
  stack.push(true);
66
68
  }
67
69
  }
@@ -30,7 +30,7 @@ const getBlockType = (statement, scope) => {
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, scope)) {
33
+ if (expr.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isTypeOfJestFnCall)(expr, scope, ['describe'])) {
34
34
  return 'describe';
35
35
  }
36
36
  }
@@ -73,7 +73,7 @@ var _default = (0, _utils2.createRule)({
73
73
 
74
74
  const isCustomTestBlockFunction = node => additionalTestBlockFunctions.includes((0, _utils2.getNodeName)(node) || '');
75
75
 
76
- const isTestBlock = node => (0, _utils2.isTestCaseCall)(node, context.getScope()) || isCustomTestBlockFunction(node);
76
+ const isTestBlock = node => (0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test']) || isCustomTestBlockFunction(node);
77
77
 
78
78
  return {
79
79
  CallExpression(node) {
@@ -30,10 +30,17 @@ var _default = (0, _utils2.createRule)({
30
30
  return {
31
31
  CallExpression(node) {
32
32
  const scope = context.getScope();
33
- const nodeName = (0, _utils2.getNodeName)(node.callee);
34
- if (!nodeName || !(0, _utils2.isDescribeCall)(node, scope) && !(0, _utils2.isTestCaseCall)(node, scope)) return;
35
- const preferredNodeName = getPreferredNodeName(nodeName);
36
- if (!preferredNodeName) return;
33
+ const jestFnCall = (0, _utils2.parseJestFnCall)(node, scope);
34
+
35
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe' && (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test') {
36
+ return;
37
+ }
38
+
39
+ if (jestFnCall.name[0] !== 'f' && jestFnCall.name[0] !== 'x') {
40
+ return;
41
+ }
42
+
43
+ const preferredNodeName = [jestFnCall.name.slice(1), jestFnCall.name[0] === 'f' ? 'only' : 'skip', ...jestFnCall.members.map(s => (0, _utils2.getAccessorValue)(s))].join('.');
37
44
  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;
38
45
  context.report({
39
46
  messageId: 'usePreferredName',
@@ -54,19 +61,4 @@ var _default = (0, _utils2.createRule)({
54
61
 
55
62
  });
56
63
 
57
- exports.default = _default;
58
-
59
- function getPreferredNodeName(nodeName) {
60
- const firstChar = nodeName.charAt(0);
61
- const suffix = nodeName.endsWith('.each') ? '.each' : '';
62
-
63
- if (firstChar === 'f') {
64
- return `${nodeName.slice(1).replace('.each', '')}.only${suffix}`;
65
- }
66
-
67
- if (firstChar === 'x') {
68
- return `${nodeName.slice(1).replace('.each', '')}.skip${suffix}`;
69
- }
70
-
71
- return null;
72
- }
64
+ exports.default = _default;
@@ -38,7 +38,10 @@ var _default = (0, _utils2.createRule)({
38
38
  create(context) {
39
39
  return {
40
40
  CallExpression(node) {
41
- if (!(0, _utils2.isTestCaseCall)(node, context.getScope())) return;
41
+ if (!(0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
42
+ return;
43
+ }
44
+
42
45
  const body = getBody(node.arguments);
43
46
  const returnStmt = body.find(t => t.type === _utils.AST_NODE_TYPES.ReturnStatement);
44
47
  if (!returnStmt) return;
@@ -116,7 +116,7 @@ var _default = (0, _utils2.createRule)({
116
116
  'ForOfStatement:exit': exitForLoop,
117
117
 
118
118
  CallExpression(node) {
119
- if ((0, _utils2.isTestCaseCall)(node, context.getScope())) {
119
+ if ((0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
120
120
  inTestCaseCall = true;
121
121
  return;
122
122
  }
@@ -133,7 +133,7 @@ var _default = (0, _utils2.createRule)({
133
133
  },
134
134
 
135
135
  'CallExpression:exit'(node) {
136
- if (!(0, _utils2.isTestCaseCall)(node, context.getScope())) {
136
+ if (!(0, _utils2.isTypeOfJestFnCall)(node, context.getScope(), ['test'])) {
137
137
  return;
138
138
  }
139
139
 
@@ -35,14 +35,16 @@ var _default = (0, _utils.createRule)({
35
35
  return;
36
36
  }
37
37
 
38
- if (!(0, _utils.isHookCall)(node, context.getScope())) {
38
+ const jestFnCall = (0, _utils.parseJestFnCall)(node, context.getScope());
39
+
40
+ if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'hook') {
39
41
  // Reset the previousHookIndex when encountering something different from a hook
40
42
  previousHookIndex = -1;
41
43
  return;
42
44
  }
43
45
 
44
46
  inHook = true;
45
- const currentHook = node.callee.name;
47
+ const currentHook = jestFnCall.name;
46
48
  const currentHookIndex = HooksOrder.indexOf(currentHook);
47
49
 
48
50
  if (currentHookIndex < previousHookIndex) {
@@ -61,7 +63,7 @@ var _default = (0, _utils.createRule)({
61
63
  },
62
64
 
63
65
  'CallExpression:exit'(node) {
64
- if ((0, _utils.isHookCall)(node, context.getScope())) {
66
+ if ((0, _utils.isTypeOfJestFnCall)(node, context.getScope(), ['hook'])) {
65
67
  inHook = false;
66
68
  return;
67
69
  }
@@ -29,11 +29,11 @@ var _default = (0, _utils.createRule)({
29
29
  CallExpression(node) {
30
30
  const scope = context.getScope();
31
31
 
32
- if (!(0, _utils.isHookCall)(node, scope) && (0, _utils.isTestCaseCall)(node, scope)) {
32
+ if ((0, _utils.isTypeOfJestFnCall)(node, scope, ['test'])) {
33
33
  hooksContext[hooksContext.length - 1] = true;
34
34
  }
35
35
 
36
- if (hooksContext[hooksContext.length - 1] && (0, _utils.isHookCall)(node, scope)) {
36
+ if (hooksContext[hooksContext.length - 1] && (0, _utils.isTypeOfJestFnCall)(node, scope, ['hook'])) {
37
37
  context.report({
38
38
  messageId: 'noHookOnTop',
39
39
  node