Skip to content

Auto-format staged files with Biome on pre-commit#4

Merged
siffogh merged 2 commits into
mainfrom
chore/biome-precommit-hook
Jun 29, 2026
Merged

Auto-format staged files with Biome on pre-commit#4
siffogh merged 2 commits into
mainfrom
chore/biome-precommit-hook

Conversation

@siffogh

@siffogh siffogh commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

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 check stays the authoritative gate; this just fails faster — locally and auto-fixed.)

What

  • .githooks/pre-commit runs biome check --staged --write --no-errors-on-unmatched and 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.
  • Dependency-free — no husky/lefthook. Activated on install via prepare (git config core.hooksPath .githooks), guarded so a non-git/tarball install can't fail prepare.
  • --no-errors-on-unmatched so commits touching only non-Biome files (e.g. package.json, shell scripts) aren't blocked.
  • Bypass with git commit --no-verify.
  • CONTRIBUTING note added.

Verified locally

  • Ugly staged file export const probe={a:1,b:2}; → committed as export const probe = { a: 1, b: 2 }; (auto-fixed and re-staged).
  • A commit staging only package.json + the shell script passes (no false "no files processed" failure).

siffogh added 2 commits June 29, 2026 15:38
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.
@siffogh siffogh merged commit 661ba9e into main Jun 29, 2026
2 checks passed
@siffogh siffogh deleted the chore/biome-precommit-hook branch June 29, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant