shadcn/lint:面向智能体的 Tailwind 设计系统规则检查器
shadcn-ui 开源 lint 仓库用 TypeScript 规则把设计系统约定变成可机检约束,在 ESLint/Oxlint 上为 React、Svelte、Vue 组件输出可执行的修复建议,降低编码智能体破坏设计意图的概率。
设计系统规则如果只写在文档或提示词里,编码智能体很容易「类型过了、样式乱了」。开源仓库 shadcn-ui/lint 提供一套 agent-first 的 Tailwind 设计系统 linter:规则由团队自己写,检查器负责机器可读地指出违规,并给出可落地的修复方向。
据介绍,它不要求重写现有设计系统,但需要 Tailwind v4;不强制使用 shadcn/ui 组件库。运行面支持 ESLint 与 Oxlint,框架覆盖 React、Svelte、Vue。核心思路是:TypeScript 能挡住不存在的 prop,却解释不了「为什么 Button 可以改 margin/width,却不能改 padding」这类设计意图;lint 错误会说明组件自己管间距,应改用 size(如 sm、lg)、外边距或父级 gap,只有设计明确要求时才去改 button.tsx 增加尺寸。
可配置项包括按组件写 contract(例如 CardTitle 可改布局与排版但不能改 font-*)、用 shadcn/no-restyle 与 shadcn/no-arbitrary-value 把取值限制在主题刻度上,以及用一条提示让编码智能体阅读 SETUP 文档并完成接入。规则落在配置里,而不是散落在各次对话提示中,有利于多人、多智能体共用同一组件库时得到稳定约束。
对产品设计与前端智能化协作,这是把「设计系统」从文档推进到 可执行契约 的一步;实际效果仍取决于规则写得是否覆盖真实违规模式。
shadcn/lint agent-first design system linter
Interesting repo: shadcn-ui/lint (3250 stars).
It is an agent-first linter for Tailwind design systems. It is written in TypeScript. You write the rules. The linter checks them.
The goal is simple. Your design system rules become machine-checkable. When an agent breaks a rule, the error says what is wrong. It also suggests a fix. The fix comes from your components, your variants and your theme.
It works with your existing design system. No rewrite. It needs Tailwind v4. shadcn/ui is not required. It runs on ESLint and Oxlint. It works with React, Svelte and Vue.
Here is why it matters. A TypeScript type can block a prop. It cannot explain the design intent. The readme uses a Button that permits margin and width, but controls its own padding. TypeScript gives you TS2353: padding does not exist in type Pick. The agent learns that padding is blocked. It does not learn how to size the Button.
The linter gives the second part. The error says the Button owns its spacing. It says to use a size (sm, lg), or margin here, or gap on the parent. It says to add a size in components/ui/button.tsx only if the design calls for one. That is a fix an agent can apply.
What you can do:
- Write contracts per component. One example lets CardTitle change layout and typography, but not font-*. Another lets CardContent change layout and spacing.
- Keep values on your theme scale. Pair shadcn/no-restyle with shadcn/no-arbitrary-values set to "error".
- Set it up with one prompt to your coding agent: Read the SETUP docs and set up @shadcn/lint in this project.
The config is small. One example sets shadcn/no-restyle to "error" with layout permitted. It adds a contract for ^Button$ that lists w-full, mt-* and mb-*. That is the whole rule.
This is a good pattern for a team that runs agents on a shared component library. The rules live in config. They do not live in the agent prompt. The agent gets the same answer every time.