The best way to control Claude Code, Codex and more from any computer or phone

main
ts 41 lines 1.81 KB
Raw
1 // @effect-diagnostics nodeBuiltinImport:off globalConsole:off - a synchronous wrapper around one lint run.
2 // Counts copy that `t3code/no-untranslated-copy` flags, per directory.
3 import * as NodeChildProcess from "node:child_process";
4 import * as NodePath from "node:path";
5
6 const ROOTS = ["apps/web/src", "apps/mobile/src", "packages/client-runtime/src"];
7 const RULE = "no-untranslated-copy";
8 // Split these one level deeper; they hold most of each app.
9 const SPLIT = new Set(["apps/web/src/components", "apps/mobile/src/features"]);
10
11 const lint = NodeChildProcess.spawnSync("vp", ["lint", "--format=json", ...ROOTS], {
12 encoding: "utf8",
13 maxBuffer: 512 * 1024 * 1024,
14 });
15 const report: { diagnostics: ReadonlyArray<{ code?: string; filename: string }> } = JSON.parse(
16 lint.stdout,
17 );
18
19 const bucket = (file: string) => {
20 const relative = NodePath.relative(process.cwd(), NodePath.resolve(file)).split(NodePath.sep);
21 const depth = SPLIT.has(relative.slice(0, 4).join("/")) ? 5 : 4;
22 return relative.length > depth
23 ? relative.slice(0, depth).join("/")
24 : `${relative.slice(0, -1).join("/")}/*`;
25 };
26
27 const counts = new Map<string, number>();
28 for (const diagnostic of report.diagnostics) {
29 if (!diagnostic.code?.includes(RULE)) continue;
30 const key = bucket(diagnostic.filename);
31 counts.set(key, (counts.get(key) ?? 0) + 1);
32 }
33
34 const rows = [...counts].toSorted((left, right) => right[1] - left[1]);
35 const width = Math.max(...rows.map(([key]) => key.length), 5);
36 for (const [key, count] of rows) console.log(`${String(count).padStart(6)} ${key.padEnd(width)}`);
37 for (const root of ROOTS) {
38 const total = rows.filter(([key]) => key.startsWith(root)).reduce((sum, [, n]) => sum + n, 0);
39 console.log(`${String(total).padStart(6)} ${root} total`);
40 }
41 console.log(`${String(rows.reduce((sum, [, n]) => sum + n, 0)).padStart(6)} all`);