53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { readdir, readFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const SRC_DIR = join(import.meta.dirname, "../src");
|
|
|
|
const DISALLOWED = [
|
|
"node:fs",
|
|
"node:path",
|
|
"process.env",
|
|
"Buffer",
|
|
"document",
|
|
"window",
|
|
];
|
|
|
|
async function collectTsFiles(dir: string): Promise<string[]> {
|
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
const files: string[] = [];
|
|
for (const e of entries) {
|
|
if (e.name === "__benchmarks__") continue;
|
|
if (e.isDirectory()) {
|
|
files.push(...(await collectTsFiles(join(dir, e.name))));
|
|
} else if (
|
|
e.name.endsWith(".ts") &&
|
|
!e.name.endsWith(".test.ts") &&
|
|
!e.name.endsWith(".bench.ts")
|
|
) {
|
|
files.push(join(dir, e.name));
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
describe("no-disallowed", () => {
|
|
it("source files must not use disallowed APIs", {
|
|
timeout: 5000,
|
|
}, async () => {
|
|
const files = await collectTsFiles(SRC_DIR);
|
|
const violations: string[] = [];
|
|
|
|
for (const file of files) {
|
|
const content = await readFile(file, "utf-8");
|
|
for (const banned of DISALLOWED) {
|
|
if (content.includes(banned)) {
|
|
violations.push(`${file}: contains "${banned}"`);
|
|
}
|
|
}
|
|
}
|
|
|
|
expect(violations).toEqual([]);
|
|
});
|
|
});
|