-
Notifications
You must be signed in to change notification settings - Fork 49
feat: Add native Git hooks for automatic code formatting #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add native Git hooks for automatic code formatting #167
Conversation
- Add setup.sh script to start all services in tmux session - Add stop.sh script for graceful shutdown - Add comprehensive development/README.md with setup instructions - Include prerequisite checks for Go, Node.js, npm, Docker, and tmux - Validate environment files before starting services - Auto-install dependencies if missing - Update main README.md with development setup section Fixes CCExtractor#155
- Change backend/.env to ./backend/.env to avoid confusion - Add note about running backend in separate user environment - Clarify sync server startup command in service URLs - Add CCSync documentation website references in setup.sh error messages - Add documentation link for OAuth credential setup
- Setup Husky v9.1.7 with lint-staged for pre-commit hooks - Automatically run Prettier on staged frontend files (JS/TS/JSON/CSS/MD) - Automatically run gofmt on staged backend Go files - Add .prettierignore to exclude build artifacts and dependencies - Update CONTRIBUTING.md with Husky setup information - Add .husky/README.md for hook documentation - Update .gitignore to exclude node_modules and package-lock.json at root This prevents contributors from forgetting to run formatting commands manually, ensuring consistent code style across all commits. Fixes: CCExtractor#114
Remove deprecated shebang and husky.sh sourcing to prepare for Husky v10
|
hey @its-me-abhishek . This PR is ready for review. I've implemented Husky pre-commit hooks to automatically format code before committing, which solves issue #114. |
|
hi, while this looks fine, i think having another package.json will just make this project more complicated. i think we can shall either use a Githook instead of Husky, or if we continue to integrate this Husky into the package.json of frontend dir (which will not work with the root dir so thats a drawback). |
|
hey @its-me-abhishek , thanks for the feedback! You're absolutely right - adding a root package.json does add unnecessary complexity. I'll refactor this to use native Git hooks instead of Husky. Will update the PR soon. |
- Remove Husky dependency and root package.json - Add setup-git-hooks.sh script for native Git hook installation - Maintain automatic formatting functionality for frontend and backend - Update CONTRIBUTING.md with new setup instructions This addresses maintainer feedback to avoid adding complexity with a root package.json. Contributors run ./scripts/setup-git-hooks.sh once after cloning to enable automatic code formatting. Fixes: CCExtractor#114
37e7435 to
0b59350
Compare
hey @its-me-abhishek, |
|
This looks fine but will add another caveat or layer, to setup inorder to make things work. It'd be better to add something similar this to the githooks directory along with go fmt and then add these scripts to the frontends' package.json It'll be setup automatically, then, after the user runs npm install, hence making it an automated workflow! |
- Created .githooks/pre-commit for native Git hook implementation - Added postinstall script to automatically configure Git hooks on npm install - Hook runs prettier for frontend files and gofmt for backend files - Updated documentation to reflect automated setup process - Removed manual setup script as hooks now configure automatically Resolves maintainer feedback to avoid root package.json complexity
3be08f2 to
237620b
Compare
|
hey @its-me-abhishek , Updated the PR based on your feedback!
Let me know if any adjustments are needed! |
its-me-abhishek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
This PR implements native Git pre-commit hooks to automatically format code before committing, with automated setup via npm postinstall script.
Changes made:
=> Created
.githooks/pre-commitfor native Git hook implementation=> Added
postinstallscript infrontend/package.jsonto automatically configure Git hooks onnpm install=> Pre-commit hook automatically runs:
npm run lint=> Updated
CONTRIBUTING.mdwith automated setup instructions=> Updated
development/README.mdto mention automatic Git hooks setup=> Removed
scripts/setup-git-hooks.shas hooks now configure automaticallyHow it works:
When contributors run
npm installin the frontend directory, thepostinstallscript automatically configures Git to use the.githooksdirectory. The pre-commit hook then:npm run pre-commit→npm run lint→npx prettier --write .for frontend filesgofmtfor backend Go filesThis ensures consistent code style without any manual setup or intervention.
Why this approach:
Based on maintainer feedback, this implementation:
=> Uses native Git hooks instead of Husky (avoids root package.json complexity)
=> Automatically configures on
npm install(no manual setup script needed)=> Follows the exact pattern suggested by the maintainer
Testing:
Tested with badly formatted frontend files - automatically formatted on commit
Verified hook only formats staged files
Confirmed hook executes before commit and re-stages formatted files
Gracefully handles missing gofmt (shows warning, doesn't fail)
Frontend tests pass (126 tests)
Fixes: Husky setup for running prettier automatically before committing #114
Checklist
npm run lint(for formatting)gofmt -w .(for Go backend) - Note: Go not installed on test system, but hook is configured correctlynpm test(for JS/TS testing) - All 126 tests passedAdditional Notes
For Contributors:
After pulling this PR, simply run
npm installin the frontend directory. The Git hooks will be automatically configured, and your code will be formatted on every commit.For Reviewers:
You can test the hook by:
npm installin the frontend directory to configure the hookfrontend/src/git addThis implementation matches the maintainer's requested approach exactly, using native Git hooks with automated setup via npm postinstall.