Without pre-commit checks, lint errors and formatting issues are caught only in CI, slowing down the review cycle. Husky pre-commit hooks catch the most common issues locally before they're ever pushed.
Requirements and context
- Install
husky and lint-staged
- Pre-commit: run
eslint --fix and prettier --write on staged files
- Pre-push: run
tsc --noEmit to catch type errors before push
- Document in
CONTRIBUTING.md
- Hooks must complete in < 10 seconds for a typical staged change
Suggested execution
git checkout -b ci/husky-pre-commit
- Install Husky and lint-staged
- Configure
lint-staged for ESLint + Prettier
- Add pre-push TypeScript check
- Document in CONTRIBUTING.md
Example commit message
ci: add Husky pre-commit hooks for lint and formatting
Without pre-commit checks, lint errors and formatting issues are caught only in CI, slowing down the review cycle. Husky pre-commit hooks catch the most common issues locally before they're ever pushed.
Requirements and context
huskyandlint-stagedeslint --fixandprettier --writeon staged filestsc --noEmitto catch type errors before pushCONTRIBUTING.mdSuggested execution
lint-stagedfor ESLint + PrettierExample commit message
ci: add Husky pre-commit hooks for lint and formatting