hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { readdirSync, readFileSync, statSync } from "node:fs"; |
| 2 | import { join, relative } from "node:path"; |
| 3 | |
| 4 | /** |
| 5 | * Guardrails for the UI rules in docs/ui and the ui-conventions skill. Each |
| 6 | * one was broken somewhere before the 2026-09 UI pass fixed it; this keeps it |
| 7 | * from drifting back. |
| 8 | */ |
| 9 | const SRC = join(__dirname, ".."); |
| 10 | |
| 11 | function sourceFiles(dir: string): string[] { |
| 12 | return readdirSync(dir).flatMap((name) => { |
| 13 | const path = join(dir, name); |
| 14 | if (statSync(path).isDirectory()) return sourceFiles(path); |
| 15 | return /\.tsx?$/.test(name) && !/\.test\.tsx?$/.test(name) ? [path] : []; |
| 16 | }); |
| 17 | } |
| 18 | |
| 19 | const files = sourceFiles(SRC).map((path) => ({ path: relative(SRC, path), text: readFileSync(path, "utf8") })); |
| 20 | const offenders = (pattern: RegExp, allow: (path: string) => boolean = () => false) => |
| 21 | files.filter((file) => !allow(file.path) && pattern.test(file.text)).map((file) => file.path); |
| 22 | |
| 23 | it("domain code renders tables through DataTable, not raw <table>", () => { |
| 24 | // The insight run report is a print document; DataTable's toolbar and |
| 25 | // phone card layout would break the printed page. |
| 26 | expect( |
| 27 | offenders(/<table[\s>]/, (path) => path.startsWith("components/ui/") || path === "components/insights/insight-run-report.tsx"), |
| 28 | ).toEqual([]); |
| 29 | }); |
| 30 | |
| 31 | it("no text below 11px, bar the two avatar-initial circles", () => { |
| 32 | expect( |
| 33 | offenders(/text-\[(?:[0-9]|10)px\]/, (path) => path === "components/users/user-avatar.tsx" || path === "pages/questions-page.tsx"), |
| 34 | ).toEqual([]); |
| 35 | }); |
| 36 | |
| 37 | it("colored text uses the contrast-safe -text tokens", () => { |
| 38 | expect(offenders(/(?<![\w-])text-(?:primary|success|warning|info|destructive)(?![\w/-])/)).toEqual([]); |
| 39 | }); |
| 40 | |
| 41 | it("the back button never calls window.history.back()", () => { |
| 42 | expect(offenders(/window\.history\.back\(\)/)).toEqual([]); |
| 43 | }); |
| 44 | |
| 45 | it("no native browser dialogs", () => { |
| 46 | expect(offenders(/window\.(?:confirm|prompt|alert)\(/)).toEqual([]); |
| 47 | }); |