chore: add husky pre-commit hook and configure lint-staged for code formatting#48
chore: add husky pre-commit hook and configure lint-staged for code formatting#48
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Husky pre-commit hooks and configures lint-staged to automatically format code before commits. It sets up automated code quality checks for both the Python backend (using Black and Ruff) and the TypeScript/JavaScript frontend (using ESLint).
Key changes:
- Adds Husky v9 and lint-staged v15 as development dependencies
- Configures lint-staged to run Black and Ruff on Python files, and ESLint on frontend files
- Creates a pre-commit hook that triggers lint-staged
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| package.json | Defines root-level dependencies for Husky and lint-staged, and configures lint-staged patterns for backend and frontend files |
| package-lock.json | Lockfile with all dependency versions and integrity hashes for Husky, lint-staged, and their transitive dependencies |
| .husky/pre-commit | Pre-commit hook script that executes lint-staged on staged files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "ruff check --fix" | ||
| ], | ||
| "src/frontend/**/*.{ts,tsx,js,jsx}": [ | ||
| "bash -c 'cd src/frontend && npx eslint --fix ${0}'" |
There was a problem hiding this comment.
The bash command for ESLint will not work correctly. When lint-staged passes file paths to this command, they will be passed as arguments (e.g., bash -c '...' arg1 arg2 arg3), but ${0} refers to the script name/path, not the arguments.
Additionally, since the command changes directory to src/frontend but receives file paths relative to the repository root (e.g., src/frontend/src/App.tsx), the paths won't resolve correctly.
Recommended fix - replace line 17 with:
"eslint --fix"This will work because lint-staged will execute this command from within src/frontend directory when the glob pattern matches, and eslint will receive the correct relative file paths.
| "bash -c 'cd src/frontend && npx eslint --fix ${0}'" | |
| "eslint --fix" |
Proposed changes
Add husky pre-commit hook
Types of changes
🐛 Bug fix (non-breaking change which fixes an issue)
✨ Feature (non-breaking change which adds functionality)
💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
📝 Docs (documentation only changes)
♻️ Refactor (code improvement without changing functionality)
Checklist
Docker build successful (src/backend)
All tests passing (pytest)
Code follows project standards (Black, Ruff, MyPy)
Service boundaries maintained
.env.example updated (if environment variables changed)
No debug print statements left