Repository navigation
Description
Why
docs/engineering/component-layout.md (#169) says a component owns its look, its padding and its root's whole display value. The caller owns the component's margin, position, width against the parent, grid or flex item placement, and visibility, hiding only with hidden.
Nothing checks those rules yet. Component tests mustn't assert on CSS classes, as component and hook testing says, and a visual diff would catch drift without saying which rule broke. A lint rule could check them where the classes are written.
Proposal
A local oxlint JS plugin rule, beside the existing ones in scripts/lint/, that reports:
- On a component's root element: a class in a layout group the caller owns:
- margin (
m-*,mx-auto); - position (
static,relative,absolute,fixed,sticky,inset-*,top-*and the like); - width or height against the parent (
w-*,max-w-*,min-w-*,h-*); - grid or flex item placement (
col-*,row-*,self-*,justify-self-*,order-*,grow,shrink,basis-*,flex-1).
- margin (
- On a root that takes
className: aclassNamenot merged into the root last throughmergeClasses. - At a call site: a
classNamepassed to a component, or to a slot's render function, that contains adisplayvalue other thanhiddenand its responsive forms, such asflex,blockorgrid.
Classify classes with tailwind-merge's own class groups, from its default config, so the lint and the merge agree on what counts as margin or display.
Decisions to make
- What counts as a component's root: the outermost JSX element a component function returns. Fragments, conditional returns and
nullneed a decision. - Which components it applies to: every component under
app/andsrc/components/, or only those that takeclassName. Proposed: those that takeclassName, plus any root that carries a caller-owned class. - Overlays: dialogs and toasts place themselves. Exempt them by an allow comment with a reason, or by a config list. Proposed: a line-level disable with a reason, as other rules do.
- Dynamic classes: the rule can check only string literals and template literals' static parts. Proposed: skip classes it can't read, and say so in its README.
- Its contract: like the other
scripts/lint/rules, it needs a README and tests. Whether it also needs feature scenarios is tooling testing's call.
Timing
After #169 merges, since it adds the rules and mergeClasses. #172, the move to Tailwind v4, may change tailwind-merge's groups, so build against whichever version is current then.
🤖 Generated with Claude Code
Activity
Give component layout a document of its own
Give component layout a document of its own
DetweilerRyan commentedon Dec 1, 2026
Research on the decisions to make
Web research and a check against
mainfor each open decision. Each item ends with a recommendation for the owner to accept or reject.The layout rules live in Components § Layout, not in
docs/engineering/component-layout.md, which doesn't exist.Prior art
no-restylechecks classes callers pass to known components. It has anallow: ["layout"]option and reports unreadable classes through a separaterequire-static-classesrule.layout-related-propertiesis the same idea for CSS: a root rule holds no margin, position, size, z-index or flex and grid item properties.no-margin. Its UI styling standard bansclassNamewithno-classname-prop.None checks both sides, root and call site, so a local rule is justified.
What counts as a component's root
returnof a component function. Look through?:,&&and parentheses, and skipnull, strings and numbers.classNamebut returns a fragment, as check 2, since it can't mergeclassName.onCodePathStart..tsxfile is enough. eslint-plugin-react's detection shows that deeper heuristics stay imperfect.Which components it applies to
className, plus any root with a caller-owned class" reports the same roots as checking every root. State it that way.app/error.tsx's root hasmx-auto max-w-xl, and the rule as proposed reports it.page,layout,error,not-found,loading,templateandglobal-error.Overlays
Toastis affected today. Its root hasfixed bottom-4 right-4.ModalDialogisn't affected. It places itself through themodal-cardCSS class and the native<dialog>, which the rule can't see.react/forbid-component-props'allowedFor, costs more than one exemption saves.eslint-comments/require-description.app/layout.tsx:22andsrc/components/RoomEntry.tsx:37disable rules without one.Dynamic classes
mergeClasses, and both branches of?:and&&. Every dynamicclassNameonmainis one of these, or a template literal holding them.`bg-${color}`.require-static-classesisn't needed for this codebase.Its contract
readonlyandfunctionalplugins have none.RuleTestertest, a real test through.oxlintrc.json, and a property test where it pays.Classifying classes with tailwind-merge
getDefaultConfig().classGroupsholds the groups, but matching a class against them copies tailwind-merge's internal parser.twMerge. A class is in a group when a later class of that group, with the same variants, removes it.twMerge('md:-mb-4 md:m-0')dropsmd:-mb-4, so it's margin.mx-auto,md:-mb-4,sticky,top-0,w-full,max-w-prose,max-md:hiddenandinline-flexcorrectly. It toldflex(display) fromflex-1(item).hiddenis in the display group, so check 3 allows it by name.card,page-columnormodal-card, so the README should say so.🤖 Generated with Claude Code