Understanding Pre-Commit Hook Behavior with Auto-Fixers | Generated by AI
I see the friction — but here’s the thing: trailing-whitespace and end-of-file-fixer already do auto-fix. The “Failed” status just means they modified files. Pre-commit then aborts the commit on purpose (by design), so you must git add + commit again.
There is no config flag in .pre-commit-config.yaml that makes pre-commit auto-stage and continue — it’s an intentional safety choice by pre-commit’s authors. It’s not like ruff --fix where the fix happens and the same hook then re-checks; for the pre-commit-hooks fixers, the “fix” is the modification, and any modification = failure.
So the real options are:
- Editor-side fix (recommended) — make your editor trim trailing whitespace + ensure newline at EOF on save. Then these hooks never trigger. I can add a
.editorconfigso VS Code / most editors do this automatically. - Remove the two noisy hooks — drop
trailing-whitespaceandend-of-file-fixerfrom.pre-commit-config.yaml. They mainly catch editor sloppiness; if your editor handles it, they’re redundant. - Wrapper script — a
git commitwrapper that runspre-commit runfirst,git add -u, then commits. More moving parts, works but lives outside the config file.
Which do you want? My pick is #1 (editorconfig) + keep the hooks as a safety net — that way you stop hitting the double-commit, but commits from other machines still get cleaned up.