Skip to content

Commit f413cd0

Browse files
TMHSDigitalclaude
andcommitted
lint: node --check runs in parallel (#261); its syntax-only scope is documented (#260)
lint drops from about 1.6 s to 0.8 s here. Undefined names still pass lint; the header and CONTRIBUTING now say so, and that tests are what catch them. Closes #260 Closes #261 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXQPaUhxjgqdqnk6BrJ
1 parent 551df14 commit f413cd0

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ To add a starter stack (one pick per need for a kind of game), follow [`stacks/R
7272

7373
Every pull request, every push to `main` (before the site deploys) and every release run one sequence, `npm run check` in [`package.json`](package.json). Pull requests and pushes run it on Node 24 and again on Node 22; releases run it on Node 24:
7474

75-
1. `npm run lint` (`site/lint.mjs`): every script parses, and none imports a name it does not use.
75+
1. `npm run lint` (`site/lint.mjs`): every script parses, and none imports a name it does not use. It is syntax-only, not ESLint: a misspelled variable still passes and fails only when that line runs, so code the tests never reach needs a test or a careful read.
7676
2. `npm test`: the checks against known-bad fixtures (`site/checks.test.mjs`) and the site modules' tests (`site/lib/lib.test.mjs`).
7777
3. `npm run validate` (`site/validate.mjs`): every entry, link, count table and file against the checks.
7878
4. `npm run check-added` (`site/check-added.mjs`): no entry's `added` date is later than the file's first commit, following renames. It needs the full git history; CI fetches it, and a shallow clone of your own will fail this step.

‎site/lint.mjs‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
* run monthly (thumbs, reverify, check-links): each file must parse
55
* (`node --check`), and every name it imports must be used. Zero
66
* dependencies; run: node site/lint.mjs
7+
*
8+
* It is not a linter in the ESLint sense: a misspelled variable parses, so
9+
* it passes here and fails only when that line runs (#260). Tests are what
10+
* catch those; CONTRIBUTING says so.
711
*/
8-
import { execFileSync } from "node:child_process";
12+
import { execFile } from "node:child_process";
913
import fs from "node:fs";
14+
import os from "node:os";
1015
import path from "node:path";
1116
import { fileURLToPath } from "node:url";
1217
import { cliArgs } from "./lib/cli.mjs";
@@ -63,21 +68,34 @@ export function unusedImports(text) {
6368
return unused;
6469
}
6570

66-
function main() {
71+
/** `node --check file`: null when it parses, else the first lines of the error. */
72+
function syntaxError(file) {
73+
return new Promise((resolve) => {
74+
execFile(process.execPath, ["--check", file], (err, _out, stderr) => {
75+
resolve(err ? String(stderr || err.message).trim().split("\n").slice(0, 5).join("\n ") : null);
76+
});
77+
});
78+
}
79+
80+
async function main() {
6781
cliArgs({}, "node site/lint.mjs");
68-
const errors = [];
6982
const files = scriptFiles();
70-
for (const file of files) {
71-
const rel = path.relative(ROOT, file).split(path.sep).join("/");
72-
try {
73-
execFileSync(process.execPath, ["--check", file], { stdio: ["ignore", "ignore", "pipe"] });
74-
} catch (err) {
75-
const first = String(err.stderr || err.message).trim().split("\n").slice(0, 5).join("\n ");
76-
errors.push(`${rel} does not parse:\n ${first}`);
77-
continue;
83+
// One node --check per file, several at a time (#261); results stay in file order.
84+
const results = new Array(files.length);
85+
let next = 0;
86+
const worker = async () => {
87+
while (next < files.length) {
88+
const i = next++;
89+
results[i] = await syntaxError(files[i]);
7890
}
91+
};
92+
await Promise.all(Array.from({ length: Math.min(files.length, Math.max(2, os.availableParallelism())) }, worker));
93+
const errors = [];
94+
files.forEach((file, i) => {
95+
const rel = path.relative(ROOT, file).split(path.sep).join("/");
96+
if (results[i]) return void errors.push(`${rel} does not parse:\n ${results[i]}`);
7997
for (const name of unusedImports(fs.readFileSync(file, "utf8"))) errors.push(`${rel} imports ${name} and never uses it`);
80-
}
98+
});
8199
if (errors.length) {
82100
console.error(`lint failed (${errors.length}):`);
83101
for (const e of errors) console.error(` - ${e}`);
@@ -86,4 +104,4 @@ function main() {
86104
console.log(`lint ok: ${files.length} scripts parse, no unused imports`);
87105
}
88106

89-
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main();
107+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) await main();

0 commit comments

Comments
 (0)