--- name: validating-design-tokens description: Ensures CSS and components only use approved design tokens. Use when the user asks about design system enforcement, hardcoded colors, spacing values, or wants to validate token usage across files. --- # Design System Token Validator ## When to use this skill - User asks to check for hardcoded colors or spacing - User wants to enforce design token usage - User mentions design system consistency - User asks to find `var(--token-*)` violations - User wants to prevent design debt ## Workflow - [ ] Identify design token source file - [ ] Scan target files (CSS, TSX, Vue) - [ ] Detect hardcoded values - [ ] Match violations to available tokens - [ ] Generate fix suggestions - [ ] Report violations by severity ## Instructions ### Step 1: Identify Token Source Locate design token definitions: ```bash ls src/styles/tokens.css src/tokens/*.css styles/variables.css 2>/dev/null ls src/styles/tokens.ts src/tokens/*.ts 2>/dev/null ls tokens.json style-dictionary.config.* 2>/dev/null ``` Common token file patterns: - CSS custom properties: `--color-*`, `--spacing-*`, `--font-*` - JavaScript/TypeScript objects: `tokens.colors.*`, `theme.spacing.*` - Style Dictionary output: `tokens.json` ### Step 2: Extract Available Tokens **From CSS variables:** ```bash grep -hoE 'var\(--[a-zA-Z0-9-]+' src/styles/tokens.css | sort -u ``` **Parse into categories:** | Category | Pattern | Examples | | ----------- | -------------------------------- | --------------------------------------- | | Colors | `--color-*` | `--color-primary`, `--color-text-muted` | | Spacing | `--spacing-*`, `--space-*` | `--spacing-md`, `--space-4` | | Typography | `--font-*`, `--text-*` | `--font-size-lg`, `--font-weight-bold` | | Radii | `--radius-*`, `--rounded-*` | `--radius-md`, `--rounded-lg` | | Shadows | `--shadow-*` | `--shadow-sm`, `--shadow-elevated` | | Transitions | `--transition-*`, `--duration-*` | `--transition-fast` | | Z-index | `--z-*` | `--z-modal`, `--z-tooltip` | ### Step 3: Scan for Violations **Hardcoded colors in CSS:** ```bash grep -rn --include="*.css" --include="*.scss" -E '#[0-9a-fA-F]{3,8}|rgb\(|rgba\(|hsl\(' src/ ``` **Hardcoded colors in JSX/TSX:** ```bash grep -rn --include="*.tsx" --include="*.jsx" -E "color:\s*['\"]#|background:\s*['\"]#|borderColor:\s*['\"]#" src/ ``` **Hardcoded spacing (px values):** ```bash grep -rn --include="*.css" --include="*.scss" -E ':\s*[0-9]+px' src/ | grep -v "0px\|1px" ``` **Inline styles in React:** ```bash grep -rn --include="*.tsx" --include="*.jsx" "style={{" src/ ``` **Tailwind arbitrary values (if using tokens with Tailwind):** ```bash grep -rn --include="*.tsx" --include="*.jsx" -E '\[#[0-9a-fA-F]+\]|\[[0-9]+px\]' src/ ``` ### Step 4: Categorize Violations **Severity levels:** | Severity | Description | Examples | | -------- | -------------------------------------- | ---------------------------------- | | Error | Hardcoded colors in component styles | `color: #333333` | | Error | Hardcoded spacing in layout | `padding: 24px` | | Warning | Inline styles with raw values | `style={{ margin: 10 }}` | | Warning | Magic numbers | `width: 347px` | | Info | One-off values that may be intentional | Border widths, specific dimensions | ### Step 5: Match to Available Tokens For each violation, suggest the closest token: ```markdown ## Violation Report ### src/components/Card.module.css:15 **Found**: `background-color: #f5f5f5;` **Suggestion**: `background-color: var(--color-surface);` ### src/components/Button.tsx:42 **Found**: `padding: '16px 24px'` **Suggestion**: `padding: 'var(--spacing-md) var(--spacing-lg)'` ### src/pages/Home.module.css:8 **Found**: `color: #1a1a1a;` **Suggestion**: `color: var(--color-text-primary);` ``` ### Step 6: Generate Fixes **CSS fix pattern:** ```css /* Before */ .card { background-color: #ffffff; padding: 16px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } /* After */ .card { background-color: var(--color-surface); padding: var(--spacing-md); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); } ``` **React inline style fix:** ```tsx // Before