Skip to content

Add pre-commit hooks for lint and format commands #66

Closed
@bhouston

Description

@bhouston

Overview

Implement pre-commit hooks to automatically run the project's lint and format commands before each commit. This will help maintain code quality and consistency throughout the codebase.

Implementation Plan

  1. Install required dependencies:

    pnpm add -D husky lint-staged
  2. Add configuration to package.json:

    "lint-staged": {
      "*.{js,jsx,ts,tsx}": [
        "pnpm lint",
        "pnpm format"
      ]
    }
  3. Initialize husky:

    pnpm husky install
  4. Add a prepare script to package.json to ensure husky is installed on npm install:

    "scripts": {
      "prepare": "husky install"
    }
  5. Create a pre-commit hook:

    pnpm husky add .husky/pre-commit "pnpm lint-staged"
  6. Add documentation in CONTRIBUTING.md about the pre-commit hooks

Benefits

  • Ensures all committed code meets the project's style guidelines
  • Prevents formatting inconsistencies
  • Catches linting errors before they're committed
  • Reduces the need for style-related code review comments

Additional Notes

  • We should consider only running lint/format on staged files to improve performance
  • We may want to make the hooks skippable with a flag for emergency situations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions