Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(eslint): Fix no-abstracted-overlay-trigger rule (#17621)

Ben Bachem1ae84be0c84b
diff --git a/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.test.ts b/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.test.ts
index 8a4373ccff..1ce089de7b 100644
--- a/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.test.ts
+++ b/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.test.ts
@@ -91,6 +91,42 @@ ruleTester.run("no-abstracted-overlay-trigger", rule, {
`
import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+ export function NonInteractivePresentation({ visible }) {
+ return (
+ <DialogController>
+ {() => (
+ <div>
+ <section />
+ {visible && <aside />}
+ <Menu.Button />
+ </div>
+ )}
+ </DialogController>
+ );
+ }
+ `,
+ `
+ import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+
+ export function ComplexPresentation({ visible }) {
+ return (
+ <DialogController>
+ {() => (
+ <div>
+ {visible && <Button />}
+ <span />
+ <i />
+ <b />
+ <em />
+ </div>
+ )}
+ </DialogController>
+ );
+ }
+ `,
+ `
+ import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+
export function ControllerOnly() {
return <DialogController />;
}
@@ -129,6 +165,24 @@ ruleTester.run("no-abstracted-overlay-trigger", rule, {
);
}
`,
+ `
+ import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";
+
+ export function IntegrationForm() {
+ return (
+ <ConfirmationDialogController>
+ {({ openDialog }) => (
+ <Form>
+ <FormField><Input /></FormField>
+ <FormField><Select /></FormField>
+ <FormField><Switch /></FormField>
+ <Button onClick={openDialog}>Reset</Button>
+ </Form>
+ )}
+ </ConfirmationDialogController>
+ );
+ }
+ `,
`
import {
Dialog,
@@ -291,6 +345,42 @@ ruleTester.run("no-abstracted-overlay-trigger", rule, {
code: `
import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+ export function LinkedPrompt() {
+ return <DialogController>{() => <a href="#open">Open</a>}</DialogController>;
+ }
+ `,
+ errors: [{ messageId: "abstractedTrigger" }],
+ },
+ {
+ code: `
+ import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+
+ export function ConditionalPrompt({ visible }) {
+ return (
+ <DialogController>
+ {() => (
+ <div>{visible ? <aside /> : <Button />}</div>
+ )}
+ </DialogController>
+ );
+ }
+ `,
+ errors: [{ messageId: "abstractedTrigger" }],
+ },
+ {
+ code: `
+ import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+
+ export function InputPrompt() {
+ return <DialogController>{() => <input type="button" />}</DialogController>;
+ }
+ `,
+ errors: [{ messageId: "abstractedTrigger" }],
+ },
+ {
+ code: `
+ import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+
export function DeletePrompt() {
return (
<DialogController>
@@ -306,6 +396,27 @@ ruleTester.run("no-abstracted-overlay-trigger", rule, {
},
],
},
+ {
+ code: `
+ import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+
+ export function DeletePrompt() {
+ return (
+ <DialogController>
+ {({ openDialog }) => (
+ <div>
+ <Button onClick={openDialog}>
+ <Icon />
+ Delete
+ </Button>
+ </div>
+ )}
+ </DialogController>
+ );
+ }
+ `,
+ errors: [{ messageId: "abstractedTrigger" }],
+ },
{
code: `
import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
diff --git a/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.ts b/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.ts
index 8b9c4d4c84..028de0007d 100644
--- a/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.ts
+++ b/packages/eslint-plugin/src/rules/no-abstracted-overlay-trigger.ts
@@ -99,14 +99,82 @@ function getEffectiveRoots(node: JsxRenderableNode): TSESTree.JSXElement[] {
return child ? getEffectiveRoots(child) : [];
}
-function expressionRendersJsx(node: TSESTree.Expression): boolean {
+function expressionRendersJsx(
+ node: TSESTree.Expression,
+): node is TSESTree.JSXElement | TSESTree.JSXFragment {
return (
node.type === AST_NODE_TYPES.JSXElement ||
node.type === AST_NODE_TYPES.JSXFragment
);
}
-function controllerOwnsPresentation(node: TSESTree.JSXElement): boolean {
+const MAX_CONTROLLER_TRIGGER_ELEMENTS = 5;
+
+function countJsxElements(
+ node: TSESTree.JSXElement | TSESTree.JSXFragment,
+): number {
+ let count = node.type === AST_NODE_TYPES.JSXElement ? 1 : 0;
+
+ for (const child of node.children) {
+ if (
+ child.type === AST_NODE_TYPES.JSXElement ||
+ child.type === AST_NODE_TYPES.JSXFragment
+ ) {
+ count += countJsxElements(child);
+ continue;
+ }
+ if (
+ child.type === AST_NODE_TYPES.JSXExpressionContainer &&
+ child.expression.type !== AST_NODE_TYPES.JSXEmptyExpression
+ ) {
+ for (const root of getEffectiveRoots(child.expression)) {
+ count += countJsxElements(root);
+ }
+ }
+ }
+
+ return count;
+}
+
+function isInteractiveElement(node: TSESTree.JSXElement): boolean {
+ const name = getJsxElementName(node);
+ if (!name) return false;
+ if (name === "button" || name === "a" || name === "input") return true;
+
+ return /(Button|Trigger|Link|Item|Switch)$/.test(name);
+}
+
+function containsInteractiveElement(
+ node: TSESTree.JSXElement | TSESTree.JSXFragment,
+): boolean {
+ if (node.type === AST_NODE_TYPES.JSXElement && isInteractiveElement(node)) {
+ return true;
+ }
+
+ for (const child of node.children) {
+ if (
+ child.type === AST_NODE_TYPES.JSXElement ||
+ child.type === AST_NODE_TYPES.JSXFragment
+ ) {
+ if (containsInteractiveElement(child)) return true;
+ continue;
+ }
+ if (
+ child.type === AST_NODE_TYPES.JSXExpressionContainer &&
+ child.expression.type !== AST_NODE_TYPES.JSXEmptyExpression
+ ) {
+ if (
+ getEffectiveRoots(child.expression).some(containsInteractiveElement)
+ ) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+function controllerOwnsTriggerPresentation(node: TSESTree.JSXElement): boolean {
const child = getMeaningfulChild(node.children);
if (
child?.type !== AST_NODE_TYPES.ArrowFunctionExpression &&
@@ -115,11 +183,18 @@ function controllerOwnsPresentation(node: TSESTree.JSXElement): boolean {
return false;
}
- let ownsPresentation = false;
+ let ownsTriggerPresentation = false;
visitFunctionReturnExpressions(child, (returnExpression) => {
- if (expressionRendersJsx(returnExpression)) ownsPresentation = true;
+ if (!expressionRendersJsx(returnExpression)) return;
+
+ if (
+ countJsxElements(returnExpression) <= MAX_CONTROLLER_TRIGGER_ELEMENTS &&
+ containsInteractiveElement(returnExpression)
+ ) {
+ ownsTriggerPresentation = true;
+ }
});
- return ownsPresentation;
+ return ownsTriggerPresentation;
}
function jsxSubtreeContainsName(
@@ -218,7 +293,7 @@ const rule = createRule<Options, "abstractedTrigger">({
if (
localImports.get(`${family.module}:${family.root}`) ===
localRootName &&
- controllerOwnsPresentation(rootNode)
+ controllerOwnsTriggerPresentation(rootNode)
) {
context.report({
node: rootNode.openingElement,
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index eb652f77e2..41fbe1242c 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
import { DataTable } from "@/src/components/table/data-table";
import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
import {
diff --git a/web/src/ee/features/sso-settings/components/SSOSettings.tsx b/web/src/ee/features/sso-settings/components/SSOSettings.tsx
index d10334d9f5..8015a487a4 100644
--- a/web/src/ee/features/sso-settings/components/SSOSettings.tsx
+++ b/web/src/ee/features/sso-settings/components/SSOSettings.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
import { showErrorToast, showSuccessToast } from "@/src/features/notifications";
import { Alert } from "@/src/components/design-system/Alert/Alert";
import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";
diff --git a/web/src/features/datasets/components/DatasetRunsTable.tsx b/web/src/features/datasets/components/DatasetRunsTable.tsx
index cbd0c700a9..e62f3af029 100644
--- a/web/src/features/datasets/components/DatasetRunsTable.tsx
+++ b/web/src/features/datasets/components/DatasetRunsTable.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
import { DataTable } from "@/src/components/table/data-table";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { createDropdownTableColumn } from "@/src/components/design-system/table/columns/createDropdownTableColumn";
diff --git a/web/src/features/posthog-integration/components/PostHogIntegrationForm.tsx b/web/src/features/posthog-integration/components/PostHogIntegrationForm.tsx
index 2c7ddefb27..aa6fdb0c2d 100644
--- a/web/src/features/posthog-integration/components/PostHogIntegrationForm.tsx
+++ b/web/src/features/posthog-integration/components/PostHogIntegrationForm.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
import { zodResolver } from "@hookform/resolvers/zod";
import {
validateExportSource,
diff --git a/web/src/features/support-chat/SupportForm.tsx b/web/src/features/support-chat/SupportForm.tsx
index 4f0591330d..90db31d8ff 100644
--- a/web/src/features/support-chat/SupportForm.tsx
+++ b/web/src/features/support-chat/SupportForm.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable @repo/no-abstracted-overlay-trigger */
"use client";
import { zodResolver } from "@hookform/resolvers/zod";