Skip to content

Generalized no-goto-without-base into no-navigation-without-base #900

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

Merged
merged 12 commits into from
Dec 30, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(no-navigation-without-base): fixed namespace import detections
  • Loading branch information
marekdedic committed Dec 2, 2024
commit add6e9b174894e15f53da90582f68c4ece702840
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,20 @@ function extractBasePathReferences(
}
}
})) {
const variable = findVariable(context, (node as TSESTree.ImportSpecifier).local);
if (!variable) continue;
for (const reference of variable.references) {
if (reference.identifier.type === 'Identifier') set.add(reference.identifier);
if (node.type === 'ImportSpecifier') {
const variable = findVariable(context, node.local);
if (variable === null) {
continue;
}
for (const reference of variable.references) {
if (reference.identifier.type === 'Identifier') set.add(reference.identifier);
}
} else if (
node.type === 'MemberExpression' &&
node.property.type === 'Identifier' &&
node.property.name === 'base'
) {
set.add(node.property);
}
}
return set;
Expand Down Expand Up @@ -218,6 +228,8 @@ function expressionStartsWithBase(
return binaryExpressionStartsWithBase(context, url, basePathNames);
case 'Identifier':
return variableStartsWithBase(context, url, basePathNames);
case 'MemberExpression':
return memberExpressionStartsWithBase(url, basePathNames);
case 'TemplateLiteral':
return templateLiteralStartsWithBase(context, url, basePathNames);
default:
Expand All @@ -236,6 +248,13 @@ function binaryExpressionStartsWithBase(
);
}

function memberExpressionStartsWithBase(
url: TSESTree.MemberExpression,
basePathNames: Set<TSESTree.Identifier>
): boolean {
return url.property.type === 'Identifier' && basePathNames.has(url.property);
}

function variableStartsWithBase(
context: RuleContext,
url: TSESTree.Identifier,
Expand Down
Loading