35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const srcRoot = resolve(here, "..", "src");
|
|
|
|
function walk(dir: string): string[] {
|
|
const out: string[] = [];
|
|
for (const name of readdirSync(dir)) {
|
|
const full = join(dir, name);
|
|
const st = statSync(full);
|
|
if (st.isDirectory()) out.push(...walk(full));
|
|
else if (full.endsWith(".ts")) out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe("zod import discipline", () => {
|
|
it("every src file uses default-import z (never named { z })", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const offenders: string[] = [];
|
|
for (const file of walk(srcRoot)) {
|
|
const text = readFileSync(file, "utf8");
|
|
// Named-form: import { z } from "zod"
|
|
if (/import\s*\{\s*z\s*\}\s*from\s*["']zod["']/.test(text)) {
|
|
offenders.push(file);
|
|
}
|
|
}
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
});
|