From 46f1c89809caa9f0e63bae406eb3a1a4ff137816 Mon Sep 17 00:00:00 2001 From: Rafael Santana Date: Thu, 23 Sep 2021 19:06:54 -0300 Subject: [PATCH] refactor(eslint-plugin): [no-shadow] use `findVariable` from utils --- packages/eslint-plugin/src/rules/no-shadow.ts | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-shadow.ts b/packages/eslint-plugin/src/rules/no-shadow.ts index 61a34c231d0..a49afd502cf 100644 --- a/packages/eslint-plugin/src/rules/no-shadow.ts +++ b/packages/eslint-plugin/src/rules/no-shadow.ts @@ -1,4 +1,5 @@ import { + ASTUtils, AST_NODE_TYPES, TSESLint, TSESTree, @@ -340,31 +341,6 @@ export default util.createRule({ ); } - /** - * Finds the variable by a given name in a given scope and its upper scopes. - * @param initScope A scope to start find. - * @param name A variable name to find. - * @returns A found variable or `null`. - */ - function getVariableByName( - initScope: TSESLint.Scope.Scope | null, - name: string, - ): TSESLint.Scope.Variable | null { - let scope = initScope; - - while (scope) { - const variable = scope.set.get(name); - - if (variable) { - return variable; - } - - scope = scope.upper; - } - - return null; - } - /** * Checks the current context for shadowed variables. * @param {Scope} scope Fixme @@ -404,7 +380,9 @@ export default util.createRule({ } // Gets shadowed variable. - const shadowed = getVariableByName(scope.upper, variable.name); + const shadowed = scope.upper + ? ASTUtils.findVariable(scope.upper, variable.name) + : null; if (!shadowed) { continue; }