# outtrue

> Oxlint rules that keep code on the design system: tokens, props, imports and composition.
>
> Source: https://jakub.kr/outtrue. Interactive demos are only available on the page.

Oxlint rules that keep your design system clean.

Extend one of the three configs. `base` has three rules to start with, `recommended` adds the ones that need no setup and `all` turns on everything.

```json title=".oxlintrc.json"
{
  "extends": ["./node_modules/outtrue/configs/recommended.json"]
}
```

Each example below shows the code it flags, the fix and the error it prints.

## no-raw-values

Flags hardcoded **lengths** and **colors** in classes, attributes and inline styles.

```diff title="plan-card.tsx"
- <div className="rounded-xl p-[12px]">
+ <div className="rounded-xl p-3">
    <PlanName />
  </div>
```

p-[12px] hardcodes a length. 12px is p-3 on the spacing scale.

## layout-only-classname

Flags a `className` that **restyles a primitive**. It can only place it.

```diff title="pricing.tsx"
- <Button className="mt-4 rounded-full bg-blue-600">Upgrade</Button>
+ <Button className="mt-4" variant="primary">Upgrade</Button>
```

className on <Button> can only place it: margin, size, position and flex or grid placement. rounded-full, bg-blue-600 restyle the component. Use a prop, or add a variant in @/design-system/components/button.

## one-way-imports

Flags an import from a **level above**.

```diff title="components/plan-card.tsx"
- import { PLANS } from "@/app/pricing/plans";
- export default function PlanCard() {
+ export default function PlanCard({ plans }: PlanCardProps) {
```

src/components sits below src/app and can't import from it. Pass what this needs through props, or move the file up to src/app.

## no-rebuilt-primitives

Flags a raw `<button>`, `<input>` or hand-built overlay where a **primitive already exists**.

```diff title="settings.tsx"
- <button type="submit">Save</button>
+ <Button type="submit">Save</Button>
```

<button> rebuilds a primitive the design system already has. Use Button.

## index-in-sync

Flags a component **missing from the index** or an index line whose file is gone.

```diff title="design-system/INDEX.md"
  - Button: runs an action. `components/button`
  - Dialog: asks for a decision. `components/dialog`
+ - Tooltip: names a control on hover. `components/tooltip`
```

tooltip has no line in src/design-system/INDEX.md. Add one with what it is for and its import path.

## complete-composition

Flags a composable component used **without a required part**.

```diff title="faq.tsx"
  <Accordion>
    <AccordionItem>
      <AccordionTrigger>Can I cancel anytime?</AccordionTrigger>
+     <AccordionPanel>Yes, from the billing page.</AccordionPanel>
    </AccordionItem>
  </Accordion>
```

<Accordion> is missing AccordionPanel. Use every required part, as in the component's full example.

## closed-variants

Flags a `variant` or `size` prop typed as **any string**.

```diff title="button.tsx"
  interface ButtonProps {
    children: React.ReactNode;
-   variant?: string;
+   variant?: "primary" | "secondary";
  }
```

variant accepts any string or number, so nothing says which values exist. List the allowed values as a union, such as 'primary' | 'secondary'.

## semantic-tokens-only

Flags a **raw palette class** such as `text-gray-900` outside the design system.

```diff title="pricing.tsx"
- <p className="text-gray-900">Billed yearly</p>
+ <p className="text-foreground">Billed yearly</p>
```

text-gray-900 uses a raw token, which says nothing about when to use it. Use the semantic variable for this role, or add one.

## no-deprecated

Flags a **deprecated** component, prop or import path.

```diff title="pricing.tsx"
- <Button color="blue">Upgrade</Button>
+ <Button variant="primary">Upgrade</Button>
```

color on <Button> is deprecated. Use variant.

## primitive-naming

Flags a primitive **named after a page or a variant**, such as `pricing-card-pro`.

```diff title="pricing-card-pro.tsx"
- export default function PricingCardPro({ children }: Props) {
+ export default function Card({ children, tier }: Props) {
    return <div className="rounded-xl p-4">{children}</div>;
  }
```

pricing-card-pro is named after a page or a variant: pricing, pro. Name the primitive for what it is, card, and move the variant into a prop.

## prefer-shorthand

Flags `w-4 h-4`, `h-screen`, an arbitrary `z-[n]` and template-literal class strings.

```diff title="avatar.tsx"
- <span className="w-4 h-4 rounded-full" />
+ <span className="size-4 rounded-full" />
```

w-4 h-4 is a square. Use size-4.

## icon-button-label

Flags an **icon-only button** with no `aria-label`.

```diff title="row-actions.tsx"
- <Button>
+ <Button aria-label="Delete">
    <TrashIcon />
  </Button>
```

<Button> holds only an icon, so a screen reader has nothing to announce. Add an aria-label that names the action.

## no-cross-surface-imports

Flags one part of the product **importing a component from another**.

```diff title="billing/invoice.tsx"
- import PlanBadge from "@/components/settings/plan-badge";
+ import PlanBadge from "@/design-system/components/plan-badge";
```

billing imports from settings. A component two parts of the product use belongs to the design system. Move it to src/design-system/components, or pass it in through props.

## no-reach-in-selectors

Flags a class that **styles the inside of a primitive**, such as `[&_svg]:size-4`.

```diff title="row-actions.tsx"
- <Button className="[&_svg]:size-4">Delete</Button>
+ <Button size="sm">Delete</Button>
```

[&_svg]:size-4 on <Button> styles the inside of the component from outside. Add a prop or a variant in @/design-system/components/button.

## known-tokens

Flags a color step the **theme does not define**, such as `bg-gray-150`.

```diff title="divider.tsx"
- <div className="h-px bg-gray-150" />
+ <div className="h-px bg-gray-200" />
```

bg-gray-150 names a step the theme does not define, so it renders nothing. gray has 100, 200, 300, 400, 500, 600, 700, 800, 900.

## classname-passthrough

Flags a primitive that accepts `className` and **never applies it**.

```diff title="badge.tsx"
  export default function Badge({ children, className }: BadgeProps) {
-   return <span className="rounded-md px-2">{children}</span>;
+   return <span className={cn("rounded-md px-2", className)}>{children}</span>;
  }
```

className is taken from the props and never reaches an element, so placing this component from outside does nothing. Merge it into the root element's classes.

## no-important

Flags the `!` modifier.

```diff title="pricing.tsx"
- <h2 className="!mt-0">Plans</h2>
+ <h2 className="mt-0">Plans</h2>
```

!mt-0 forces a style with !important. Change the class it is fighting, or add a variant to the component.

## no-inline-style

Flags a **fixed value** in a `style` object.

```diff title="plan-card.tsx"
- <div style={{ padding: 12 }} />
+ <div className="p-3" />
```

style sets padding to a fixed value. Use a class or a token, and keep style for values computed at runtime.

## single-export-default

Flags a lone component not written as `export default function`.

```diff title="card.tsx"
- export const Card = ({ children }: CardProps) => (
-   <div className="rounded-xl p-4">{children}</div>
- );
+ export default function Card({ children }: CardProps) {
+   return <div className="rounded-xl p-4">{children}</div>;
+ }
```

Card is the only export of this file. Write it as export default function Card().
