Lefthook Setup Guide
Why Lefthook?
Lefthook run automated checks before code commit. Catch bugs, format issues, lint errors before production.
- Frontend ESLint validation
- Backend Go tests
- Backend format checks
Commit fail if checks fail.
Prerequisites
Need:
- Node.js 18+
- npm
- Go 1.21+
Check versions:
node -v
npm -v
go version
Install Lefthook
From project root:
npm install --save-dev lefthook
npx lefthook install
Output show sync hooks: ✔️.
Verify Installation
npx lefthook run pre-commit
Execute configured checks.
Normal Development Flow
Before commit:
git add .
git commit -m "your message"
Lefthook run automatically. If check fail, commit rejected. Fix issue, commit again.
Troubleshooting
Lefthook not running:
npx lefthook install
Skip hooks temporarily (emergency only):
git commit --no-verify -m "message"
Configuration
Config file: lefthook.yml.
Add new checks example:
pre-commit:
jobs:
backend-test:
root: backend/
run: go test ./...
frontend-lint:
root: customer/
run: npm run lint
Run npx lefthook install after change.
Team Rule
All developers must install Lefthook before contribute. Do not commit code with failing tests, lint errors, broken builds, format issues.
Commit package.json, package-lock.json, lefthook.yml to Git. Do NOT commit .git/hooks. Other devs clone and run npm install then npx lefthook install.
Written by A.M. Rinas