Fix: check .js/.cjs/.mjs in format:check so the hook and CI agree - #733
Open
AmaadMartin wants to merge 3 commits into
Open
Fix: check .js/.cjs/.mjs in format:check so the hook and CI agree#733AmaadMartin wants to merge 3 commits into
AmaadMartin wants to merge 3 commits into
Conversation
added 2 commits
August 6, 2026 13:10
Output of `npm run format` with the widened glob. No hand edits. Both workflow entry points keep their export shape.
…ommit hook The pre-commit hook formats .js with Prettier but CI only checked .ts, so four tracked JS-family files drifted with nothing to catch them. `cjs` stays out of the lint-staged key: that key runs `eslint --fix` first, and ESLint has no CommonJS override, so it errors on the two tracked .cjs fixtures and would block their commits. Typedoc writes .js bundles to api-reference/, which is not gitignored, so that directory is added to .prettierignore.
The hook's Prettier scope now equals the format:check scope, so a .cjs
edit can no longer commit clean and then fail CI.
The key is separate from **/*.{js,mjs,ts} because that one runs
`eslint --fix` first, and ESLint has no CommonJS override: it errors on
the two tracked .cjs fixtures and would block their commits. Disjoint
globs also keep lint-staged from running eslint and prettier on one file
concurrently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
No existing issue.
Problem: The pre-commit hook formats
.jswith Prettier, butformat:checkin CI only checks.ts. Four tracked JS-family files have therefore drifted, and nothing catches them. A contributor who stages one of those files for an unrelated one-line edit gets a whole-file reformat mixed into the diff, with no warning.Solution: I widened the
formatandformat:checkglobs to**/*.{ts,js,cjs,mjs}and rannpm run formatonce. The four reformats are tool output; I hand-edited none of them. I also widened thelint-stagedkeys to the same four extensions, so the hook formats every file CI checks.Why
.cjsneeds its ownlint-stagedkey..mjsjoins the existing key, but.cjscannot. That key runseslint --fixbeforeprettier --write, and ESLint has no CommonJS override today, so it errors on the two tracked.cjsfixtures:Adding
cjsto that key would block any commit staging either fixture. So.cjsgets a Prettier-only key instead. Keeping the two globs disjoint also stopslint-stagedfrom runningeslint --fixandprettier --writeon one file concurrently. Giving ESLint a**/*.cjsoverride withsourceType: 'commonjs'would let the keys merge, but that widens the ESLint scope and belongs in its own change..prettierignoregetsapi-reference/. Typedoc writes itsoutdirectory there (typedoc.json), and it is not in.gitignore. I measured this rather than assuming it: afternpm run docs:generate, the widened glob flags five Typedoc asset bundles.CI is unaffected either way, because
docs:checkrunstypedoc --emit noneafterformat:check. The ignore entry protects a developer who runsnpm run docsand thennpm run format.Two intended behaviour changes for contributors. A PR that leaves a
.js,.cjsor.mjsfile unformatted now fails CI. Staging a.mjsfile now runseslint --fixandprettier --writein the pre-commit hook, and staging a.cjsfile runsprettier --write.Overlapping open PRs (checked before writing code). Three open PRs touch the same two lines. None is merged, and
mainstill has the narrow**/*.tsglob.#426, notmainmainmain**/*.{ts,json,md}This PR is the only one that sits on
mainand changes the Prettier scope alone. #552's format hunks cannot land until #426 lands. #636 covers JSON and Markdown, not JavaScript, so if it lands first the two widenings compose to**/*.{ts,js,cjs,mjs,json,md}.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
No new test file, deliberately. This change adds zero executable lines. The regression guard is
npm run format:checkin.github/workflows/validation.yaml. A unit test that read the glob string back out ofpackage.jsonwould be a tautology.Mutation proof that the gate can fail. I reverted each of two reformatted files to its
maincopy and re-ran the gate. The old**/*.tsglob passes on the same dirty tree, which is the defect.Integration suites that own the JS-family files this change could disturb, to show the reformats are inert:
Manual End-to-End (E2E) Tests:
Prettier resolves to 3.8.4 from
package-lock.json.npm run formatrewrote exactly the four files listed in the diff and no.tsfile.Local validation on commit
231c1fd. The Actions queue on this fork is backlogged, so no check had started when I finished. I ran the CI steps locally on the exact pushed commit instead.Checklist