chore: Add Husky pre-commit hook for automatic code formatting (Vibe Kanban) - #76
Conversation
1. **Installed Husky** (`^9.1.7`) as a dev dependency 2. **Created `.husky/pre-commit`** hook that: - Runs `pnpm format:write` to auto-format code - Runs `git add -u` to stage the formatted changes 3. **Added `prepare` script** to `package.json` so Husky installs automatically after `pnpm install` Now every commit will automatically format the code with Prettier before committing.
📝 WalkthroughSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughAdds Husky pre-commit hook and lint-staged integration; introduces a prepare script in package.json and updates scripts. A new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Code Review: Pre-commit Hook for Automatic FormattingSummaryThis PR adds a Husky pre-commit hook to automatically run 🔴 Critical Issues1. Missing Shebang in Hook ScriptThe Current: pnpm format:write
git add -uShould be: #!/usr/bin/env sh
pnpm format:write
git add -u2. Unsafe
|
**Changes made:**
1. **Added shebang and error handling** to `.husky/pre-commit`:
```sh
#!/usr/bin/env sh
set -e
npx lint-staged
```
2. **Installed `lint-staged`** (`^16.2.7`) - the industry standard for running linters on staged files only
3. **Added `lint-staged` configuration** to `package.json`:
```json
"lint-staged": {
"*.{ts,tsx,js,jsx,json,md,yml,yaml}": "prettier --write"
}
```
**Benefits of this approach:**
- Only formats files that are being committed (not the entire codebase)
- Much faster commits
- No unsafe `git add -u` that could stage unrelated changes
- Proper error handling with `set -e`
- Correct shebang for cross-platform compatibility
Code Review - PR #76: Add Husky Pre-commit HookSummaryThis PR adds automated code formatting via Husky pre-commit hooks using 🔴 Critical Issue: Implementation vs Description MismatchThe PR description does NOT match the actual implementation: Description claims:
Actual implementation (.husky/pre-commit:3): npx lint-stagedWhat's actually happening:
Impact: This is actually better than described because: Recommendation: Update the PR description to accurately reflect the ✅ Strengths
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.husky/pre-commit (1)
1-2: Optional: avoid formatting the entire repo on every commit (performance + surprise diffs).
pnpm format:writeruns Prettier over.; that can be slow and can stage unrelated formatting changes viagit add -u. Consider switching to staged-file formatting (e.g.,lint-staged).
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
.husky/pre-commitpackage.json
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
Repo: AndurilCode/mcp-apps-kit PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-09T14:18:43.501Z
Learning: Run full checks before PR: `pnpm build && pnpm test && pnpm lint && pnpm typecheck`
📚 Learning: 2026-01-09T14:18:43.501Z
Learnt from: CR
Repo: AndurilCode/mcp-apps-kit PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-09T14:18:43.501Z
Learning: Run full checks before PR: `pnpm build && pnpm test && pnpm lint && pnpm typecheck`
Applied to files:
.husky/pre-commitpackage.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test-and-lint
- GitHub Check: claude-review
🔇 Additional comments (5)
package.json (4)
55-56: Tooling deps look consistent withdocs/docs:watch; just ensure versions are intentional.
21-21:typedoc --watchis fully supported in TypeDoc 0.28.15 (the version specified in package.json). The flag is documented in TypeDoc's CLI options and works as expected for watch mode. No issues or caveats detected.
50-50: Husky v9.1.7 bump is safe—repository already has proper pnpm workspace setup.The repo correctly uses
"prepare": "husky"(v9-compatible) with pnpm-workspace.yaml and .npmrc in place, which aligns with Husky v9's requirements for pnpm environments. No additional action needed.
21-22: Husky prepare script is safe in this CI setup.Husky v9.1.7 automatically detects CI environments and non-git contexts, gracefully skipping the prepare step without requiring
HUSKY=0or--ignore-scripts. Your GitHub Actions workflows have.gitdirectories from full repository clones, so theprepare: "husky"script will execute safely. No guard is needed for the current setup.Likely an incorrect or invalid review comment.
.husky/pre-commit (1)
1-2: Current hook file is already correct for Husky v9.The recommendation to add
#!/usr/bin/env shand. "$(dirname -- "$0")/_/husky.sh"is outdated. Husky v9 deprecated this pattern and no longer requires it. For simple hooks like this, the current implementation (plain commands without shebang) is the recommended approach in Husky v9. The repository uses Husky v9.1.7, which handles hook execution without the deprecated bootstrap code. No changes are needed.Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
package.json (1)
61-63: Configuration looks correct; consider the pre-commit scope trade-off.The
lint-stagedconfiguration is properly structured, and the file patterns appropriately cover common source files. lint-staged will automatically append matched files to theprettier --writecommand.Note that the pre-commit hook currently only runs formatting, not the full suite of checks (lint, typecheck, tests). While this is faster and aligns with the PR's stated goals, it means commits may pass formatting but still fail CI checks. Based on learnings, full checks (
pnpm build && pnpm test && pnpm lint && pnpm typecheck) should be run before creating a PR. Consider documenting this workflow expectation for contributors, or optionally addeslint --fixto the lint-staged configuration to catch at least some lint issues early.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
.husky/pre-commitpackage.json
🚧 Files skipped from review as they are similar to previous changes (1)
- .husky/pre-commit
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
Repo: AndurilCode/mcp-apps-kit PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-09T14:18:43.501Z
Learning: Run full checks before PR: `pnpm build && pnpm test && pnpm lint && pnpm typecheck`
🔇 Additional comments (2)
package.json (2)
22-22: LGTM! Standard Husky v9 initialization.The
preparescript correctly initializes Husky hooks after installation, following the recommended pattern for Husky v9.
50-50: Both package versions are valid and have no known security vulnerabilities.husky@9.1.7andlint-staged@16.2.7are available on npm and free from reported CVEs.
Summary
This PR adds a pre-commit hook using Husky and lint-staged to automatically format staged files before each commit, ensuring consistent code style across the project.
Changes
^9.1.7) for Git hooks management^16.2.7) to run formatters only on staged files.husky/pre-commithook with:#!/usr/bin/env sh) for cross-platform compatibilityset -e) to abort commit on formatter errorsnpx lint-stagedto format only staged filespreparescript topackage.jsonfor automatic Husky installation*.{ts,tsx,js,jsx,json,md,yml,yaml}filesWhy
Previously, code formatting was a manual step that contributors had to remember to run. This could lead to:
With this pre-commit hook, formatting is now automatic and enforced for staged files only.
Implementation Details
git commit --no-verifyif neededThis PR was written using Vibe Kanban