- Bootstraps `src/core/` foundation (`db.ts`, `valkey.ts`, `spire_ffi.ts`, `main.ts`). - Adds `auth_guards.ts` for payload capping, CSRF check, and rate limiting. - Adds `content_negotiation.ts` and `sse_adapter.ts` for Datastar transport helpers. - Adds `error_fragments.tsx` for standardized Datastar error morphs. - Introduces `scripts/lint_arch.ts` to block imperative DOM usage. - Updates `deno.json` with src workspace configs and lint commands. Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { walk } from "jsr:@std/fs";
|
|
|
|
const targetDir = "./src";
|
|
|
|
let hasErrors = false;
|
|
|
|
async function checkFile(path: string) {
|
|
const content = await Deno.readTextFile(path);
|
|
const lines = content.split('\n');
|
|
|
|
lines.forEach((line, index) => {
|
|
// 1. Block banned DOM APIs
|
|
if (line.includes("document.getElementById") ||
|
|
line.includes("document.querySelector") ||
|
|
line.includes("document.createElement")) {
|
|
console.error(`[Arch Lint] ❌ Banned DOM API used in ${path}:${index + 1}`);
|
|
console.error(` ${line.trim()}`);
|
|
console.error(` -> Use Datastar reactive attributes or SSE morphs instead.`);
|
|
hasErrors = true;
|
|
}
|
|
|
|
// 2. Block unescaped HTML in raw strings (basic heuristic for dangerouslySetInnerHTML)
|
|
if (line.includes("dangerouslySetInnerHTML") && !path.includes("error_fragments.tsx")) {
|
|
console.error(`[Arch Lint] ❌ dangerouslySetInnerHTML used in ${path}:${index + 1}`);
|
|
console.error(` ${line.trim()}`);
|
|
console.error(` -> Native JSX HTML escaping should be used unless in explicit core fragments.`);
|
|
hasErrors = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
for await (const entry of walk(targetDir, { exts: [".ts", ".tsx"] })) {
|
|
if (entry.isFile) {
|
|
await checkFile(entry.path);
|
|
}
|
|
}
|
|
|
|
if (hasErrors) {
|
|
Deno.exit(1);
|
|
} else {
|
|
console.log("✅ Architecture lint passed.");
|
|
}
|