Skip to main content

ADR-0050: Husky for Git Hooks

Status

Accepted - 2025-01-26


Context

Enforce code quality checks before commits and pushes to prevent broken code.


Decision

Husky 9.x for Git hooks management.

Rationale

  1. Simple: Easy setup with pnpm exec husky init
  2. Fast: Runs only on staged files (lint-staged)
  3. Enforced: Pre-commit hook prevents bad commits
  4. CI Alignment: Same checks as CI

Setup

# Install
pnpm add -D husky lint-staged

# Initialize
pnpm exec husky init

Pre-Commit Hook

# .husky/pre-commit
pnpm lint-staged

Lint-Staged Config

// package.json
{
"lint-staged": {
"*.{ts,tsx}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,yaml}": [
"prettier --write"
]
}
}

Hooks

  1. pre-commit - Lint + format staged files
  2. pre-push - Run tests
  3. commit-msg - Validate commit message format

References