Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursion in FQN resolution #3642

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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