eslint-plugin-jest 27.6.2 → 27.6.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.
@@ -70,7 +70,7 @@ var _default = exports.default = (0, _utils2.createRule)({
70
70
  for (const node of nodes) {
71
71
  const index = node.type === _utils.AST_NODE_TYPES.CallExpression ? unchecked.indexOf(node) : -1;
72
72
  if (node.type === _utils.AST_NODE_TYPES.FunctionDeclaration) {
73
- const declaredVariables = context.getDeclaredVariables(node);
73
+ const declaredVariables = (0, _utils2.getDeclaredVariables)(context, node);
74
74
  const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
75
75
  checkCallExpressionUsed(testCallExpressions);
76
76
  }
@@ -90,7 +90,7 @@ var _default = exports.default = (0, _utils2.createRule)({
90
90
  unchecked.push(node);
91
91
  } else if (matchesAssertFunctionName(name, assertFunctionNames)) {
92
92
  // Return early in case of nested `it` statements.
93
- checkCallExpressionUsed(context.getAncestors());
93
+ checkCallExpressionUsed((0, _utils2.getAncestors)(context, node));
94
94
  }
95
95
  },
96
96
  'Program:exit'() {
@@ -24,7 +24,7 @@ var _default = exports.default = (0, _utils.createRule)({
24
24
  },
25
25
  defaultOptions: [],
26
26
  create(context) {
27
- const sourceCode = context.getSourceCode();
27
+ const sourceCode = (0, _utils.getSourceCode)(context);
28
28
  function checkNode(node) {
29
29
  if (!hasTests(node)) {
30
30
  return;
@@ -30,7 +30,7 @@ var _default = exports.default = (0, _utils2.createRule)({
30
30
  const decreaseConditionalDepth = () => inTestCase && conditionalDepth--;
31
31
  return {
32
32
  FunctionDeclaration(node) {
33
- const declaredVariables = context.getDeclaredVariables(node);
33
+ const declaredVariables = (0, _utils2.getDeclaredVariables)(context, node);
34
34
  const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
35
35
  if (testCallExpressions.length > 0) {
36
36
  inTestCase = true;
@@ -30,7 +30,6 @@ var _default = exports.default = (0, _utils.createRule)({
30
30
  let shouldEmitOrderSetTimeout = false;
31
31
  return {
32
32
  CallExpression(node) {
33
- const scope = context.getScope();
34
33
  const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
35
34
  if (!jestFnCall) {
36
35
  return;
@@ -39,7 +38,7 @@ var _default = exports.default = (0, _utils.createRule)({
39
38
  shouldEmitOrderSetTimeout = true;
40
39
  return;
41
40
  }
42
- if (!['global', 'module'].includes(scope.type)) {
41
+ if (!['global', 'module'].includes((0, _utils.getScope)(context, node).type)) {
43
42
  context.report({
44
43
  messageId: 'globalSetTimeout',
45
44
  node
@@ -68,7 +68,7 @@ var _default = exports.default = (0, _utils.createRule)({
68
68
  }
69
69
  },
70
70
  'CallExpression[callee.name="pending"]'(node) {
71
- if ((0, _utils.resolveScope)(context.getScope(), 'pending')) {
71
+ if ((0, _utils.resolveScope)((0, _utils.getScope)(context, node), 'pending')) {
72
72
  return;
73
73
  }
74
74
  if (testDepth > 0) {
@@ -83,7 +83,7 @@ var _default = exports.default = (0, _utils2.createRule)({
83
83
  body,
84
84
  params
85
85
  } = callback;
86
- const sourceCode = context.getSourceCode();
86
+ const sourceCode = (0, _utils2.getSourceCode)(context);
87
87
  const firstBodyToken = sourceCode.getFirstToken(body);
88
88
  const lastBodyToken = sourceCode.getLastToken(body);
89
89
  const [firstParam] = params;
@@ -59,7 +59,7 @@ var _default = exports.default = (0, _utils2.createRule)({
59
59
  stack.push(isTestFunctionExpression(node));
60
60
  },
61
61
  FunctionDeclaration(node) {
62
- const declaredVariables = context.getDeclaredVariables(node);
62
+ const declaredVariables = (0, _utils2.getDeclaredVariables)(context, node);
63
63
  const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
64
64
  stack.push(testCallExpressions.length > 0);
65
65
  },
@@ -37,7 +37,7 @@ var _default = exports.default = (0, _utils2.createRule)({
37
37
  return;
38
38
  }
39
39
  if (calleeName === 'spyOn' || calleeName === 'spyOnProperty' || calleeName === 'fail' || calleeName === 'pending') {
40
- if ((0, _utils2.resolveScope)(context.getScope(), calleeName)) {
40
+ if ((0, _utils2.resolveScope)((0, _utils2.getScope)(context, node), calleeName)) {
41
41
  // It's a local variable, not a jasmine global.
42
42
  return;
43
43
  }
@@ -20,7 +20,7 @@ const reportOnViolation = (context, node, {
20
20
  }
21
21
  let isAllowed = false;
22
22
  if (node.type === _utils.AST_NODE_TYPES.ExpressionStatement && 'left' in node.expression && node.expression.left.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.expression.left.property)) {
23
- const fileName = context.getFilename();
23
+ const fileName = (0, _utils2.getFilename)(context);
24
24
  const allowedSnapshotsInFile = allowedSnapshots[fileName];
25
25
  if (allowedSnapshotsInFile) {
26
26
  const snapshotName = (0, _utils2.getAccessorValue)(node.expression.left.property);
@@ -45,7 +45,7 @@ var _default = exports.default = (0, _utils2.createRule)({
45
45
  });
46
46
  },
47
47
  FunctionDeclaration(node) {
48
- const declaredVariables = context.getDeclaredVariables(node);
48
+ const declaredVariables = (0, _utils2.getDeclaredVariables)(context, node);
49
49
  const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
50
50
  if (testCallExpressions.length === 0) {
51
51
  return;
@@ -87,7 +87,7 @@ var _default = exports.default = (0, _utils2.createRule)({
87
87
  }
88
88
  context.report({
89
89
  fix(fixer) {
90
- const sourceCode = context.getSourceCode();
90
+ const sourceCode = (0, _utils2.getSourceCode)(context);
91
91
 
92
92
  // preserve the existing modifier if it's not a negation
93
93
  const modifierText = modifier && (0, _utils2.getAccessorValue)(modifier) !== 'not' ? `.${(0, _utils2.getAccessorValue)(modifier)}` : '';
@@ -55,7 +55,7 @@ var _default = exports.default = (0, _utils2.createRule)({
55
55
  // value is itself negated by the "not" modifier
56
56
  const addNotModifier = (comparison.operator === '!==' ? !matcherValue : matcherValue) === hasNot;
57
57
  const buildFixer = equalityMatcher => fixer => {
58
- const sourceCode = context.getSourceCode();
58
+ const sourceCode = (0, _utils2.getSourceCode)(context);
59
59
 
60
60
  // preserve the existing modifier if it's not a negation
61
61
  let modifierText = modifier && (0, _utils2.getAccessorValue)(modifier) !== 'not' ? `.${(0, _utils2.getAccessorValue)(modifier)}` : '';
@@ -52,7 +52,7 @@ var _default = exports.default = (0, _utils2.createRule)({
52
52
  replacement
53
53
  },
54
54
  fix(fixer) {
55
- const sourceCode = context.getSourceCode();
55
+ const sourceCode = (0, _utils2.getSourceCode)(context);
56
56
 
57
57
  // there shouldn't be more than one argument, but if there is don't try
58
58
  // fixing since we have no idea what to do with the extra arguments
@@ -35,7 +35,7 @@ const getAutoFixMockImplementation = (jestFnCall, context) => {
35
35
  return '';
36
36
  }
37
37
  const [arg] = jestFnCall.arguments;
38
- const argSource = arg && context.getSourceCode().getText(arg);
38
+ const argSource = arg && (0, _utils2.getSourceCode)(context).getText(arg);
39
39
  return argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()';
40
40
  };
41
41
  var _default = exports.default = (0, _utils2.createRule)({
@@ -60,7 +60,7 @@ var _default = exports.default = (0, _utils2.createRule)({
60
60
  const hasNot = jestFnCall.modifiers.some(nod => (0, _utils2.getAccessorValue)(nod) === 'not');
61
61
  context.report({
62
62
  fix(fixer) {
63
- const sourceCode = context.getSourceCode();
63
+ const sourceCode = (0, _utils2.getSourceCode)(context);
64
64
 
65
65
  // we need to negate the expectation if the current expected
66
66
  // value is itself negated by the "not" modifier
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getFirstMatcherArg = exports.findTopMostCallExpression = exports.createRule = exports.TestCaseName = exports.ModifierName = exports.HookName = exports.EqualityMatcher = exports.DescribeAlias = void 0;
6
+ exports.getFirstMatcherArg = exports.getFilename = exports.getDeclaredVariables = exports.getAncestors = 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.removeExtraArgumentsFixer = exports.isFunction = exports.isBooleanLiteral = exports.hasOnlyOneArgument = exports.getTestCallExpressionsFromDeclaredVariables = void 0;
8
+ exports.replaceAccessorFixer = exports.removeExtraArgumentsFixer = exports.isFunction = exports.isBooleanLiteral = exports.hasOnlyOneArgument = exports.getTestCallExpressionsFromDeclaredVariables = exports.getSourceCode = exports.getScope = void 0;
9
9
  var _path = require("path");
10
10
  var _utils = require("@typescript-eslint/utils");
11
11
  var _package = require("../../../package.json");
@@ -120,7 +120,7 @@ exports.replaceAccessorFixer = replaceAccessorFixer;
120
120
  const removeExtraArgumentsFixer = (fixer, context, func, from) => {
121
121
  const firstArg = func.arguments[from];
122
122
  const lastArg = func.arguments[func.arguments.length - 1];
123
- const sourceCode = context.getSourceCode();
123
+ const sourceCode = getSourceCode(context);
124
124
  let tokenAfterLastParam = sourceCode.getTokenAfter(lastArg);
125
125
  if (tokenAfterLastParam.value === ',') {
126
126
  tokenAfterLastParam = sourceCode.getTokenAfter(tokenAfterLastParam);
@@ -156,4 +156,46 @@ const getFirstMatcherArg = expectFnCall => {
156
156
  }
157
157
  return (0, _followTypeAssertionChain.followTypeAssertionChain)(firstArg);
158
158
  };
159
- exports.getFirstMatcherArg = getFirstMatcherArg;
159
+
160
+ /* istanbul ignore next */
161
+ exports.getFirstMatcherArg = getFirstMatcherArg;
162
+ const getFilename = context => {
163
+ return 'filename' in context ? context.filename : context.getFilename();
164
+ };
165
+
166
+ /* istanbul ignore next */
167
+ exports.getFilename = getFilename;
168
+ const getSourceCode = context => {
169
+ return 'sourceCode' in context ? context.sourceCode : context.getSourceCode();
170
+ };
171
+
172
+ /* istanbul ignore next */
173
+ exports.getSourceCode = getSourceCode;
174
+ const getScope = (context, node) => {
175
+ const sourceCode = getSourceCode(context);
176
+ if ('getScope' in sourceCode) {
177
+ return sourceCode.getScope(node);
178
+ }
179
+ return context.getScope();
180
+ };
181
+
182
+ /* istanbul ignore next */
183
+ exports.getScope = getScope;
184
+ const getAncestors = (context, node) => {
185
+ const sourceCode = getSourceCode(context);
186
+ if ('getAncestors' in sourceCode) {
187
+ return sourceCode.getAncestors(node);
188
+ }
189
+ return context.getAncestors();
190
+ };
191
+
192
+ /* istanbul ignore next */
193
+ exports.getAncestors = getAncestors;
194
+ const getDeclaredVariables = (context, node) => {
195
+ const sourceCode = getSourceCode(context);
196
+ if ('getDeclaredVariables' in sourceCode) {
197
+ return sourceCode.getDeclaredVariables(node);
198
+ }
199
+ return context.getDeclaredVariables(node);
200
+ };
201
+ exports.getDeclaredVariables = getDeclaredVariables;
@@ -96,7 +96,7 @@ const parseJestFnCallWithReasonInner = (node, context) => {
96
96
  if (node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression && lastLink !== 'each') {
97
97
  return null;
98
98
  }
99
- const resolved = resolveToJestFn(context, (0, _utils2.getAccessorValue)(first));
99
+ const resolved = resolveToJestFn(context, first);
100
100
 
101
101
  // we're not a jest function
102
102
  if (!resolved) {
@@ -303,8 +303,9 @@ const resolveScope = (scope, identifier) => {
303
303
  return null;
304
304
  };
305
305
  exports.resolveScope = resolveScope;
306
- const resolveToJestFn = (context, identifier) => {
307
- const maybeImport = resolveScope(context.getScope(), identifier);
306
+ const resolveToJestFn = (context, accessor) => {
307
+ const identifier = (0, _utils2.getAccessorValue)(accessor);
308
+ const maybeImport = resolveScope((0, _utils2.getScope)(context, accessor), identifier);
308
309
 
309
310
  // the identifier was found as a local variable or function declaration
310
311
  // meaning it's not a function from jest
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "27.6.2",
3
+ "version": "27.6.3",
4
4
  "description": "ESLint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",