Skip to content
ui8kitPublic

About

ui8px validates utility class maps against an 8 + 4 spacing policy

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

NPM Version NPM Type Definitions GitHub deployments Socket Badge License: MIT

UI8px CLI

ui8px is a framework-agnostic CLI for keeping utility-class projects aligned to a strict 8px design grid. It is intended for Tailwind-style workflows where classes remain explicit in source code, while a policy layer prevents drift, raw palette usage, accidental 4px layout spacing, and repeated unreviewed patterns.

Run without installing:

npx ui8px@latest lint ./...

Documentation

For a full onboarding path, read the docs:

Commands

npx ui8px init
npx ui8px init --preset go
npx ui8px lint ./...
npx ui8px lint ./... --ignore .manual .project
npx ui8px lint ./... --learn
npx ui8px validate aria ./...
npx ui8px validate grid --input class-map.json --output class-map.backlog.json
npx ui8px validate patterns ./...
npx ui8px policy review

Legacy class-map validation is still supported:

npx ui8px --design grid --input class-map.json --output class-map.backlog.json

Project Files

ui8px init creates:

.ui8px/
  policy/
    allowed.json
    denied.json
    scopes.json
    groups.json
    patterns.json
  telemetry/
  reports/

If .ui8px is missing, ui8px lint uses bundled defaults. For Go component libraries, use npx ui8px init --preset go to make ui/**, components/**, and utils/**/*.go control scope while examples and views remain strict layout scope.

ui8px reads the current working directory's .gitignore automatically during file scanning, including negation lines (!pattern) that re-include a previously ignored path. Use --ignore to add extra ignored files or folders for a single run:

npx ui8px lint ./... --ignore .manual .project snapshots
npx ui8px validate patterns ./... --ignore fixtures/reference
npx ui8px validate aria ./... --ignore .manual

Place scan paths before --ignore; every non-option value after --ignore is treated as an ignore entry.

8px Spacing Policy

Layout scope is strict 8px:

{
  "spacing": {
    "layout": ["0", "2", "4", "6", "8", "10", "12", "16", "20", "24"],
    "control": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "10", "12"]
  }
}

Examples:

  • px-2 = 8px, allowed in layout.
  • px-4 = 16px, allowed in layout.
  • px-3 = 12px, denied in layout as fine tuning.
  • px-3 is allowed in control scope for buttons, fields, badges, tabs, and other compact primitives.

Scopes are file/folder based:

{
  "defaultScope": "layout",
  "scopes": [
    {
      "name": "controls",
      "files": ["src/ui/**", "src/components/**", "ui/**", "components/**"],
      "spacing": "control"
    },
    {
      "name": "layout",
      "files": ["src/views/**", "src/pages/**", "examples/**", "internal/site/views/**"],
      "spacing": "layout"
    }
  ]
}

Linting

npx ui8px lint ./...
npx ui8px lint ./... --ignore .manual .project

