/** * Grep guard — fail if `src/` contains any disallowed construct: * `any`, `ts-ignore`, `ts-expect-error`, `TODO`, `FIXME`, `@deprecated`, * `.skip(`, `.only(`. Test fixtures and benchmarks are excluded. */ import { readdir, readFile } from "node:fs/promises"; import { dirname, join, relative, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "../src/runner/index.js"; const here = dirname(fileURLToPath(import.meta.url)); const srcRoot = resolve(here, "..", "src"); const PATTERNS: Array<{ name: string; regex: RegExp }> = [ { name: "any", regex: /(? { const entries = await readdir(dir, { withFileTypes: true }); for (const entry of entries) { const full = join(dir, entry.name); if (entry.isDirectory()) { await walk(full, out); } else if ( entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".tsx")) ) { out.push(full); } } } describe("no-disallowed source guard", () => { it("src/ contains no disallowed constructs", { timeout: 10000, }, async () => { const all: string[] = []; await walk(srcRoot, all); const files = all.filter((file) => { const rel = relative(srcRoot, file).replace(/\\/g, "/"); return !EXCLUDED_FILE_SUFFIXES.some((s) => rel.endsWith(s)); }); const violations: string[] = []; for (const file of files) { const text = await readFile(file, "utf8"); const lines = text.split("\n"); const rel = relative(srcRoot, file).replace(/\\/g, "/"); for (const { name, regex } of PATTERNS) { if (name === "any" && EXCLUDED_FROM_ANY_CHECK.includes(rel)) { continue; } for (let i = 0; i < lines.length; i++) { const line = lines[i] ?? ""; const trimmed = line.trim(); if ( trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*") ) continue; if (regex.test(line)) { violations.push( `${rel}:${i + 1} contains "${name}": ${trimmed}` ); } } } } expect(violations).toEqual([]); }); });