Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

husky pre-commit hook not triggering

Tags:

git

husky

I am having an issue with husky. I would like for husky to run eslint and prettier at the point at which git commit is about to be done so that it can enforce clean coding checks. I have already setup eslint, prettier and integrated both. They are working fine when used manually. However, husky allows a commit if one of the eslint rules is violated.

I also renamed the pre-commit.sample file in my local project's .git/hooks directory to pre-commit.

This is my package.json file:

  "scripts": {
    "prettier-format": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' --write",
    "lint": "eslint . --ext .ts"
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run prettier-format && npm run lint"
    }
  },
  "devDependencies": {
    "husky": "^7.0.1"
  }

Please, what could be the problem here? Thank you very much.

like image 529
sage Avatar asked Jun 16 '26 23:06

sage


1 Answers

I think for this to work with husky v7, you need to move what you want to run pre-commit into a file called .husky/pre-commit. husky v7 won't use the configuration from your package.json. See here for upgrading from v4 to v7.

like image 174
Rin Avatar answered Jun 18 '26 12:06

Rin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!