π OpenHands: AI-Driven Development
chore(lint): protect divider and toggle appearance contracts (#18194)
Engel Nyste72c07a88147
diff --git a/__tests__/scripts/restyle-lint.test.ts b/__tests__/scripts/restyle-lint.test.tsnew file mode 100644index 0000000000..c4721a104b--- /dev/null+++ b/__tests__/scripts/restyle-lint.test.ts@@ -0,0 +1,72 @@+// @vitest-environment node+import { ESLint } from "eslint";+import { describe, expect, it } from "vitest";++// Use the shipped policy; virtual probes only opt out of type-aware parsing.+const eslint = new ESLint({+ overrideConfig: [+ {+ languageOptions: { parserOptions: { project: null } },+ rules: { "@typescript-eslint/prefer-optional-chain": "off" },+ },+ ],+});++const probe = `+import { Divider as Separator } from "#/ui/divider";+import { ToggleSwitch, ToggleSwitchVisual as Track } from "#/ui/toggle-switch";+import { ToggleSwitch as AutomationToggle } from "#/components/features/automations/toggle-switch";+import { Typography } from "#/ui/typography";+export function Probe() {+ return <>+ <Separator className="mt-2 w-full" />+ <Separator className="bg-danger" />+ <ToggleSwitch className="ml-2 opacity-50" />+ <ToggleSwitch className="bg-danger" />+ <AutomationToggle className="bg-danger" />+ <Track enabled className="opacity-50" />+ <Typography.Text className="text-danger" />+ <div className="bg-danger" />+ </>;+}+`;++describe("Canvas divider and toggle appearance contracts", () => {+ it("rejects restyling through aliases and re-exports while keeping allowed usage", async () => {+ // Layout and caller-owned wrapper opacity remain supported. Other Canvas+ // primitives and HTML are deliberately outside this first rollout.+ const [result] = await eslint.lintText(probe, {+ filePath: "src/routes/restyle-probe.tsx",+ });++ expect(result.fatalErrorCount).toBe(0);+ const findings = result.messages.filter(+ (message) => message.ruleId === "shadcn/no-restyle",+ );+ const probeLines = probe.split("\n");+ expect(+ new Set(findings.map(({ line }) => probeLines[line - 1]?.trim())),+ ).toEqual(+ new Set([+ '<Separator className="bg-danger" />',+ '<ToggleSwitch className="bg-danger" />',+ '<AutomationToggle className="bg-danger" />',+ '<Track enabled className="opacity-50" />',+ ]),+ );+ expect(findings.every(({ severity }) => severity === 2)).toBe(true);+ });++ it("allows primitive implementations to own their appearance", async () => {+ const [result] = await eslint.lintText(probe, {+ filePath: "src/ui/restyle-probe.tsx",+ });++ expect(result.fatalErrorCount).toBe(0);+ expect(+ result.messages.filter(+ (message) => message.ruleId === "shadcn/no-restyle",+ ),+ ).toEqual([]);+ });+});diff --git a/eslint.config.js b/eslint.config.jsindex 9e52319c9b..e7c9c382cd 100644--- a/eslint.config.js+++ b/eslint.config.js@@ -402,8 +402,10 @@ export default [// read imported constants, so its documented narrow exceptions remain.// no-raw-colors starts at warn while existing palette colors are migrated// and checked across themes (#18004). Keep verified plugin/config tokens exempt below.- // Next: finish that migration before promoting to error, then define component- // contracts for no-restyle and audit dynamic styles for no-inline-styles.+ // no-restyle first protects divider/toggle appearances; layout remains public,+ // and ToggleSwitch callers can dim the control for disabled/pending states.+ // Next: finish the color migration before promoting to error; define contracts+ // for the remaining UI primitives and audit dynamic styles for no-inline-styles.// 0.2.0 also improves render-prop, destructuring, barrel-export, and custom// animation recognition. Vue/Svelte support adds no new rule names or parsers// to this React project; keep this upgrade separate from rule activation.@@ -412,7 +414,24 @@ export default [plugins: { shadcn: shadcnPlugin },rules: {"shadcn/no-arbitrary-values": "warn",- "shadcn/no-restyle": "off",+ "shadcn/no-restyle": [+ "error",+ {+ // Adopt only primitives whose appearance contract is already settled.+ // Typography, menus, Pre, and caret slots need a separate design audit.+ componentImports: [+ "^#/ui/(divider|toggle-switch)$",+ // 0.2.0 needs the existing re-export path matched explicitly too.+ "^#/components/features/automations/toggle-switch$",+ ],+ allow: ["layout"],+ contracts: [+ // The button wrapper can express caller-owned disabled/pending state.+ // ToggleSwitchVisual still owns the track/thumb color, shape, and effects.+ { pattern: "^ToggleSwitch$", allow: ["layout", "opacity"] },+ ],+ },+ ],"shadcn/no-raw-colors": ["warn",{@@ -451,9 +470,12 @@ export default [},},{- // Primitive implementations own variant helpers that this rule cannot- // resolve. Token and unknown-class checks still apply to their definitions.+ // Primitive implementations own appearance and variant helpers. Token and+ // unknown-class checks still apply to their definitions.files: ["src/ui/**/*.{ts,tsx}"],- rules: { "shadcn/require-static-classes": "off" },+ rules: {+ "shadcn/no-restyle": "off",+ "shadcn/require-static-classes": "off",+ },},];