|
| 1 | +#!/usr/bin/env node |
| 2 | +// Dependency-free static lint for the repo. Two cheap, fast checks that fit the |
| 3 | +// "no package.json, no toolchain" philosophy: |
| 4 | +// 1. `node --check` every .mjs we own → catches syntax errors before tests run. |
| 5 | +// 2. JSON.parse every .json we own → catches broken manifests / kit metadata. |
| 6 | +// Vendored bundles (canvas-kit/vendor/), node_modules/ and per-user artifacts/ are |
| 7 | +// skipped — we don't own them. Run with `node scripts/lint.mjs`. |
| 8 | + |
| 9 | +import { readdirSync, readFileSync } from "node:fs"; |
| 10 | +import { spawnSync } from "node:child_process"; |
| 11 | +import { dirname, join, relative, sep } from "node:path"; |
| 12 | +import { fileURLToPath } from "node:url"; |
| 13 | + |
| 14 | +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); |
| 15 | +const SKIP_DIRS = new Set(["node_modules", "artifacts", "vendor", ".git"]); |
| 16 | + |
| 17 | +function* walk(dir) { |
| 18 | + for (const entry of readdirSync(dir, { withFileTypes: true })) { |
| 19 | + if (entry.isDirectory()) { |
| 20 | + if (!SKIP_DIRS.has(entry.name)) yield* walk(join(dir, entry.name)); |
| 21 | + } else { |
| 22 | + yield join(dir, entry.name); |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +const files = [...walk(root)]; |
| 28 | +const rel = (p) => relative(root, p).split(sep).join("/"); |
| 29 | + |
| 30 | +let failures = 0; |
| 31 | +const fail = (p, msg) => { |
| 32 | + failures++; |
| 33 | + console.error(`✗ ${rel(p)}: ${msg}`); |
| 34 | +}; |
| 35 | + |
| 36 | +const mjs = files.filter((f) => f.endsWith(".mjs")); |
| 37 | +for (const f of mjs) { |
| 38 | + const res = spawnSync(process.execPath, ["--check", f], { encoding: "utf8" }); |
| 39 | + if (res.status !== 0) fail(f, `syntax error\n${(res.stderr || "").trim()}`); |
| 40 | +} |
| 41 | + |
| 42 | +const json = files.filter((f) => f.endsWith(".json")); |
| 43 | +for (const f of json) { |
| 44 | + try { |
| 45 | + JSON.parse(readFileSync(f, "utf8")); |
| 46 | + } catch (err) { |
| 47 | + fail(f, `invalid JSON: ${err.message}`); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +if (failures > 0) { |
| 52 | + console.error(`\n${failures} lint problem(s) found.`); |
| 53 | + process.exit(1); |
| 54 | +} |
| 55 | + |
| 56 | +console.log(`✓ lint clean: ${mjs.length} .mjs syntax-checked, ${json.length} .json parsed.`); |
0 commit comments