Skip to content

[DevOps/DX] Setup Pre-commit hooks using Husky & Lint-staged #202

@yash-pouranik

Description

@yash-pouranik

Description

Currently, our monorepo does not enforce linting rules before a commit is made. This means contributors might accidentally push code with formatting errors, trailing spaces, or unused variables, which then requires manual fixes or fails in CI.

To maintain high code quality and improve our Developer Experience (DX), we need to implement Husky and lint-staged. This will automatically run our linter on staged files right before a commit is created. If the linter fails, the commit will be blocked until the issues are fixed.

What needs to be done (Tasks)

  • Install husky and lint-staged as development dependencies in the root package.json.
  • Initialize husky in the repository (this will create a .husky folder).
  • Create a pre-commit hook inside .husky/ that triggers npx lint-staged.
  • Add a lint-staged configuration block in the root package.json (or a .lintstagedrc file) to run ESLint on all staged JavaScript/React files (*.js, *.jsx).
    • Hint: It should run npm run lint --workspace=web-dashboard (or equivalent eslint command) only on the files that are staged.
  • Update package.json scripts to include "prepare": "husky install" so that husky hooks are automatically set up when someone runs npm install.

Where to look

  • Root package.json
  • apps/web-dashboard/package.json (to see the existing lint commands)

Why this is important

This is a standard industry practice that saves reviewers time and ensures the urBackend codebase stays clean and consistent!

Skills Required

  • Basic knowledge of Node.js & package.json
  • Git Hooks
  • ESLint / Code Linting concepts

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions