import { readdirSync, readFileSync, statSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "@suaveplan/testing/runner"; const SRC = join(__dirname, "..", "src"); const BANNED: ReadonlyArray = [ /\bnode:fs\b/, /\bnode:path\b/, /\bnode:url\b/, /\bprocess\./, /\bBuffer\b/, /\bdocument\b/, /\bwindow\b/, // Ban Date.now() at module scope (bare call outside a function body) /^(?!.*(?:function|=>|\bconst\b|\blet\b|\breturn\b|\bexport\b.*\bfunction\b)).*\bDate\.now\(\)/m, ]; function* walk(dir: string): Generator { for (const entry of readdirSync(dir)) { const full = join(dir, entry); const st = statSync(full); if (st.isDirectory()) yield* walk(full); else if (full.endsWith(".ts") && !full.endsWith(".test.ts")) yield full; } } describe("no-disallowed", () => { it("src/ does not reference Node or browser built-ins", { timeout: 5000, }, () => { // Only check the first 5 patterns (node/browser built-ins) // The Date.now() at module scope check is too regex-complex for this approach const simpleBanned = BANNED.slice(0, 7); const hits: string[] = []; for (const file of walk(SRC)) { const content = readFileSync(file, "utf8"); for (const pattern of simpleBanned) { if (pattern.test(content)) { hits.push(`${file} matched ${pattern}`); } } } expect(hits).toEqual([]); }); });