Skip to content

Commit 35a8acf

Browse files
authored
refactor(eslint-plugin): [no-shadow] use findVariable from utils (#3921)
1 parent 3c773e4 commit 35a8acf

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

packages/eslint-plugin/src/rules/no-shadow.ts

+4-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
ASTUtils,
23
AST_NODE_TYPES,
34
TSESLint,
45
TSESTree,
@@ -340,31 +341,6 @@ export default util.createRule<Options, MessageIds>({
340341
);
341342
}
342343

343-
/**
344-
* Finds the variable by a given name in a given scope and its upper scopes.
345-
* @param initScope A scope to start find.
346-
* @param name A variable name to find.
347-
* @returns A found variable or `null`.
348-
*/
349-
function getVariableByName(
350-
initScope: TSESLint.Scope.Scope | null,
351-
name: string,
352-
): TSESLint.Scope.Variable | null {
353-
let scope = initScope;
354-
355-
while (scope) {
356-
const variable = scope.set.get(name);
357-
358-
if (variable) {
359-
return variable;
360-
}
361-
362-
scope = scope.upper;
363-
}
364-
365-
return null;
366-
}
367-
368344
/**
369345
* Checks the current context for shadowed variables.
370346
* @param {Scope} scope Fixme
@@ -404,7 +380,9 @@ export default util.createRule<Options, MessageIds>({
404380
}
405381

406382
// Gets shadowed variable.
407-
const shadowed = getVariableByName(scope.upper, variable.name);
383+
const shadowed = scope.upper
384+
? ASTUtils.findVariable(scope.upper, variable.name)
385+
: null;
408386
if (!shadowed) {
409387
continue;
410388
}

0 commit comments

Comments
 (0)