Auto-format staged files with Biome on pre-commit#4
Merged
Conversation
A dependency-free git hook (.githooks/pre-commit) runs `biome check --staged --write --no-errors-on-unmatched` and re-stages the fixes, so formatting and safe lint fixes land automatically and never fail CI's `pnpm run check`. Activated on install via `prepare` (git config core.hooksPath .githooks); bypass with --no-verify.
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.
Why
PR #3's first CI run failed only on Biome formatting. A pre-commit hook makes formatting/safe-fixes land automatically so it never reaches a red build. (CI's
pnpm run checkstays the authoritative gate; this just fails faster — locally and auto-fixed.)What
.githooks/pre-commitrunsbiome check --staged --write --no-errors-on-unmatchedand re-stages the rewritten files, so the commit includes the fixes. Anything Biome can't auto-fix (lint errors needing a manual edit) still blocks the commit.prepare(git config core.hooksPath .githooks), guarded so a non-git/tarball install can't failprepare.--no-errors-on-unmatchedso commits touching only non-Biome files (e.g.package.json, shell scripts) aren't blocked.git commit --no-verify.Verified locally
export const probe={a:1,b:2};→ committed asexport const probe = { a: 1, b: 2 };(auto-fixed and re-staged).package.json+ the shell script passes (no false "no files processed" failure).