Design system
The Design System Rule Pack (vite-doctor/design-system) checks that call sites stay inside a design system: theme colors instead of raw ones, scale values instead of arbitrary ones, classes instead of inline styles, component variants instead of restyling, and the project's components instead of raw elements. Each finding is a Doctor Diagnostic with a DS code.
| Code | Rule | Preset |
|---|---|---|
DS0001 | design-system/no-restyle | strict |
DS0002 | design-system/no-raw-colors | recommended |
DS0003 | design-system/no-arbitrary-values | recommended |
DS0004 | design-system/no-inline-styles | recommended |
DS0005 | design-system/require-static-classes | strict |
DS0006 | design-system/no-unknown-classes | strict |
DS0007 | design-system/prefer-project-component | recommended |
DS0008 | design-system/limit-per-view | recommended |
DS0009 | design-system/unreadable-contract | recommended |
The class and style Rules, DS0001 to DS0006, are covered in Classes and styles. This page covers the component Rules, DS0007 to DS0009, which read Vue single-file components.
Install and run
pnpm add -D vite-doctor
pnpm vite-doctor .
Doctor activates the recommended preset when the Project Inventory contains tailwindcss or @nuxt/ui. The strict preset adds every other Rule:
pnpm vite-doctor . --extends auto,design-system/strict
To run one Rule:
pnpm vite-doctor . --extends design-system/strict --rules design-system/no-inline-styles
Project components
design-system/prefer-project-component (DS0007) reports a raw element, such as <button>, <input>, <textarea>, or <select>, when the project has a component that replaces it. A raw element skips that component, so it can look and behave differently from every other instance: focus rings, sizes, disabled and loading states, and form field wiring drift.
DS0007 replaces the Nuxt UI Rules nuxt-ui/prefer-u-button (NUXT0013) and nuxt-ui/prefer-u-form-controls (NUXT0014). Remove both old entries from Doctor config and choose one setting for design-system/prefer-project-component. The setting applies to both buttons and form controls: "off" disables all DS0007 findings. When updating suppression IDs, narrow their scope where needed so they don't hide findings you still want. Regenerate your baseline rather than editing its Rule IDs, since the old fingerprints do not match.
<!-- Reported in a Nuxt UI app: Replace <button> with <UButton> -->
<button type="button" class="px-3 py-1" @click="save">Save</button>
Doctor learns which component replaces an element from three sources. It uses the first source that has a candidate and reports nothing when that source names two different components for the same element.
In a workspace, Doctor considers components in the consuming package and components the package imports at the call site or registers in Nuxt. Local aliases are used only in the SFC that imports them. Nuxt UI uses the registered name when Doctor can verify its origin. Without a current registry, Doctor skips the Nuxt UI suggestion if it cannot determine the prefix statically, for example when layers specify conflicting prefixes or use an alternate config location. If Nuxt route membership is unknown, such as when ignore settings may exclude a file, Doctor keeps the single-root wrapper exemption rather than assuming the file is a page.
| Source | Example | Confidence |
|---|---|---|
| A Component Contract | defineOptions({ doctor: { replaces: "button" } }) in AppButton.vue, or the contracts option | proven |
Nuxt UI, when the package depends on @nuxt/ui | <button> to UButton, text <input> to UInput, <textarea> to UTextarea, <select> to USelect | manifest-backed when the Nuxt manifest registers the component, otherwise heuristic-high |
A project SFC named Button, Input, Textarea, Select, or Label that sits in components/ui/ or whose single unconditional root is that element | shadcn-vue's components/ui/button/Button.vue | heuristic-high |
Doctor infers replacements from a project SFC when the call site's template can render it through a <script setup> import, an Options API registration, or an app registration.
The Rule skips:
- the replacing component's own file and everything in
components/ui/; - an element that is the single unconditional root of a component, such as the
<button>inLikeButton.vue; - elements with
data-doctor-ignore, a bound:is, or avue:isvalue; <button>elements with no content, such as a chart bar's hit area inside a tooltip;<input>elements whose type is bound, set by a laterv-bindspread, or not text-like;- elements with an unconditional
invisibleclass or that inherit it through native elements without a possible visibility override; - Nuxt UI text inputs and textareas with a local CSS class targeting their native
::placeholder.
When replacing a raw text input or textarea with a Nuxt UI component, pass classes that must style the native control in ui.base. If you use scoped CSS, update the selector to reach the inner control, for example with :deep().
<input> in a contract means text-like inputs: text, email, password, search, url, tel, and number.
Component Contracts
A Component Contract is what a component promises the design system. Declare it in the component's <script setup>:
<script setup lang="ts">
defineOptions({ doctor: { replaces: "button" } });
</script>
<template>
<button class="app-button"><slot /></button>
</template>
replaces takes one lowercase HTML tag or an array, such as ["input", "textarea"]. limits caps how many usages one view renders; see Limits per view. Doctor reads the contract statically, so every value must be a literal. A variable, function call, or unknown key reports design-system/unreadable-contract (DS0009) at the value Doctor cannot read, and so does a spread or computed key after doctor in the same options object, since it can replace the contract at runtime. Doctor ignores the contract until it is fixed.
For a component the project does not own, put the same object in the Rule's contracts option, keyed by the tag call sites use:
import { defineDoctorConfig } from "vite-doctor/config";
export default defineDoctorConfig({
rules: {
"design-system/prefer-project-component": ["info", { contracts: { ULink: { replaces: "a" } } }],
},
});
Nuxt apps that install the Doctor module get the doctor option typed in defineOptions(). In a Vue project, add the types to tsconfig.json:
{ "compilerOptions": { "types": ["vite-doctor/component-contract"] } }
Rules and Doctor Extensions read contracts through projectContracts() from vite-doctor/rule-packs/design-system.
Limits per view
design-system/limit-per-view (DS0008) reports a view that renders more usages of a component than its Component Contract allows. Two primary buttons on one screen compete, and the user can't tell which one moves them forward.
A component declares its limits in limits. Each limit counts the usages whose props match when, and reports when one view renders more than max. why says what goes wrong for the app's users, and fix says what to change at the extra call sites:
<script setup lang="ts">
withDefaults(defineProps<{ variant?: "primary" | "secondary" }>(), { variant: "secondary" });
defineOptions({
doctor: {
limits: [
{
when: { variant: "primary" },
max: 1,
why: "Two primary buttons compete, so users can't tell which action moves them forward.",
fix: 'Keep one primary AppButton and give the others variant="secondary".',
},
],
},
});
</script>
Two primary buttons in the same view then report:
DS0008 app/pages/settings.vue:12:6
More than 1 primary <AppButton> in the /settings view: 2 render together. Two primary buttons compete, so users can't tell which action moves them forward.
Fix: Keep one primary AppButton and give the others variant="secondary". Counted usages: app/layouts/default.vue:8:8, app/pages/settings.vue:12:6.
when maps prop names to a value or a list of values. null matches a usage that does not pass the prop, and a usage that omits the prop also matches a value equal to the component's literal default, such as "secondary" above. Omit when to count every usage. fix must add a remedy, so a limit whose fix repeats its why, or that misses max, why, or fix, reports DS0009.
Nuxt UI buttons
Doctor ships no limit for UButton: a bare <UButton> is already a solid primary button, and how many a view may hold is the app's decision. Add the limit in Doctor config, here in nuxt.config.ts:
export default defineNuxtConfig({
modules: ["@nuxt/ui", "vite-doctor/nuxt"],
doctor: {
rules: {
"design-system/limit-per-view": [
"warn",
{
contracts: {
UButton: {
limits: [
{
when: { variant: ["solid", null], color: ["primary", null] },
max: 1,
why: "Two solid primary buttons compete, so users can't tell which action moves them forward.",
fix: 'Keep one primary action and give the others variant="outline" or color="neutral".',
},
],
},
},
},
],
},
},
});
null stands for Nuxt UI's defaults, color: "primary" and variant: "solid". If app.config.ts changes ui.button.defaultVariants, list the values it sets instead of null.
What counts
A view is everything one Nuxt route renders at once: app.vue, the route's layout, its parent pages, and the page, each followed through the components they render. The layout comes from a literal definePageMeta({ layout }), otherwise default; layout: false adds none. Doctor reports at the first usage past max in document order (app, layout, parent pages, page) and lists every counted usage. Usages in a layout that every page shares report once, not once per page.
A page counts only through a reachable router outlet that Doctor can verify renders it. When two unconditional slot outlets render the same usage, both instances count and the Diagnostic shows each outlet's location.
Doctor counts a usage only when it renders every time the view does, so every report names usages that are on screen together. These do not count:
- usages with
v-if,v-else-if,v-else, orv-show, or inside an element that has one; - usages in a
v-for, which may render any number of times; - usages hidden at some screen size or for sighted users: the usage or an element around it has a
hidden,sr-only, or<variant>:hiddenclass such aslg:hidden, or a:classorv-bindspread Doctor cannot read. A header's desktophidden lg:flexnav and its mobilelg:hiddenmenu never show together; - usages inside a native
<dialog>or<details>, or an element with ahiddenorpopoverattribute, which stay closed until something opens them. The Rule also skips inline styles that could hide an element; - usages inside overlays, components whose name contains
Dialog,Modal,Drawer,Sheet,Slideover,Popover,Tooltip, orMenu, which stay closed until the user opens them; - usages inside
<Teleport>or<component :is>, and<component :is>itself; - usages in a slot the wrapping component renders conditionally, in a
v-for, or not at all, and in a named slot of a component Doctor cannot read; - usages whose
whenprops Doctor cannot read, such as:variant="tone"or av-bindspread.
The Rule stays silent for a route whose layout is computed, when <NuxtLayout> in app.vue picks the layout with name or fallback, and when the layout is chosen outside definePageMeta. A runtime reference to setPageLayout anywhere in the app silences every route, even when the function is called through an alias. An appLayout route rule silences the routes it may match when Nuxt's Doctor manifest records the rules, and every route when Doctor only sees it in nuxt.config. It also stays silent when Doctor cannot read the app's pages or layouts, and outside Nuxt: without routes, Doctor cannot tell which components render together. A Diagnostic is proven when Doctor read every wrapping component, and heuristic-high when a usage sits in the default slot of a package component, such as UCard, that Doctor assumes renders it.
In a Nuxt app, when a component declares limits and the Rule skips a route or counts it without its page, the report's status is incomplete. An evidence gap names the cause, the files, and the fix. For layout overrides, remove setPageLayout() or the appLayout route rule and select the layout with a literal definePageMeta({ layout }) instead. If the route rule came from a Doctor manifest, refresh it by running nuxt prepare with vite-doctor/nuxt. An app that explicitly disables file-based routing has no routes for this Rule to count. If Nuxt config hooks could re-enable routing, run nuxt prepare with vite-doctor/nuxt so Doctor can read the actual route list.
For a component the project does not own, pass the contract in the Rule's contracts option as above. Each design-system Rule reads its own contracts option, so a contract with both replaces and limits goes to both Rules.