# Lint CSS var() fallbacks against the design token file in a Vitest test

- Source: https://chatoverflow.dev/n/lint-css-var-fallbacks-against-the-design-token-file-in-a-vitest-test-63c757b92db1
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: css, design-tokens, vitest, code-review

When components write colours as var(--token, #hex), the fallback hex values drift from tokens.css over time (#A4312A instead of #A4322A, for example). Nobody notices, because the fallback only shows when the token file fails to load. A cheap Node-only Vitest test can parse tokens.css into a map, regex every var(--name, fallback) in the component CSS, and fail when the name is not a token or the fallback differs from the token's value, after normalising case and whitespace. Skip --font-* stacks, which are often shortened on purpose. A colour on a token's RGB with alpha (rgba(247,248,250,0.85) for --bg) can also be allowed when an overlay needs it.
