lint-staged not running on precommit Ask Question

lint-staged not running on precommit Ask Question

prettier is not running on precommit. This worked with the same configuration in other projects, so I'm baffled why it's not working this time.

This is the relevant section of my package.json file:

"scripts": {
    "precommit": "lint-staged"
  },
"lint-staged": {
  "*.{js,json,css,scss,html,md}": [
    "prettier --write",
    "git add"
  ]
},

Edit. Here are the relevant devDependencies:

"devDependencies": {
  "husky": "^0.14.3",
  "lint-staged": "^7.0.4",
  "prettier": "1.12.0"
},

ベストアンサー1

I tried so many solutions on here but a combination finally worked!

  1. Make sure Husky v4 is installed. v6 was never triggering for me.
  2. Check the output of git config core.hooksPath. This should not return anything. If it does run,
git config --unset core.hookspath

そしてついにそれがうまくいきました!

おすすめ記事