Skip to content
Source
Sign inSign up

no-ambiguous-detail-navigation.ts

35 lines1.2 KB

1import { defineRule, type ESTree } from "@oxlint/plugins";
2​
3const DETAIL_ROUTES = new Set(["Thread", "PullRequest"]);
4​
5const MESSAGE =
6 "`navigate` to a Thread or PullRequest pushes or updates in place depending on what is on top. Use useSelectWorkspaceDetail to show it as the page, or StackActions.push to open it over the current one.";
7​
8function calleeName(callee: ESTree.Expression) {
9 if (callee.type === "Identifier") return callee.name;
10 if (callee.type === "MemberExpression" && callee.property.type === "Identifier") {
11 return callee.property.name;
12 }
13 return null;
15​
16export default defineRule({
17 meta: {
18 type: "problem",
19 docs: {
20 description:
21 "Disallow `navigate` to the workspace's detail routes; selections and drill-ins each have one explicit action.",
22 },
23 },
24 create(context) {
25 return {
26 CallExpression(node) {
27 if (calleeName(node.callee as ESTree.Expression) !== "navigate") return;
28 const [route] = node.arguments;
29 if (route?.type !== "Literal" || typeof route.value !== "string") return;
30 if (!DETAIL_ROUTES.has(route.value)) return;
31 context.report({ node, message: MESSAGE });
32 },
33 };
34 },
35});