chore: add Husky formatting hooks#621
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds Husky-based Git hooks and supporting npm scripts so contributor formatting commands run automatically on commit and push, and documents the new workflow in CONTRIBUTING.md. Sequence diagram for Husky formatting hooks on commit and pushsequenceDiagram
actor Developer
participant Git
participant Husky
participant NpmScripts
participant Biome
Developer->>Git: git commit
Git->>Husky: Trigger pre-commit hook
Husky->>NpmScripts: npm run format
NpmScripts->>Biome: biome format --write .
Biome-->>NpmScripts: Formatting completed
NpmScripts-->>Husky: Exit status
Husky-->>Git: Allow or block commit
Git-->>Developer: Commit succeeds or fails
Developer->>Git: git push
Git->>Husky: Trigger pre-push hook
Husky->>NpmScripts: npm run format:check
NpmScripts->>Biome: biome format .
Biome-->>NpmScripts: Report formatting issues
NpmScripts-->>Husky: Exit status
Husky-->>Git: Allow or block push
Git-->>Developer: Push succeeds or fails
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Running
npm run formatover the entire repo in the pre-commit hook may become slow as the project grows; consider switching to formatting only staged files (e.g., vialint-stagedor a similar mechanism) to keep commit workflows snappy. - Double-check that the
.husky/pre-commitand.husky/pre-pushscripts explicitly invokenpm run formatandnpm run format:checkrespectively and have the executable bit set, so contributors don’t hit confusing no-op or permission issues on first install.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Running `npm run format` over the entire repo in the pre-commit hook may become slow as the project grows; consider switching to formatting only staged files (e.g., via `lint-staged` or a similar mechanism) to keep commit workflows snappy.
- Double-check that the `.husky/pre-commit` and `.husky/pre-push` scripts explicitly invoke `npm run format` and `npm run format:check` respectively and have the executable bit set, so contributors don’t hit confusing no-op or permission issues on first install.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
This PR introduces Husky Git hooks to enforce Biome formatting locally, adding a non-mutating formatting check on push and documenting the new workflow for contributors.
Changes:
- Added Husky as a dev dependency and enabled automatic hook installation via the
preparescript. - Introduced a
format:checknpm script and wired it into apre-pushhook. - Added a
pre-commithook to run formatting and updatedCONTRIBUTING.mdto describe the new behavior.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Adds prepare, format:check, and Husky dependency to support local Git hooks. |
| package-lock.json | Locks Husky dependency metadata for reproducible installs. |
| CONTRIBUTING.md | Documents the new Husky hook behavior and the new formatting script. |
| .husky/pre-push | Runs the formatting check before allowing pushes. |
| .husky/pre-commit | Runs auto-formatting and blocks commit if changes are detected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,6 @@ | |||
| npm run format | |||
kaungmyatshwe1397
left a comment
There was a problem hiding this comment.
@PhilixTheExplorer
It will be better to keep the hook behavior focused on one job. So, contributors do not run the same formatting logic in multiple places. Apart from that, the PR looks good.
| @@ -0,0 +1 @@ | |||
| npm run format:staged | |||
| @@ -0,0 +1 @@ | |||
| npm run format:changed | |||
| "@biomejs/biome": "2.4.11", | ||
| "autoprefixer": "^10.5.0", | ||
| "husky": "^9.1.7", | ||
| "lint-staged": "^16.4.0", |
| ``` | ||
|
|
||
| This also installs the project's Husky Git hooks for your local clone. The hooks run `npm run format:staged` before commits and `npm run format:changed` before pushes. | ||
|
|
| "lint": "biome lint .", | ||
| "format": "biome format --write .", | ||
| "format:check": "biome format .", | ||
| "format:changed": "biome format --changed --since=main --no-errors-on-unmatched", |
|
@PhilixTheExplorer please link this PR to an issue |
Mateeb-Haider
left a comment
There was a problem hiding this comment.
@PhilixTheExplorer, please add a related issue for better traceability,this will help reviewers and new contributors understand the reason behind the change.
|
I’ve created and linked the related enhancement issue #626 now, so the PR has the required issue context. |
kaungmyatshwe1397
left a comment
There was a problem hiding this comment.
@PhilixTheExplorer
Pleases resolve Copilot's concern.
| "format": "biome format --write .", | ||
| "format:check": "biome format .", | ||
| "format:changed": "biome format --changed --since=origin/main --no-errors-on-unmatched", | ||
| "format:staged": "biome format --write --staged --no-errors-on-unmatched", |
| #!/usr/bin/env sh | ||
| set -e | ||
|
|
||
| npm run format:changed |
| #!/usr/bin/env sh | ||
| set -e | ||
|
|
||
| npm run format:staged |
| "url": "git+https://github.com/fossasia/scrum_helper.git" | ||
| }, | ||
| "scripts": { | ||
| "prepare": "husky", |
| @@ -0,0 +1,4 @@ | |||
| #!/usr/bin/env sh | |||
|
Closing this for now because the hook workflow needs more careful design around staged-file formatting, Node version compatibility, and contributor environments. I’ll revisit this later with a smaller, clearer approach. |
📌 Fixes
Fixes #626
📝 Summary of Changes
preparescript sonpm installinstalls Husky hooks automatically.format:checkscript for non-mutating formatting checks.format:stagedscript that formats staged source files through lint-staged.format:changedscript that checks formatting for files changed againstmain.npm run format:staged.npm run format:changed.CONTRIBUTING.mdwith the new hook behavior and formatting commands.📸 Screenshots / Demo (if UI-related)
N/A
✅ Checklist
👀 Reviewer Notes
This is a tooling-only change. The hooks are scoped to local contributor workflows: pre-commit formats staged source files with lint-staged, and pre-push checks formatting for files changed against
main.npm run format:checkwas run locally and passes.Summary by Sourcery
Add Husky-based Git hooks to enforce code formatting in local workflows and document the updated contributor experience.
Build:
Documentation:
Chores: