chore: add pre-commit hook to auto-format and lint staged .ts files#21
Conversation
pre-commit runs prettier --write + eslint --fix on staged *.ts and re-stages them, so commits are already formatted/linted and less likely to fail the pre-push verify (format:check / lint). pre-push verify is unchanged. No functional change — tooling only. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughA ChangesPre-commit Lefthook Configuration
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lefthook.yml`:
- Line 4: The glob patterns in the lefthook.yml file for both the format and
lint jobs use `*.ts` which only matches TypeScript files in the root directory
and does not match files in subdirectories like src/. Update both glob pattern
declarations (in the format job at line 4 and in the lint job at line 7) from
`*.ts` to `**/*.ts` to match TypeScript files at any depth in the directory
structure, ensuring that staged files in src/ subdirectories are properly
processed by the pre-commit hooks.
- Around line 1-9: The glob patterns in both the format and lint jobs under
pre-commit are too restrictive and only match TypeScript files in the repository
root. Update the glob pattern from "*.ts" to "**/*.ts" (or "src/**/*.ts" if you
want to be more specific) in both the format job and lint job to ensure that
TypeScript files in subdirectories like src/ are also matched and processed
during the pre-commit hook.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 5386c64b-f1a9-4a66-98ac-a6ae4ae4e589
📒 Files selected for processing (1)
lefthook.yml
CodeRabbit flagged "*.ts" as not matching nested files. Empirically it does match staged src/*.ts under lefthook 2.1.9 (glob is applied per file name), so this is not a behavior fix — but **/*.ts states the intent explicitly and is robust to future glob_matcher changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
@coderabbitai Updated both globs to A note for the record: I tested the original |
|
Tip For best results, initiate chat on the files or code changes.
✏️ Learnings added
|
Summary
Adds a
pre-commitlefthook job that runsprettier --write+eslint --fixon staged*.tsfiles and re-stages them.Why
pre-pushverify (format:check/lint).pre-push(pnpm verify) is unchanged.Verification
lefthook dumpparses the config;lefthook run pre-commitskips when no*.tsis staged (glob works).🤖 Generated with Claude Code
Summary by CodeRabbit