| title | Governance: Validation |
|---|---|
| description | Validation catches contract violations before they break components or build pipelines. If validation is missing, invalid references, type mismatches, and naming violations ship to production. Validation MUST check: JSON syntax (valid JSON structure). Variable structure (`$type` and `$value` present on all variables). Naming convention (dot-separated paths, lowercase, no platform prefixes). Reference resolution (all references point to existing variables). Circular references (no reference cycles). Type correctness (`$value` matches `$type` format). Mode key set checks (mode keys match within collections). Group extension (`$extends` targets exist, no circular group references). |
Validation catches contract violations before they break components or build pipelines.
If validation is missing, invalid references, type mismatches, and naming violations ship to production.
Validation MUST check:
- JSON syntax (valid JSON structure)
- Variable structure (
$typeand$valuepresent on all variables) - Naming convention (dot-separated paths, lowercase, no platform prefixes)
- Reference resolution (all references point to existing variables)
- Circular references (no reference cycles)
- Type correctness (
$valuematches$typeformat) - Mode key set checks (mode keys match within collections)
- Group extension (
$extendstargets exist, no circular group references)
- Run schema validation on JSON files.
- Run VDS checks (naming, references, mode key set).
- Block merge if any errors are found.
Use DTCG-compliant validators for format validation:
- @tokens-studio/sd-transforms: Style Dictionary transforms with DTCG support
- style-dictionary: Built-in DTCG format validation
- Custom validators using DTCG JSON Schema
Create custom scripts to check Variable Design Standard (VDS)-specific rules:
- Naming convention enforcement
- Reference resolution
- Circular reference detection
- Mode key set checks
Example validation script structure:
// Validate Variable Design Standard (VDS) JSON
function validateVariableContract(json) {
const errors = [];
// Check JSON syntax
// Check variable structure
// Check naming convention
// Check references resolve
// Check for circular references
// Check type correctness
// Check mode key sets
return errors;
}Set up CI validation to block invalid changes.
name: Validate Variables
on:
pull_request:
paths:
- "tokens/**/*.json"
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
- name: Install dependencies
run: npm install
- name: Validate variables
run: npm run validate:tokensUse pre-commit hooks to catch validation errors before commit:
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-variables
name: Validate Variable Design Standard (VDS)
entry: npm run validate:tokens
language: system
files: 'tokens/.*\.json$'A Variable Design Standard (VDS) JSON file is valid if:
- JSON parses without syntax errors
- Root is an object
- All variables have
$typeproperty - All variables have
$valueproperty - Groups do not have
$typeor$value
- All variable paths use dot-separated segments
- All segments are lowercase
- No platform prefixes (no
web-,ios-,android-) - No duplicate paths (same variable defined twice)
- All references use canonical format (
{path.to.token}) - All referenced variables exist
- No circular references detected
- Property-level references target valid properties
$typevalues match supported types$valueformat matches$typerequirements- Composite types have all required properties
- Dimension values include units
- Color values are valid formats
- Mode keys are strings
- Mode keys match within collections
- Mode values are valid for the variable type
- Mode references resolve correctly
- Group
$extendstargets exist - No circular group references
- Group properties (
$deprecated,$extensions) are valid types
Common validation errors and fixes:
Error: Variable color.primary missing $type
Fix: Add $type property:
{
"color": {
"primary": {
"$type": "color",
"$value": "#0066cc"
}
}
}Error: Reference {color.primary} points to non-existent variable
Fix: Create the referenced variable or fix the reference path.
Error: Circular reference detected: color.a → color.b → color.a
Fix: Break the cycle by making one variable reference a literal value.
Error: Variable name color/web-primary includes platform prefix
Fix: Remove platform prefix: color/primary
Error: Variable spacing.base has $type: "color" but $value: "16px"
Fix: Change $type to "dimension" or change $value to a color.
Adapters MUST validate output after normalization:
- Figma adapter validates normalized JSON
- Tokens Studio adapter validates export JSON
- Style Dictionary validates before build
See adapter documentation for adapter-specific validation.
If validation is skipped:
- Invalid references break component styling
- Type mismatches cause runtime errors
- Circular references cause infinite loops
- Naming violations break code generation
- Mode mismatches break theme switching
- Runtime validation libraries (use DTCG-compliant validators)
- Validation UI tools (use existing tools or build custom)
- Performance work for large token sets (handle separately)
- Design Engineer: owns validation rules and CI setup
- Frontend Engineer: validates outputs in consumption