Skip to content

πŸ™Œ OpenHands: AI-Driven Development

chore(lint): stage raw color warnings (#18006)

Engel Nyst8136a1d59f33
diff --git a/__tests__/scripts/raw-colors-lint.test.ts b/__tests__/scripts/raw-colors-lint.test.ts
new file mode 100644
index 0000000000..ff75fcea6c
--- /dev/null
+++ b/__tests__/scripts/raw-colors-lint.test.ts
@@ -0,0 +1,46 @@
+// @vitest-environment node
+import { ESLint } from "eslint";
+import { describe, expect, it } from "vitest";
+
+const eslint = new ESLint({
+ overrideConfig: [
+ {
+ languageOptions: { parserOptions: { project: null } },
+ rules: { "@typescript-eslint/prefer-optional-chain": "off" },
+ },
+ ],
+});
+
+const probe = `
+export function Probe() {
+ return <>
+ <div className="text-red-500" />
+ <div className="text-unregistered-color" />
+ <svg><path fill="#ec4899" /></svg>
+ <div className="text-danger bg-surface text-foreground" />
+ <div className="bg-background bg-content1 text-primary-foreground text-medium" />
+ <div className="bg-status-fail-bg text-status-fail-text text-content-muted text-modal-muted" />
+ <div className="bg-content9" />
+ </>;
+}
+`;
+
+describe("Canvas raw color rollout", () => {
+ it.each(["src/routes/color-probe.tsx", "src/ui/color-probe.tsx"])(
+ "warns on raw colors and unknown tokens while accepting verified tokens in %s",
+ async (filePath) => {
+ const [result] = await eslint.lintText(probe, { filePath });
+ expect(result.fatalErrorCount).toBe(0);
+ expect(
+ result.messages
+ .filter((message) => message.ruleId === "shadcn/no-raw-colors")
+ .map(({ line, severity }) => ({ line, severity })),
+ ).toEqual([
+ { line: 4, severity: 1 },
+ { line: 5, severity: 1 },
+ { line: 6, severity: 1 },
+ { line: 10, severity: 1 },
+ ]);
+ },
+ );
+});
diff --git a/eslint.config.js b/eslint.config.js
index ecee218641..9e52319c9b 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -400,9 +400,10 @@ export default [
// Canvas primitives use #/ui, not the plugin's default components/ui path.
// require-static-classes is enabled for those consumers; 0.2.0 still cannot
// read imported constants, so its documented narrow exceptions remain.
- // Next: audit no-raw-colors against our themes (0.2.0 fixes text/shadow token
- // false positives), then define component contracts for no-restyle and audit
- // dynamic style usage before enabling no-inline-styles.
+ // 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.
// 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 +413,25 @@ export default [
rules: {
"shadcn/no-arbitrary-values": "warn",
"shadcn/no-restyle": "off",
- "shadcn/no-raw-colors": "off",
+ "shadcn/no-raw-colors": [
+ "warn",
+ {
+ // 0.2.0 reads CSS @theme tokens, but not these JS-config/plugin tokens.
+ // Exact classes only: do not exempt raw palettes or whole namespaces.
+ allow: [
+ // hero.ts / @heroui/theme: semantic colors and the medium font size.
+ "bg-background",
+ "bg-content1",
+ "text-primary-foreground",
+ "text-medium",
+ // tailwind.config.js: existing named tokens, pending theme migration.
+ "bg-status-fail-bg",
+ "text-status-fail-text",
+ "text-content-muted",
+ "text-modal-muted",
+ ],
+ },
+ ],
"shadcn/no-inline-styles": "off",
"shadcn/require-static-classes": [
"error",