🔍 Token Reviewer — CSS Compliance Skill
Đảm bảo 100% giá trị CSS đều sử dụng tokens, không hardcode. Mục tiêu: CSS luôn theme-aware, density-aware, và centrally maintained.
How to Use This Skill
This skill is organized in 3 layers:
- This file (SKILL.md) — Token hierarchy, violation summary, fix workflow, report template. Read this first.
- references/ — Deep-dive rules, scan commands, mapping tables. Read only what's relevant.
- Automated scripts — Run
lint-css.jsandverify-output.jsfor machine-checkable compliance.
Quick navigation:
- Running a review? → Quick Commands then Fix Process
- Hunting hardcoded values? → Read references/deep-scan-commands.md
- Need the token for a raw value? → Read resources/mapping-tables.md
- Understanding what's a violation? → Violation Summary then references/violation-rules.md
- Writing a compliance report? → Report Template
1. Token Hierarchy
CSS value → var(--component-token) → var(--semantic-token) → var(--primitive) → raw value
components/*.json --comp-*, --group-* --spacing-*, --color-* primitives/*.json
Why this hierarchy? Each layer serves a purpose:
- Component tokens — scoped to a specific component, swappable per variant
- Semantic tokens — theme-aware (light/dark), density-aware (compact/default)
- Primitives — base scale values, never used directly in CSS
Token Namespaces
| Prefix | Source | Prefix | Source |
|---|---|---|---|
--color-* |
primitives/color-palette + TW v4 built-in |
--spacing (base) |
TW v4 built-in |
--radius-* |
TW v4 built-in | --text-*, --font-weight-* |
TW v4 built-in |
--shadow-* |
TW v4 built-in | --duration-*, --easing-* |
shared/motion.tokens.json |
--z-index-* |
tailwind.css @theme block |
--font-mono, --font-sans |
TW v4 built-in |
Semantic Tokens (theme-aware)
- Colors:
--primary,--secondary,--destructive,--warning,--success,--info+-foreground,-muted,-muted-foregroundvariants - Base:
--background,--foreground,--border,--muted,--card,--surface,--input+ variants - State layers:
--state-layer-hover,--state-layer-focused,--state-layer-disable,--state-layer-colored-* - Density (4-tier):
--page-*,--section-*,--group-*,--comp-*(radius, margin, padding variants)
2. Violation Summary
❌ Violations — KHÔNG được phép
The core rule is simple: no raw CSS values for properties that have tokens.
| Type | Example | Token |
|---|---|---|
| Color | #ff3333, red |
var(--destructive) |
| Spacing | 16px |
calc(var(--spacing) * 4) |
| Spacing base | --spacing: 3px |
--spacing: 4px ONLY (S12 — immutable) |
| Spacing multiplier | calc(var(--spacing) * 7) |
FORBIDDEN — use ×1-6, 8, 10, 12, 16 only (S13) |
| Border-radius | 8px |
var(--comp-radius) or var(--group-radius-default) |
| Font-size | 14px |
var(--text-sm) |
| Font-weight | 600 |
var(--font-weight-semibold) |
| Transition | 0.2s ease |
var(--duration-normal-1) var(--easing-standard) |
| Z-index | 9999 |
var(--z-index-spotlight) |
📖 Full violation table with all types + rationale: references/violation-rules.md §1
✅ Exceptions — NOT violations
0— zero value- CSS keywords:
auto,none,inherit,transparent,currentColor %in layout/gradient,calc()with tokens insidecontent: '',flex: 1, grid templates,-1pxcorrections@keyframesinternals, media query breakpoints, animation100%- Demo/preview inline styles, z-index 1-10 (local stacking),
:root {}definitions
📖 Full exceptions + warnings: references/violation-rules.md §2-§3
🔴 bg/fg Pairing
Canonical source:
component-lifecycle/references/token-naming-states.md§2
Any element with background: var(--X) → color MUST be var(--X-foreground).
Why? Without pairing, theme switches (light → dark) can produce invisible text.
📖 Full mapping table: references/violation-rules.md §4
3. Validation Rules (output-specific)
These are structural errors in the token build output — different from style violations:
| ❌ ERROR | Description |
|---|---|
| Undefined var() refs | CSS uses var(--xxx) but --xxx doesn't exist |
| Duration uses px | --duration-* must use ms |
| z-index has unit | --z-index-* must be unitless |
| Unresolved JSON refs | {path.to.token} in CSS (build pipeline error) |
📖 Full rules with rationale: references/violation-rules.md §5
4. Deep Scan
Script lint-css.js may not catch all patterns. Use grep-based deep scan for comprehensive coverage:
📖 Full commands per violation type: references/deep-scan-commands.md
Quick start — most impactful scans:
## Font-weight raw numbers
grep -rn "font-weight:\s*[0-9]" showcase/style.css
## Color hex codes
grep -rn "#[0-9a-fA-F]\{3,8\}" showcase/style.css
## Fallback with raw px
grep -rn "var(--.*,\s*[0-9]" showcase/style.css
## rgba() hardcodes
grep -rn "rgba(" showcase/style.css
Specialized scans for dividers (§7) and titles (§8) are also in the reference file.
5. Fix Process
Why this order? Grouping by file minimizes I/O and review cycles. Mapping tables prevent guessing.
- Nhóm violations theo file — easier to review and batch-fix
- Tra Mapping Tables → resources/mapping-tables.md — xác định token thay thế chính xác
- Dùng
multi_replace_file_content— nhóm cùng file → 1 lần replace - Re-scan:
node design-system/scripts/pipeline/lint-css.js --all→ PHẢI đạt 0 violations - Deep scan: Run grep commands from references/deep-scan-commands.md → PHẢI 0 violations
6. Quick Commands
## Full pipeline (sync → review → verify → drift → audit)
node design-system/scripts/pipeline/run-pipeline.js --all
## Single file review
node design-system/scripts/pipeline/lint-css.js showcase/showcase-default/style.css
## Review-only step (skip sync + build)
node design-system/scripts/pipeline/run-pipeline.js --only=3
7. Compliance Report Template
Mỗi kết quả review PHẢI output theo format sau (phục vụ §4 ds-architect):
COMPLIANCE REPORT:
- File scanned : showcase/{name}/style.css
- Scan time : {timestamp}
- Total lines : {N}
VIOLATIONS:
🔴 ERRORS ({count}):
[E1] Line {N}: {property}: {hardcoded-value}
→ Fix: {property}: var(--{token-name})
🟡 WARNINGS ({count}):
[W1] Line {N}: var(--{token}, {raw-fallback})
→ Fix: var(--{token}, var(--{primitive-token}))
✅ PASSES:
- No hardcoded colors: ✅
- No hardcoded spacing: ✅ | ❌ ({count} violations)
- bg/fg pairs complete: ✅ | ❌ (missing: {list})
- All var() references defined: ✅ | ❌
VERDICT: ✅ PASS | ❌ FAIL
- Error count : {N} (must be 0 to PASS)
- Warning count : {N} (acceptable, should fix)
- bg/fg pairs : {N}/{total} complete
Nhóm violations theo loại khi có nhiều lỗi:
GROUP BY TYPE:
1. Hardcoded colors : {N} violations → lines: {list}
2. Hardcoded spacing : {N} violations → lines: {list}
3. Hardcoded radius : {N} violations → lines: {list}
4. Missing bg/fg pair : {N} violations → elements: {list}
5. Raw fallbacks : {N} violations → lines: {list}
6. Undefined var() : {N} violations → lines: {list}
PASS condition: Error count = 0. Warnings không block PASS nhưng phải có plan fix.
Anti-patterns (Quick Reference)
| ❌ Don't | ✅ Do | Why |
|---|---|---|
| Fix violations one-by-one | Batch fix by file + type | Minimizes review cycles |
| Guess the token name | Look up in mapping-tables.md | Prevents wrong substitutions |
| Skip deep scan after script | Run both automated + grep | Script misses some patterns |
| Use hardcoded fallbacks | var(--x, var(--y)) |
Keeps fallback token-aware |
| Ignore warnings | Plan fix in next sprint | Warnings become errors over time |
| Fix CSS without checking token output | Run verify-output.js last |
Catches build-level errors |
Reference Files
| File | Contents | Read when... |
|---|---|---|
| violation-rules.md | Full violation table, exceptions, warnings, bg/fg pairs, output rules | Understanding what's a violation |
| deep-scan-commands.md | Grep commands for all property types + divider + title audit | Running comprehensive manual scan |
| mapping-tables.md | Raw value → token lookup (spacing, color, typography, radius, z-index, etc.) | Converting hardcoded values to tokens |