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:
2026-09-30 20:39:44 +08:00
co-authored by Claude Haiku 4.5
parent ba9eeefe47
commit c5a98eed06
56 changed files with 335 additions and 216 deletions
+45
View File
@@ -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>&#39;quoted&#39;</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([])
})
})