Supported source types:

  • .templ and .html: static class="..." values. .html, .j2, .jinja and .twig templates (Jinja2, MiniJinja, Twig): {# comments #} are skipped; in a class value with {{ … }} / {% … %} the static text and the string literals of the expressions are linted ({{ 'p-4' if x else 'p-2' }}), variables, subscripts (p['Class']) and mapping literals are not. .templ files also go through the Go extractor, so Class: "...", cn(...) / Cn(...), and templ.Attributes{"class": "..."} are recognised.
  • .css: @apply ...; utility lists.
  • .go: static templ.Attributes{"class": "..."} style values, struct fields Class: "..." (quoted or backtick strings), utils.Cn(...) / utils.cn(...), Cn(...) / cn(...), mixed literal/dynamic cn calls, static return "..." helper strings, and const / var string declarations (including grouped const ( ... ) / var ( ... ) blocks) whose values look like utility lists.

Go examples:

return utils.Cn(base, "px-3", props.Class)
return cn("inline-flex items-center", props.Class)
return CardProps{Class: "h-8 px-3 text-sm"}
const ButtonBase = "inline-flex items-center"
var ButtonPad = `px-3 py-1`
const (
  ButtonRow = "flex items-center gap-2"
)
return "h-8 px-3 text-sm"

The extractor reads only static string literals. It does not execute Go code and ignores dynamic arguments. Each string literal argument to cn / Cn is linted as its own class list, so mutually exclusive conditional branches do not report a false UI8PX004 conflict.

Checked files is the number of supported source files scanned, including files that contained no class lists.

Tailwind v4 inset-ring, inset-ring-*, and inset-shadow-* are ring/shadow utilities, not positional inset-* spacing, so they are not checked against the spacing scale and are not grouped with inset-0. Positional inset-x-* and inset-y-* are treated as their own spacing prefixes.

By default, lint scanning skips built-in transient folders (.git, .ui8px, node_modules, dist, coverage/cache folders) and entries from the local .gitignore.

Example diagnostic:

src/views/landing.templ:24:16 UI8PX001 disallowed utility class "px-3"
Scope: layout
Reason: px-3 is not allowed in layout scope.
Suggestion: use px-2 or px-4

Error codes

Code Command Meaning Typical fix
UI8PX001 lint Spacing or size step off the scope's grid (px-3, h-3, size-3, space-y-3, ms-3, p-[13px] in layout scope) An even step (px-2, px-4), or move the class into a control
UI8PX002 lint Utility not in the allowed policy (leading-5, text-[13px], an unknown modifier) Use an allowed utility, or add it to allowed.json on purpose
UI8PX003 lint Utility explicitly denied (denied.json), with the reason and a suggestion Use the suggested utility
UI8PX004 lint Two utilities of one conflict group in one class list (p-2 p-4, text-left text-center) Keep one
UI8PX005 lint Unknown ui-* semantic class (not in patterns.json) Register the pattern or use utilities
GRID validate grid A spacing declaration (padding, margin, gap, width, height, inset, …) that does not resolve to the scope's unit: 8px in layout, 4px in control Fix the class or the CSS value

Which codes block is the consumer's choice (a gate file such as .ui8px/gate.json); UI8Kit repos block all of UI8PX001–UI8PX005 except UI8PX004, plus GRID.

Spacing prefixes checked by UI8PX001: p* m* gap* space-x/y size w h min-/max-w/h top right bottom left start end inset* ps pe ms me. z-* is a stacking order, not spacing. Modifiers: hover focus focus-visible active disabled visited dark rtl ltr sm md lg xl 2xl group-hover.

Learn Mode

npx ui8px lint ./... --learn

Learn mode writes:

.ui8px/telemetry/observed.jsonl
.ui8px/telemetry/proposals.json

Plain lint does not mutate files. --learn records unknown, denied, and disallowed classes so a developer or LLM-assisted workflow can review recurring issues later.

Pattern Discovery

npx ui8px validate patterns ./...

This command finds repeated class-list compositions. It normalizes class order, removes internal duplicates, resolves simple conflict groups, and writes:

.ui8px/reports/patterns.json

Example:

Repeated pattern found 14 times:
  flex items-center justify-between gap-4 px-6 py-4
Suggested semantic class:
  ui-section-header

ui8px does not automatically generate @apply CSS. It reports candidates so semantic ui-* patterns can be reviewed intentionally.

ARIA Bundle Validation

npx ui8px validate aria ./...

This command scans source files for static data-ui8kit="..." hooks and common UI8Kit component calls such as @ui8layout.Shell(...), @ui.Accordion(...), and @ui.Tabs(...). It checks that the matching @ui8kit/aria pattern is included in the site bundle. It reads the generated web/static/js/manifest.json when present, otherwise it falls back to package.json ui8kit.aria.

Examples:

  • data-ui8kit="dialog" requires the dialog pattern.
  • data-ui8kit="sheet" and data-ui8kit="alertdialog" also require dialog.
  • data-ui8kit="tabs" requires tabs.
  • @ui8layout.Shell(...) requires dialog because the shell owns a mobile sheet.

Use --package <path> or --manifest <path> when the files live outside the current working directory.

Grid Validation

npx ui8px validate grid --input class-map.json --output class-map.backlog.json
npx ui8px validate grid --input dist/app.css --output grid.backlog.json   # a compiled stylesheet
npx ui8px validate grid --input class-map.json --output b.json --scope control

It resolves every spacing declaration to px (calc(var(--spacing) * N) with --spacing-base, rem with --root-font-size, var(--x, fallback) from the stylesheet's own custom properties or the fallback) and reports values off the scope's unit:

  • layout scope: multiples of 8px only;
  • control scope: multiples of 4px.

The scope of a class-map entry or a CSS rule is the first scope in scopes.json whose selectors (regular expressions) match the class or the selector, otherwise the default scope; --scope forces one. A stylesheet input walks nested rules and at-rules (@media, @layer), so the compiled Tailwind output is checked as the browser gets it, hand-written CSS values (height: var(--h-button, 40px)) included. Utilities listed in allowed.json (hairlines such as w-px, sr-only) are policy decisions and are not re-checked.

Presets And extends

A policy file can extend a bundled preset and keep only its local deltas:

{ "extends": "ui8kit", "utilities": ["aspect-3/4"] }

ui8px init --preset ui8kit writes extends-only files. The ui8kit preset is the one UI8Kit policy:

  • spacing: layout = even steps 0–160 (multiples of 8px), control = 0–16 and even steps to 160 (multiples of 4px);
  • utilities: the default allowlist plus hairlines (gap-px, gap-x-px, gap-y-px, p-px, w-px, h-px), fractions w-1/4…w-3/4, min-h-screen, aspect-4/3, aspect-21/9 and the logical text-start / text-end (without the physical text-left / text-right) and self-start / self-center / self-end / self-stretch, the keyword sizes size-full / max-w-full, and what the kit primitives draw: inset-ring in the semantic colours (border, input, ring, primary, transparent), bg-primary/90 / bg-secondary/80 (hover of the filled variants), transition-colors, list-none;
  • denied: raw palette colors, gradients, and text-left / text-right (UI8PX003, suggestion text-start / text-end: physical alignment breaks right-to-left pages). A denied utility is denied under any modifier (md:text-left), and the suggestion keeps the modifiers (md:text-start);
  • conflict groups: the defaults, textAlign with text-start / text-end.

Merge rules: spacing and scopes replace the preset's when given; utilities are added (deny one in denied.json to remove it); denied utilities, conflict groups and patterns merge by key.

Exit Codes

  • 0 — no blocking violations.
  • 1 — lint, grid, or pattern violations found.
  • 2 — invalid usage or runtime error.

Publishing

Before publishing:

npm run preflight
npm publish --access public --provenance

About

ui8px validates utility class maps against an 8 + 4 spacing policy

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages