Skip to content

chore: add Husky formatting hooks#621

Closed
PhilixTheExplorer wants to merge 5 commits into
fossasia:mainfrom
PhilixTheExplorer:chore/add-husky-format-hooks
Closed

chore: add Husky formatting hooks#621
PhilixTheExplorer wants to merge 5 commits into
fossasia:mainfrom
PhilixTheExplorer:chore/add-husky-format-hooks

Conversation

@PhilixTheExplorer
Copy link
Copy Markdown
Contributor

@PhilixTheExplorer PhilixTheExplorer commented May 5, 2026

📌 Fixes

Fixes #626


📝 Summary of Changes

  • Added Husky Git hooks for local contributor workflows.
  • Added Husky and lint-staged as development dependencies.
  • Added a prepare script so npm install installs Husky hooks automatically.
  • Added a format:check script for non-mutating formatting checks.
  • Added a format:staged script that formats staged source files through lint-staged.
  • Added a format:changed script that checks formatting for files changed against main.
  • Added a pre-commit hook that runs npm run format:staged.
  • Added a pre-push hook that runs npm run format:changed.
  • Updated CONTRIBUTING.md with the new hook behavior and formatting commands.

📸 Screenshots / Demo (if UI-related)

N/A


✅ Checklist

  • I’ve tested my changes locally
  • I’ve added tests (if applicable)
  • I’ve updated documentation (if applicable)
  • My code follows the project’s code style guidelines

👀 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:check was 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:

  • Add Husky as a dev dependency and configure a prepare script to install Git hooks automatically.

Documentation:

  • Update CONTRIBUTING.md to describe automatic Husky hooks and the new format:check command.

Chores:

  • Introduce pre-commit and pre-push Husky hooks to run formatting and non-mutating format checks before commits and pushes.

Copilot AI review requested due to automatic review settings May 5, 2026 15:41
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds 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 push

sequenceDiagram
  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
Loading

File-Level Changes

Change Details Files
Introduce Husky Git hooks wired into existing Biome formatting commands and npm lifecycle.
  • Add a prepare script so Husky is installed automatically on npm install
  • Add a non-writing format:check script using biome format without --write
  • Add Husky devDependency and update package-lock.json accordingly
  • Create pre-commit hook that runs npm run format before committing
  • Create pre-push hook that runs npm run format:check before pushing
package.json
package-lock.json
.husky/pre-commit
.husky/pre-push
Document the new Husky-driven formatting workflow for contributors.
  • Explain that npm install installs Husky hooks and when they run
  • Document npm run format:check as a read-only formatting check command
CONTRIBUTING.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 prepare script.
  • Introduced a format:check npm script and wired it into a pre-push hook.
  • Added a pre-commit hook to run formatting and updated CONTRIBUTING.md to 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.

Comment thread .husky/pre-commit Outdated
@@ -0,0 +1,6 @@
npm run format
Comment thread .husky/pre-commit Outdated
Copy link
Copy Markdown
Contributor

@kaungmyatshwe1397 kaungmyatshwe1397 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copilot AI review requested due to automatic review settings May 6, 2026 13:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Comment thread .husky/pre-commit
@@ -0,0 +1 @@
npm run format:staged
Comment thread .husky/pre-push
@@ -0,0 +1 @@
npm run format:changed
Comment thread package.json Outdated
"@biomejs/biome": "2.4.11",
"autoprefixer": "^10.5.0",
"husky": "^9.1.7",
"lint-staged": "^16.4.0",
Comment thread CONTRIBUTING.md
Comment on lines 26 to +29
```

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.

Comment thread package.json Outdated
"lint": "biome lint .",
"format": "biome format --write .",
"format:check": "biome format .",
"format:changed": "biome format --changed --since=main --no-errors-on-unmatched",
@hpdang
Copy link
Copy Markdown
Member

hpdang commented May 8, 2026

@PhilixTheExplorer please link this PR to an issue

Copy link
Copy Markdown
Contributor

@Mateeb-Haider Mateeb-Haider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhilixTheExplorer, please add a related issue for better traceability,this will help reviewers and new contributors understand the reason behind the change.

@PhilixTheExplorer
Copy link
Copy Markdown
Contributor Author

I’ve created and linked the related enhancement issue #626 now, so the PR has the required issue context.

Copy link
Copy Markdown
Contributor

@kaungmyatshwe1397 kaungmyatshwe1397 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhilixTheExplorer
Pleases resolve Copilot's concern.

Copilot AI review requested due to automatic review settings May 14, 2026 15:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Comment thread package.json
"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",
Comment thread .husky/pre-push
#!/usr/bin/env sh
set -e

npm run format:changed
Comment thread .husky/pre-commit
#!/usr/bin/env sh
set -e

npm run format:staged
Comment thread package.json
"url": "git+https://github.com/fossasia/scrum_helper.git"
},
"scripts": {
"prepare": "husky",
Comment thread .husky/pre-commit
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
@PhilixTheExplorer
Copy link
Copy Markdown
Contributor Author

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.

@PhilixTheExplorer PhilixTheExplorer deleted the chore/add-husky-format-hooks branch May 14, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config dependencies Pull requests that update a dependency file documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Add Husky formatting hooks for contributor workflow

6 participants