Skip to content

Commit 6276bfc

Browse files
committed
fix: replace uses of context.getScope
1 parent 5b9e846 commit 6276bfc

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

lib/node-utils/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
TSESTree,
77
} from '@typescript-eslint/utils';
88

9+
import { getScope } from '../utils';
10+
911
import {
1012
isArrayExpression,
1113
isArrowFunctionExpression,
@@ -305,7 +307,7 @@ export function getInnermostFunctionScope(
305307
asyncQueryNode: TSESTree.Identifier
306308
): InnermostFunctionScope | null {
307309
const innermostScope = ASTUtils.getInnermostScope(
308-
context.getScope(),
310+
getScope(context, asyncQueryNode),
309311
asyncQueryNode
310312
);
311313

lib/rules/no-promise-in-fire-event.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
isNewExpression,
99
isPromiseIdentifier,
1010
} from '../node-utils';
11+
import { getScope } from '../utils';
1112

1213
export const RULE_NAME = 'no-promise-in-fire-event';
1314
export type MessageIds = 'noPromiseInFireEvent';
@@ -76,7 +77,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
7677

7778
if (ASTUtils.isIdentifier(node)) {
7879
const nodeVariable = ASTUtils.findVariable(
79-
context.getScope(),
80+
getScope(context, node),
8081
node.name
8182
);
8283
if (!nodeVariable) {

lib/rules/prefer-find-by.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
isObjectPattern,
1010
isProperty,
1111
} from '../node-utils';
12-
import { getSourceCode } from '../utils';
12+
import { getScope, getSourceCode } from '../utils';
1313

1414
export const RULE_NAME = 'prefer-find-by';
1515
export type MessageIds = 'preferFindBy';
@@ -119,7 +119,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
119119
isCallExpression(node.body.callee.object.arguments[0]) &&
120120
ASTUtils.isIdentifier(node.body.callee.object.arguments[0].callee)
121121
) {
122-
return node.body.callee.object.arguments[0].callee.name;
122+
return node.body.callee.object.arguments[0].callee;
123123
}
124124

125125
if (!ASTUtils.isIdentifier(node.body.callee.property)) {
@@ -135,7 +135,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
135135
node.body.callee.object.arguments[0].callee.property
136136
)
137137
) {
138-
return node.body.callee.object.arguments[0].callee.property.name;
138+
return node.body.callee.object.arguments[0].callee.property;
139139
}
140140

141141
// expect(screen.getByText).not shape
@@ -150,7 +150,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
150150
node.body.callee.object.object.arguments[0].callee.property
151151
)
152152
) {
153-
return node.body.callee.object.object.arguments[0].callee.property.name;
153+
return node.body.callee.object.object.arguments[0].callee.property;
154154
}
155155

156156
// expect(getByText).not shape
@@ -162,10 +162,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
162162
node.body.callee.object.object.arguments[0].callee
163163
)
164164
) {
165-
return node.body.callee.object.object.arguments[0].callee.name;
165+
return node.body.callee.object.object.arguments[0].callee;
166166
}
167167

168-
return node.body.callee.property.name;
168+
return node.body.callee.property;
169169
}
170170

171171
function getWrongQueryName(node: TSESTree.ArrowFunctionExpression) {
@@ -178,7 +178,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
178178
ASTUtils.isIdentifier(node.body.callee) &&
179179
helpers.isSyncQuery(node.body.callee)
180180
) {
181-
return node.body.callee.name;
181+
return node.body.callee;
182182
}
183183

184184
return getWrongQueryNameInAssertion(node);
@@ -354,12 +354,14 @@ export default createTestingLibraryRule<Options, MessageIds>({
354354
}
355355

356356
// shape of () => screen.getByText
357-
const fullQueryMethod = getWrongQueryName(argument);
357+
const fullQueryMethodNode = getWrongQueryName(argument);
358358

359-
if (!fullQueryMethod) {
359+
if (!fullQueryMethodNode) {
360360
return;
361361
}
362362

363+
const fullQueryMethod = fullQueryMethodNode.name;
364+
363365
// if there is a second argument to AwaitExpression, it is the options
364366
const waitOptions = node.arguments[1];
365367
let waitOptionsSourceCode = '';
@@ -401,12 +403,14 @@ export default createTestingLibraryRule<Options, MessageIds>({
401403
}
402404

403405
// shape of () => getByText
404-
const fullQueryMethod = getWrongQueryName(argument);
406+
const fullQueryMethodNode = getWrongQueryName(argument);
405407

406-
if (!fullQueryMethod) {
408+
if (!fullQueryMethodNode) {
407409
return;
408410
}
409411

412+
const fullQueryMethod = fullQueryMethodNode.name;
413+
410414
const queryMethod = fullQueryMethod.split('By')[1];
411415
const queryVariant = getFindByQueryVariant(fullQueryMethod);
412416
const callArguments = getQueryArguments(argument.body);
@@ -435,7 +439,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
435439

436440
// this adds the findBy* declaration - adding it to the list of destructured variables { findBy* } = render()
437441
const definition = findRenderDefinitionDeclaration(
438-
context.getScope(),
442+
getScope(context, fullQueryMethodNode),
439443
fullQueryMethod
440444
);
441445
// I think it should always find it, otherwise code should not be valid (it'd be using undeclared variables)

0 commit comments

Comments
 (0)