chore(lint): forbid require() in scripts/** under "type": "module" #29
No reviewers
Labels
No labels
agent-context-drift
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: rstillwell/deckhearth#29
Loading…
Reference in a new issue
No description provided.
Delete branch "convoy/lint-against-cjs-in-esm-scripts"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds an ESLint
no-restricted-syntaxrule scoped toscripts/**/*.jsthat flags any CallExpression with callee namerequire. The rule is preventative — the current tree is already clean (0 hits) — and exists to stop the recurring CJS-in-ESM bug from re-shipping in a future helper script.Why
Since
bump-next-jsflippedpackage.jsonto"type": "module", any helper script that uses CJSrequire()throwsReferenceError: require is not definedon Node 22.x. This bug has now shipped twice and been caught at first-run-on-the-developer's-machine both times rather than at PR time:drop-public-setupBrief 2 (commitb63b509) —scripts/setup-neon-db.jswas silently broken post-bump-next-jsuntil B2 swept it to ESM imports.fix-reset-db-script(PR #25, squash3ab9bf8) — threerequire()calls inscripts/reset-db.js(lines 10, 12, 142);npm run reset-dbthrewReferenceErroron Node 22.x until PR #25 mirrored the post-DPS shape.Both bugs were lint-clean before they shipped. This rule would have failed lint on both PRs and saved the round-trip.
The rule
One new flat-config block at the end of
eslint.config.mjs(NOT in the root rules block):The error message points reviewers / agents at the exemplar fix (post-DPS
setup-neon-db.jsshape: ESM top-level imports fordotenv,neon,bcrypt) instead of forcing them to re-derive it.Blast-radius rationale:
scripts/**only, NOT all.jsat repo root.pages/api/**is already correctly ESM-imported throughout (verified acrossadd-rate-limiting,cors-tighten, and theadd-routeskill). The root config files (postcss.config.js,tailwind.config.js,next.config.js) intentionally use CJS-style exports that the next-config base rules handle correctly. A repo-wide ban would produce zero true positives outsidescripts/**today and would force explicit allowlist entries for every config file — strictly more code, more maintenance, zero benefit. See.convoys/lint-against-cjs-in-esm-scripts.md§ Design decision.scripts/migrations/**is already inglobalIgnoresfrompick-a-nameB2 and stays excluded; no double-handling needed.Verification
node --check eslint.config.mjs→ exit 0npm run lint→ 128 problems (81 errors, 47 warnings) — verbatim baseline preservation, zero new false positives in the current treeNegative test (apply, run, revert): prepended
const x = require('fs');toscripts/reset-db.js, rannpm run lint, observed exit 1 with 129 problems and the rule firing at line20:11with the documented message:Then reverted the synthetic edit — clean tree, back to 128 problems.
npm run test:run→ 21/21 pass (no test surface touched)Sanity grep:
rg "require\(" scripts/ --type js→ 0 hits (current tree is clean; rule starts with zero positives to silence)Test plan
node --check eslint.config.mjspasses locallynpm run lintbaseline preserved at 128 problems locallyrequire()insert → rule fires → revert) passes locallynpm run test:run21/21 pass locallyforbidden-endpoints+forbidden-cors-headersgates stay greenPlaywright smokestays 3/3 greenScreenshot diffNOT triggered (config-only PR —paths:filter excludeseslint.config.mjsand.convoys/**)Follow-ups
None new — this convoy IS the follow-up surfaced by
fix-reset-db-script(PR #25). Thepurge-weak-creds-from-helpersfollow-up (thescripts/create-test-users.jsportion) remains queued independently and is out of scope here.Made with Cursor
The latest updates on your projects. Learn more about Vercel for GitHub.
Pipeline Health
Build + CI gates
Build runs on Vercel; this CI runs lint and schema-map drift only (no duplicate build).
Role reports
See individual comments above for details. This rollup updates automatically.