|
1 |
| -import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils'; |
2 | 1 | import {
|
3 |
| - AccessorNode, |
| 2 | + AST_NODE_TYPES, |
| 3 | + type TSESLint, |
| 4 | + type TSESTree, |
| 5 | +} from '@typescript-eslint/utils'; |
| 6 | +import { |
| 7 | + type AccessorNode, |
4 | 8 | DescribeAlias,
|
5 | 9 | HookName,
|
6 |
| - KnownMemberExpression, |
| 10 | + type KnownMemberExpression, |
7 | 11 | ModifierName,
|
8 | 12 | TestCaseName,
|
9 | 13 | findTopMostCallExpression,
|
@@ -238,7 +242,7 @@ const parseJestFnCallWithReasonInner = (
|
238 | 242 | return null;
|
239 | 243 | }
|
240 | 244 |
|
241 |
| - const resolved = resolveToJestFn(context, getAccessorValue(first)); |
| 245 | + const resolved = resolveToJestFn(context, first); |
242 | 246 |
|
243 | 247 | // we're not a jest function
|
244 | 248 | if (!resolved) {
|
@@ -534,9 +538,10 @@ interface ResolvedJestFn {
|
534 | 538 |
|
535 | 539 | const resolveToJestFn = (
|
536 | 540 | context: TSESLint.RuleContext<string, unknown[]>,
|
537 |
| - identifier: string, |
| 541 | + accessor: AccessorNode, |
538 | 542 | ): ResolvedJestFn | null => {
|
539 |
| - const maybeImport = resolveScope(context.getScope(), identifier); |
| 543 | + const identifier = getAccessorValue(accessor); |
| 544 | + const maybeImport = resolveScope(getScope(context, accessor), identifier); |
540 | 545 |
|
541 | 546 | // the identifier was found as a local variable or function declaration
|
542 | 547 | // meaning it's not a function from jest
|
@@ -564,3 +569,20 @@ const resolveToJestFn = (
|
564 | 569 | type: 'global',
|
565 | 570 | };
|
566 | 571 | };
|
| 572 | + |
| 573 | +/* istanbul ignore next */ |
| 574 | +const getScope = ( |
| 575 | + context: TSESLint.RuleContext<string, unknown[]>, |
| 576 | + node: TSESTree.Node, |
| 577 | +) => { |
| 578 | + const sourceCode = |
| 579 | + 'sourceCode' in context |
| 580 | + ? (context.sourceCode as TSESLint.SourceCode) |
| 581 | + : context.getSourceCode(); |
| 582 | + |
| 583 | + if ('getScope' in sourceCode) { |
| 584 | + return sourceCode.getScope(node); |
| 585 | + } |
| 586 | + |
| 587 | + return context.getScope(); |
| 588 | +}; |
0 commit comments