The-DevOps-Daily / The-DevOps-Daily/devops-daily

feat: Add pre-commit hooks with Husky

Open
#535 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement good first issue hacktoberfest
Dominant language
TypeScript
Stars
1.1k
Forks
392
Avg merge
5h 8m
Merged PRs (30d)
121

Description

Description

Set up Husky and lint-staged for automatic code quality checks before commits.

Problem

  • README mentions "Husky for pre-commit hooks" but no .husky/ directory exists
  • No automated checks before committing
  • Code style issues can be committed
  • Tests not run before push
  • Potential for broken commits to reach CI/CD

Current State

  • Prettier is configured (.prettierrc)
  • ESLint is configured (eslint.config.mjs)
  • No pre-commit automation

Proposed Solution

Install Husky with these hooks:

Pre-commit:

  • Run Prettier on staged files
  • Run ESLint on staged files
  • Run TypeScript type checking

Pre-push:

  • Run test suite (pnpm test)
  • Ensure no console.log statements (optional)

Acceptance Criteria

  • Install Husky and lint-staged
  • Configure pre-commit hook
  • Configure pre-push hook
  • Run Prettier on staged files
  • Run ESLint on staged files
  • Run TypeScript checks
  • Run tests before push
  • Update README with hook documentation
  • Add setup script in package.json
  • Test hooks work for new contributors

Implementation

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

Files to Create/Modify

  • package.json - Add dependencies and scripts
  • .husky/pre-commit - Pre-commit hook
  • .husky/pre-push - Pre-push hook
  • README.md - Update hook documentation

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with package.json, .prettierrc, and eslint.config.mjs to understand the existing scripts and checks. Then create the specified .husky/pre-commit and .husky/pre-push hooks and update README.md; run the hooks with the project’s pnpm commands and verify the listed acceptance criteria for a new contributor.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, typescript
Domain
ci-cd, developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.