Skip to content

Configure Husky pre-commit hooks #40

@haljac

Description

@haljac

Problem

Husky v9 is installed as a dev dependency but is not configured — there is no .husky/ directory. Developers can commit code that fails lint or format checks, which then fails in CI. Catching these issues locally saves CI time and reduces failed PR builds.

Scope of Work

1. Initialize Husky

npx husky init

This creates the .husky/ directory and a sample pre-commit hook.

2. Configure pre-commit hook

Create .husky/pre-commit that runs:

  • npx lint-staged (preferred) or npm run lint && npm run format -- --check

3. Add lint-staged (recommended)

Install lint-staged and configure in package.json:

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

This only checks staged files rather than the entire codebase, keeping the hook fast.

Acceptance Criteria

  • .husky/ directory exists with a working pre-commit hook
  • Pre-commit hook runs lint and format checks on staged files
  • lint-staged is installed and configured (or equivalent approach)
  • Hook runs in under 5 seconds for typical commits
  • npm ci (fresh install) sets up hooks automatically via Husky's prepare script
  • Documentation in README or CONTRIBUTING.md explains the hook setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions