import { readdirSync, readFileSync, statSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' // Files where a circular element is legitimate (avatar). Add others only with a reason. export const ROUND_ALLOWED = ['components/layout/sidebar.tsx'] const RULES = [ { rule: 'no-rounded', re: /(?<=[\s"'`:{])(?:[\w-]+:)*rounded(?:-(?!full(?![\w-]))[\w]+)*(?=[\s"'`}])/, }, { rule: 'no-bg-white', re: /(?]*className=[^>]*(? { const line = i + 1 for (const { rule, re } of RULES) { if (re.test(text)) out.push({ file, line, rule, text: text.trim() }) } if (!roundAllowed && /(?<=[\s"'`:{])(?:[\w-]+:)*rounded-full(?=[\s"'`}])/.test(text)) { out.push({ file, line, rule: 'no-rounded-full', text: text.trim() }) } }) return out } function walk(dir, files = []) { for (const name of readdirSync(dir)) { const full = path.join(dir, name) if (statSync(full).isDirectory()) walk(full, files) else if (full.endsWith('.tsx')) files.push(full) } return files } function main() { const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') const all = [] for (const dir of ['app', 'components']) { for (const abs of walk(path.join(root, dir))) { const rel = path.relative(root, abs).split(path.sep).join('/') all.push(...findViolations(readFileSync(abs, 'utf8'), rel)) } } for (const v of all) console.log(`${v.file}:${v.line} [${v.rule}] ${v.text}`) console.log(all.length === 0 ? 'design gates: clean' : `design gates: ${all.length} violation(s)`) process.exit(all.length === 0 ? 0 : 1) } if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main()