chore: add Husky pre-commit hooks for code quality#5
Conversation
Set up Husky with comprehensive pre-commit checks to enforce code quality standards across the entire codebase before commits. **Changes:** - Add husky@^9.1.7 to pnpm catalog for centralized version management - Initialize Husky with prepare script in package.json - Create pre-commit hook that runs on entire codebase: - Prettier formatting check - ESLint on all packages - TypeScript type checking on @poly/ui, @poly/api, and web **Pre-commit checks:** ✅ Format entire codebase with Prettier ✅ Lint all packages with ESLint ✅ Type check all TypeScript packages **Benefits:** - Prevents committing unformatted, unlinted, or type-unsafe code - Ensures consistent code quality across migrations and refactors - Catches issues before they reach CI/CD pipeline - All checks run on full codebase for comprehensive validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PR Review: Husky Pre-commit HooksOverall, this is a well-implemented PR that adds valuable quality gates to the development workflow. The approach is sound and aligns with the repository's quality standards. ✅ Strengths
🔍 Code Quality ObservationsPre-commit Script (.husky/pre-commit:1-34)
|
Address review feedback to make the pre-commit hooks more robust, consistent, and developer-friendly. **Key Improvements:** 1. **Add shebang** - Added #!/bin/sh to pre-commit script for better portability 2. **Standardize typecheck script** - Renamed check-types → typecheck across all packages - Updated @poly/ui, @poly/api package.json scripts - Added root-level "pnpm typecheck" command that runs Turbo typecheck - Updated turbo.json to include typecheck task with db:generate dependency - Simplified pre-commit hook to use single "pnpm typecheck" command 3. **Add Prisma Client generation** - Hook now generates Prisma Client before type checks - Ensures type safety with latest schema changes - Prevents "Prisma Client not generated" errors 4. **Include Storybook type checking** - Now checks all 4 packages: @poly/ui, @poly/api, storybook, web 5. **Comprehensive documentation** - Added Git Hooks section to CLAUDE.md with: - What checks run and why - How to bypass hooks (emergency only) - How to run hooks manually - Troubleshooting guide **Benefits:** - Consistent script naming across monorepo - Single command for type checking entire codebase - Better error messages and documentation - Includes Storybook in quality checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Pull Request Review: Husky Pre-commit Hooks✅ Overall AssessmentThis is a well-implemented PR that adds comprehensive pre-commit hooks to enforce code quality. The implementation is solid, documentation is thorough, and the approach aligns well with the project's needs. 🎯 Strengths
🔍 Code QualityPre-commit Hook (.husky/pre-commit)
Configuration Changes
|
Change pre-commit hook to automatically format files with Prettier and re-stage them, rather than blocking the commit on formatting issues. **Changes:** - Prettier now auto-formats files during pre-commit - Formatted files are automatically re-staged with `git add -u` - Commit proceeds seamlessly without manual formatting intervention **Benefits:** - Better developer experience - no interruption for formatting - Files are always properly formatted before commit - Developers don't need to manually run format and re-commit - Lint and type checks still block commits (as they should) **Behavior:** - Auto-fix: Formatting (non-blocking) - Block: Lint, Prisma generation, type checks (blocking) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Code Review: Husky Pre-commit Hooks SetupOverall AssessmentThis is a well-implemented PR that adds essential code quality gates. The implementation is clean, well-documented, and follows best practices. Strengths
Critical Issue: Git State ProblemLocation: .husky/pre-commit:8 Using git add -u only re-stages modified tracked files, but won't stage new files. Consider either:
This avoids complexity and makes developers explicitly format. Medium Issues
Minor Suggestions
Security & Testing
Code Quality Score: 8.5/10
Approval: Ready to merge after fixing git add -u issueGreat work on improving the development workflow! |
Summary
Set up Husky with comprehensive pre-commit hooks that enforce code quality standards by running checks on the entire codebase before each commit.
Why Full Codebase Checks?
Running checks on the entire codebase (instead of just staged files) ensures:
Pre-commit Hook Checks
The hook runs three comprehensive checks on every commit:
1. 💅 Prettier Formatting
Formats all TypeScript, TSX, and Markdown files with Prettier + Tailwind plugin
2. 📝 ESLint Linting
Runs ESLint across all packages:
3. 🔎 TypeScript Type Checking
Ensures type safety across all TypeScript packages
Changes
Configuration:
.husky/pre-commithook with format + lint + type-checkFiles:
pnpm-workspace.yaml- Added Husky to catalogpackage.json- Added catalog reference and prepare script.husky/pre-commit- Pre-commit hook scriptpnpm-lock.yaml- Updated dependenciesBenefits
✅ Prevents bad commits: Catches formatting, linting, and type errors before they're committed
✅ Enforces standards: All code must meet quality checks
✅ Saves CI time: Issues caught locally instead of in CI/CD
✅ Migration-safe: Validates entire codebase, not just changed files
✅ Fast with Turbo: Cached results make repeat checks quick
Testing
Tested successfully:
Performance Note
With Turbo caching, subsequent runs are very fast (< 1 second when cached). First run takes ~10-15 seconds for full codebase validation.
🤖 Generated with Claude Code