Skip to content

Setup Husky + Lint-staged for Git pre-commit code quality enforcement #152

Open
@EnkhsaikhanCh

Description

@EnkhsaikhanCh

🧹 Setup Husky + Lint-staged for Git pre-commit code quality enforcement

📄 Description

We need to enforce code formatting and linting at the time of Git commits to maintain clean, consistent, and error-free code. This task will integrate Husky for Git hooks and Lint-staged for running linters and formatters only on staged files.


✅ Tasks

  • Install husky and initialize Git hooks
  • Add prepare script in package.json
  • Set up Husky pre-commit hook to run lint-staged
  • Install and configure lint-staged in package.json
  • Add lint and format rules for the following file types:
    • *.ts, *.tsx: Run eslint --fix and prettier --write
    • *.json, *.md: Run prettier --write
  • Create a test commit with intentional format issues to verify enforcement
  • Update project README with basic usage and troubleshooting tips

📦 Commands to Run

# Step 1: Install Husky
npm install husky --save-dev
npx husky install
npm pkg set scripts.prepare="husky install"

# Step 2: Add pre-commit hook
npx husky add .husky/pre-commit "npx lint-staged"

# Step 3: Install lint-staged
npm install lint-staged --save-dev

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions