Validator & Lint Rules
Validate DESIGN.md files either interactively in your browser using the DesignMD Pro Validator or in terminals and CI pipelines with npx @google/design.md lint.
Online Validator vs Official CLI
| Capability | DesignMD Pro Validator | @google/design.md lint CLI |
|---|---|---|
| Runs locally with no upload | Yes (client-side in browser) | Yes (local Node.js process) |
| Accepted file limit / input | .md / .markdown / .txt, max 1 MB | File path or - (stdin) |
YAML frontmatter syntax & name check | Yes | Yes |
Interleaved ```yaml blocks in body | Not parsed (top frontmatter only) | Yes |
Unresolved {token} & circular ref detection | Yes | Yes |
| Automated heuristic WCAG contrast pairs | Yes (< 3:1 error, < 4.5:1 warn) | Yes (contrast-ratio warn) |
| Section order & duplicate section checks | — | Yes (section-order, error) |
Orphaned tokens & missing-primary warnings | — | Yes |
DesignMD Pro Validator rules
1. Structural frontmatter checks (validateDesignMd)
| Code | Severity | Trigger |
|---|---|---|
empty | Error | Input contains only whitespace |
missing-frontmatter | Error | Input does not begin with a --- delimiter |
unclosed-frontmatter | Error | Opening --- has no matching \n--- closing delimiter |
invalid-yaml | Error | YAML parser fails on the frontmatter block |
frontmatter-not-mapping | Error | Frontmatter parses as a scalar or list instead of a YAML key-value object |
missing-name | Error | Required name string is absent or empty |
no-token-sections | Warning | None of colors, typography, rounded, spacing, motion, or components exist |
If any structural error above fails, parsing stops immediately and valid returns false.
2. Parser & reference checks (lintDesignMd)
| Code | Severity | Trigger |
|---|---|---|
parser-finding | Warning | Non-hex color value in colors (preserved as literal, excluded from luminance math) |
unresolved-ref | Error | {a.b.c} reference anywhere in raw frontmatter cannot be found in the resolved symbol table |
circular-ref | Error | Cycle detected in the {token} reference dependency graph (a -> b -> a) |
3. WCAG contrast checks (low-contrast)
The validator calculates WCAG relative luminance (0–1) for every valid hex color (#RGB, #RGBA, #RRGGBB, #RRGGBBAA) and evaluates two sets of pairs:
- Global color heuristics:
- Foreground keys matching
/(^|[._-])(text|foreground|fg|heading|body|link|label|title)/i - Background keys matching
/(^|[._-])(background|bg|surface|card|canvas|page|fill)/i - Every matched foreground color is paired against every matched background color (excluding self-pairs).
- Foreground keys matching
- Component color heuristics:
- Within each entry in
components, properties matching/^(color|text|textcolor|foreground)$/iare paired against properties matching/^(background|backgroundcolor|bg|surface|fill)$/i.
- Within each entry in
Contrast thresholds:
- Error (
severity: "error"): contrast ratio< 3:1(fails even large text / UI thresholds, marks document invalid) - Warning (
severity: "warning"): contrast ratio>= 3:1and< 4.5:1(below WCAG AA normal text4.5:1) - Pass: contrast ratio
>= 4.5:1(all evaluated pairs are listed worst-first in the contrast matrix)
Official @google/design.md CLI rules
Run the reference validator in any project:
npx @google/design.md lint DESIGN.mdKey CLI behaviors:
- Exit code:
0when zero errors are found,1on errors. - Output format: JSON by default (
--format json); accepts-to read from stdin. - Errors: duplicate
##sections, broken{token}references, invalid component properties, flat/grouped key collisions (e.g.colors.surfacealongsidecolors.surface.elevated). - Warnings:
missing-primary,contrast-ratio,orphaned-tokens,section-order. - Windows alias: run
npx -p @google/design.md designmd lint DESIGN.mdin PowerShell.
Next steps
- DesignMD Pro Validator — test your file interactively
- Token Naming — name colors to avoid false contrast pairing and collisions
- Complete Example — sample
DESIGN.mdthat passes with zero errors and zero warnings
Last updated on