mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
2f54f04380
lint:size counted newlines, so a file could stay under its entry by joining lines, and the trip planner page already carried one JSX element on a single 3760 character line. A line now counts once per 120 characters it spans, the printWidth in .prettierrc, so formatted code measures what it shows and packed code measures what it holds. The check also covered only .ts and .tsx sources. Stylesheets now share the 1000 line limit, and tests get a limit of their own at 2000: they mirror the component they cover and carry fixtures, but the largest are past 5000 lines and growing with the god components. The baseline is measured again with the new rule and keyed by the path from client/, since it now spans src/ and tests/. Entries are higher in number than before because the metric changed, not because a file grew; every file is held at exactly what it holds today. New entries are the ten largest tests, index.css and studio.css, the generated countryShapes.ts (305 lines of 2600 characters each) and JourneyDetailPageEntryEditor.tsx, which was just under the old count. The scanning, baseline reading and lowering move to scripts/lib/ so the next ratchets share them. A baseline that is missing or misshapen, a directory that is not there and a scan that finds nothing now fail the run instead of reading as empty, and the command file always runs its check: there is no entry point guard left that could skip it.
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { dirname, join } from 'node:path';
|
|
|
|
/**
|
|
* A throwaway client tree for the ratchet scripts in scripts/lib/: each key is
|
|
* a path from the tree's root, each value the file's text. The checks are run
|
|
* against it with their output collected, so a test sees exactly what CI would
|
|
* print and the exit code it would end with.
|
|
*/
|
|
export interface RatchetTree {
|
|
root: string;
|
|
write: (files: Record<string, string>) => void;
|
|
path: (key: string) => string;
|
|
log: string[];
|
|
error: string[];
|
|
out: { log: (line: string) => void; error: (line: string) => void };
|
|
remove: () => void;
|
|
}
|
|
|
|
export function ratchetTree(files: Record<string, string> = {}): RatchetTree {
|
|
const root = mkdtempSync(join(tmpdir(), 'trek-ratchet-'));
|
|
const log: string[] = [];
|
|
const error: string[] = [];
|
|
const write = (more: Record<string, string>) => {
|
|
for (const [key, text] of Object.entries(more)) {
|
|
const path = join(root, key);
|
|
mkdirSync(dirname(path), { recursive: true });
|
|
writeFileSync(path, text);
|
|
}
|
|
};
|
|
write(files);
|
|
return {
|
|
root,
|
|
write,
|
|
path: (key) => join(root, key),
|
|
log,
|
|
error,
|
|
out: { log: (line) => log.push(line), error: (line) => error.push(line) },
|
|
remove: () => rmSync(root, { recursive: true, force: true }),
|
|
};
|
|
}
|
|
|
|
/** n lines of short code, each ending in a newline. */
|
|
export function lines(n: number, text = 'const a = 1'): string {
|
|
return `${text}\n`.repeat(n);
|
|
}
|