feat(design): sweep off-system styles and add the check:design gate
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,11 @@ describe('Modernist tokens in globals.css', () => {
|
||||
expect(css).toMatch(/--color-blue-700:\s*var\(--color-accent-700\)/)
|
||||
})
|
||||
|
||||
it('remaps the red ramp onto the accent ramp, with body-size steps on accent-700', () => {
|
||||
expect(css).toMatch(/--color-red-600:\s*var\(--color-accent-700\)/)
|
||||
expect(css).toMatch(/--color-red-50:\s*var\(--color-accent-100\)/)
|
||||
})
|
||||
|
||||
it('maps shadows onto the Modernist elevation tokens', () => {
|
||||
expect(css).toMatch(/--shadow-2xl:\s*var\(--shadow-lg\)/)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { findViolations, ROUND_ALLOWED } from '../../scripts/check-design-gates.mjs'
|
||||
|
||||
const rules = (src: string, file = 'components/x.tsx'): string[] =>
|
||||
(findViolations(src, file) as Array<{ rule: string }>).map(v => v.rule)
|
||||
|
||||
describe('design gates', () => {
|
||||
it('flags rounded corner classes', () => {
|
||||
expect(rules('<div className="rounded-lg p-2" />')).toContain('no-rounded')
|
||||
expect(rules('<div className="p-2 hover:rounded-md" />')).toContain('no-rounded')
|
||||
})
|
||||
|
||||
it('flags rounded-full outside the allowlist and accepts it inside', () => {
|
||||
expect(rules('<div className="rounded-full" />')).toContain('no-rounded-full')
|
||||
expect(rules('<div className="rounded-full" />', ROUND_ALLOWED[0])).not.toContain('no-rounded-full')
|
||||
})
|
||||
|
||||
it('flags off-palette colors but accepts remapped gray, blue and red', () => {
|
||||
expect(rules('<p className="text-green-700" />')).toContain('off-palette')
|
||||
expect(rules('<p className="bg-purple-100" />')).toContain('off-palette')
|
||||
expect(rules('<p className="text-gray-500 text-blue-700 bg-red-50" />')).toEqual([])
|
||||
})
|
||||
|
||||
it('flags hard-coded hex colors', () => {
|
||||
expect(rules('<div style={{ color: "#ec3013" }} />')).toContain('no-hex')
|
||||
expect(rules('<p>'quoted'</p>')).not.toContain('no-hex')
|
||||
})
|
||||
|
||||
it('flags centered button labels', () => {
|
||||
expect(rules('<button className="text-center px-2">x</button>')).toContain('no-centered-button')
|
||||
})
|
||||
|
||||
it('flags leftovers the codemod should have replaced', () => {
|
||||
expect(rules('<div className="bg-white shadow-2xl" />')).toEqual(expect.arrayContaining(['no-bg-white', 'no-heavy-shadow']))
|
||||
})
|
||||
|
||||
it('reports file and 1-based line numbers', () => {
|
||||
const v = findViolations('a\n<div className="rounded-md" />', 'components/y.tsx')
|
||||
expect(v[0]).toMatchObject({ file: 'components/y.tsx', line: 2, rule: 'no-rounded' })
|
||||
})
|
||||
|
||||
it('accepts clean on-system markup', () => {
|
||||
expect(rules('<div className="bg-surface border border-divider p-4 text-ink shadow-sm" />')).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user