Add scripts/format-changed.sh: sanctioned pre-commit formatting - #213
Merged
Merged
Conversation
The "never run prettier --write or eslint --fix by hand" rule was right, but its only sanctioned formatter ran after the commit — so format:check was guaranteed red on a working tree, and every branch paid one doomed check:all run before the post-commit hook's amend made it green. - format-touched gains --no-amend: same per-package buckets and fixers, but nothing is staged or amended, and files with unstaged changes are formatted rather than skipped (the skip only ever protected the amend from swallowing WIP; with no amend there is nothing to protect). - scripts/format-changed.sh collects the working tree's modified and untracked files from git status --porcelain and delegates. Files the branch already committed are not revisited — the hook formatted them at commit time. - Tests: --no-amend formats dirty files and never folds into HEAD; the wrapper collects modified/untracked/renamed paths and skips deletions. - Root and cli AGENTS.md now name the wrapper where the rule lives; scripts/README.md indexes it.
| 🟣 Preview removed (PR closed). |
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.
What
The
format:checkchicken-and-egg: the only sanctioned formatter was the post-commit hook's amend, so a working tree was guaranteed red until after the commit — every branch paid one doomedcheck:allrun. This adds the pre-commit half.How
.githooks/format-touched --no-amend— the same per-package buckets and pinned fixers, but nothing is staged or amended, and files with unstaged changes are formatted rather than skipped. That skip only ever protected the amend from swallowing WIP; with no amend there is nothing to protect — a dirty working-tree file is exactly what the mode is for.scripts/format-changed.sh— the documented front door: collects modified + untracked files fromgit status --porcelain(renames resolve to their new name; deletions are skipped byformat-touched's[ -f ]) and delegates. Files the branch already committed are deliberately not revisited — the hook formatted them at commit time, and re-reading them against a stale base would only reformat whatever main gained since.The new loop:
scripts/format-changed.sh→check:allgreen on the first run → commit → the hook finds nothing to do.The hand-run ban stays and is the point: no root
node_modules, per-package pinned binaries, and only web's prettier parses.svelte— so the fixer dispatch has one owner, and both entry points go through it.Tests
--no-amendformats a file with unstaged changes, folds nothing into HEAD even when fixers rewrote it, no-ops with no paths; the wrapper collects modified/untracked/renamed and skips deleted; clean tree runs nothing.repo-filessteps run locally).check-commentsgreen; rootAGENTS.md,cli/AGENTS.mdandscripts/README.mdupdated where the rule lives.web/src/*.tsand a dirty tracked one were both rewritten by web's own pinned prettier,prettier --checkgreen after, HEAD untouched.