Skip to content

chore: add husky pre-commit hook with lint-staged#660

Open
hydrosquall wants to merge 1 commit intovega:masterfrom
hydrosquall:cameron.yick/add-pre-commit-lint-hooks
Open

chore: add husky pre-commit hook with lint-staged#660
hydrosquall wants to merge 1 commit intovega:masterfrom
hydrosquall:cameron.yick/add-pre-commit-lint-hooks

Conversation

@hydrosquall
Copy link
Member

@hydrosquall hydrosquall commented Feb 8, 2026

Motivation

This PR adds pre-commit hooks to catch formatting issues locally before CI, reduce wasted CI minutes, and ensure consistent code style across the codebase (related to vega/vega#4237).

Changes

  • Upgrades husky from v7.0.0 to v9.1.7 for git hooks management
  • Upgrades lint-staged from v10.0.3 to v16.2.7 to run linters only on staged files
  • Configures pre-commit hook to run npx lint-staged && npm test
  • Adds "prepare": "husky" script to auto-initialize hooks on npm install
  • Configures lint-staged to run eslint --fix on *.{js,ts,tsx,mjs,cjs} files
  • Updates .gitignore to exclude .claude/ directory

Testing

  • Run npm install to verify the prepare script initializes husky
  • Make a change to a JS/TS/TSX file with a formatting issue
  • Stage and commit the change
  • Verify the pre-commit hook runs and auto-fixes the formatting issue
  • Verify tests run as part of pre-commit
  • Verify CI passes

Enable formatting issues to be automatically handled locally
instead of only erroring in CI, reducing wasted CI minutes.

Related to vega/vega#4237

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
@@ -0,0 +1 @@
npx lint-staged && npm test
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't running tests slow down commits significantly? I am okay with linting but would be hesitant about running tests in precommit unless we have a way to only run affected tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants