π OpenHands: AI-Driven Development
chore(lint): require static classes on Canvas UI components (#17916)
Engel Nyst5b57272cc52b
diff --git a/__tests__/scripts/static-classes-lint.test.ts b/__tests__/scripts/static-classes-lint.test.tsnew file mode 100644index 0000000000..6b5793afa7--- /dev/null+++ b/__tests__/scripts/static-classes-lint.test.ts@@ -0,0 +1,61 @@+// @vitest-environment node+import { ESLint } from "eslint";+import { describe, expect, it } from "vitest";++// Exercise the shipped config, not a separate copy of the rule settings.+// Virtual TSX probes need syntax parsing but do not belong to tsconfig's project.+const eslint = new ESLint({+ overrideConfig: [+ {+ languageOptions: { parserOptions: { project: null } },+ rules: { "@typescript-eslint/prefer-optional-chain": "off" },+ },+ ],+});++const probe = `+import { Typography as Type } from "#/ui/typography";+import { ComboboxCaretIcon as Caret } from "#/ui/combobox-caret";+export function Probe({ color, wide, className }: { color: string; wide: boolean; className?: string }) {+ return <>+ <Type.Text className={\`text-\${color}\`} />+ <Caret className={unresolvedClasses()} />+ <Type.Text className={wide ? "w-full" : "w-auto"} />+ <Caret className={className} />+ <div className="flex-cols" />+ </>;+}+`;++describe("Canvas static class policy", () => {+ it("rejects opaque UI classes while permitting static choices and forwarding", async () => {+ const [result] = await eslint.lintText(probe, {+ filePath: "src/routes/lint-probe.tsx",+ });+ expect(result.fatalErrorCount).toBe(0);+ const findings = result.messages.filter(+ (message) => message.ruleId === "shadcn/require-static-classes",+ );+ expect(findings.map(({ line, severity }) => ({ line, severity }))).toEqual([+ { line: 6, severity: 2 },+ { line: 7, severity: 2 },+ ]);+ });++ it("exempts primitive internals but still rejects unknown utilities there", async () => {+ const [result] = await eslint.lintText(probe, {+ filePath: "src/ui/lint-probe.tsx",+ });+ expect(result.fatalErrorCount).toBe(0);+ expect(+ result.messages.filter(+ (message) => message.ruleId === "shadcn/require-static-classes",+ ),+ ).toEqual([]);+ expect(+ result.messages+ .filter((message) => message.ruleId === "shadcn/no-unknown-classes")+ .map(({ line, severity }) => ({ line, severity })),+ ).toEqual([{ line: 10, severity: 2 }]);+ });+});diff --git a/eslint.config.js b/eslint.config.jsindex 4f0f137f72..4f68d63aa1 100644--- a/eslint.config.js+++ b/eslint.config.js@@ -397,6 +397,7 @@ export default [// (raw hex, vh/vw, calc(), grid templates) with no theme-scale equivalent.// Class existence does not need component contracts. With no remaining// unknown utilities, new findings fail lint; styling policy remains opt-in.+ // Canvas primitives use #/ui, not the plugin's default components/ui path.{files: ["src/**/*.{ts,tsx}"],plugins: { shadcn: shadcnPlugin },@@ -405,7 +406,10 @@ export default ["shadcn/no-restyle": "off","shadcn/no-raw-colors": "off","shadcn/no-inline-styles": "off",- "shadcn/require-static-classes": "off",+ "shadcn/require-static-classes": [+ "error",+ { componentImports: ["^#/ui(/|$)"] },+ ],"shadcn/no-unknown-classes": ["error",{@@ -419,4 +423,10 @@ export default [],},},+ {+ // Primitive implementations own variant helpers that this rule cannot+ // resolve. Token and unknown-class checks still apply to their definitions.+ files: ["src/ui/**/*.{ts,tsx}"],+ rules: { "shadcn/require-static-classes": "off" },+ },];diff --git a/src/components/features/home/shared/toggle-button.tsx b/src/components/features/home/shared/toggle-button.tsxindex 353b638792..3c2fac99b8 100644--- a/src/components/features/home/shared/toggle-button.tsx+++ b/src/components/features/home/shared/toggle-button.tsx@@ -37,6 +37,7 @@ export function ToggleButton({type="button"aria-label={t(I18nKey.COMMON$TOGGLE_MENU)}>+ {/* eslint-disable-next-line shadcn/require-static-classes -- Forward the caller's icon slot class; the analyzer only recognizes props named className. */}<ComboboxCaretIcon className={iconClassName} /></button>);diff --git a/src/routes/agent-settings.tsx b/src/routes/agent-settings.tsxindex 917ab4484a..7986b9ac90 100644--- a/src/routes/agent-settings.tsx+++ b/src/routes/agent-settings.tsx@@ -770,6 +770,7 @@ export function AgentSettingsScreen({{subAgentsDescription ? (<Typography.ParagraphclassName={cn(+ // eslint-disable-next-line shadcn/require-static-classes -- Shared static token is linted at its definition; cross-file constants are opaque to this rule.formControlSwitchDescriptionClassName,"text-tertiary-alt text-xs leading-5",)}@@ -794,6 +795,7 @@ export function AgentSettingsScreen({{switchLlmToolDescription ? (<Typography.ParagraphclassName={cn(+ // eslint-disable-next-line shadcn/require-static-classes -- Shared static token is linted at its definition; cross-file constants are opaque to this rule.formControlSwitchDescriptionClassName,"text-tertiary-alt text-xs leading-5",)}