Skip to content

Commit

Permalink
Fix recursion in FQN resolution (#3642)
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-diez-sonarsource authored Jan 11, 2023
1 parent 85f3f16 commit e589356
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions eslint-bridge/src/linting/eslint/rules/helpers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Rule, Scope } from 'eslint';
import * as estree from 'estree';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { Node, isIdentifier, getVariableFromScope, getUniqueWriteReference } from './ast';
import Variable = Scope.Variable;

export function getImportDeclarations(context: Rule.RuleContext) {
const program = context.getSourceCode().ast;
Expand Down Expand Up @@ -122,6 +123,7 @@ export function getFullyQualifiedNameRaw(
node: estree.Node,
fqn: string[],
scope?: Scope.Scope,
visitedVars: Variable[] = [],
): string | null {
let nodeToCheck = reduceToIdentifier(node, fqn);

Expand Down Expand Up @@ -149,7 +151,7 @@ export function getFullyQualifiedNameRaw(
// ESLint marks built-in global variables with an undocumented hidden `writeable` property that should equal `false`.
// @see https://github.com/eslint/eslint/blob/6380c87c563be5dc78ce0ddd5c7409aaf71692bb/lib/linter/linter.js#L207
// @see https://github.com/eslint/eslint/blob/6380c87c563be5dc78ce0ddd5c7409aaf71692bb/lib/rules/no-global-assign.js#L81
if ((variable as any).writeable === false) {
if ((variable as any).writeable === false || visitedVars.includes(variable)) {
fqn.unshift(nodeToCheck.name);
return fqn.join('.');
}
Expand Down Expand Up @@ -195,7 +197,13 @@ export function getFullyQualifiedNameRaw(
fqn.unshift(...importedQualifiers);
return fqn.join('.');
} else {
return getFullyQualifiedNameRaw(context, nodeToCheck, fqn, variable.scope);
return getFullyQualifiedNameRaw(
context,
nodeToCheck,
fqn,
variable.scope,
visitedVars.concat(variable),
);
}
}
return null;
Expand Down

0 comments on commit e589356

Please sign in to comment.