import { readdirSync, readFileSync, statSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const RULES = [ { rule: 'no-2px-border', re: /(?]*className=[^>]*(? { for (const { rule, re } of RULES) { if (re.test(text)) out.push({ file, line: i + 1, rule, 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()