Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code issue with Husky

I have configured husky in my project. It is running the pre-commit hook with "lint-staged" to use "prettier" to format the code before each commit. The configuration works fine when I use the terminal to invoke the git commit.

However, if I commit the files using VS Code source control panel to commit, it just commits without running the pre-commit hook. I am using windows 10. pre-commit file:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx "lint-staged"

package.json for "lint-staged"

"lint-staged":{
    "*.{js,json,css,md}": [
        "prettier --write"
    ]
}

VS Code source control panel

vscode source control panel

How do I solve this to invoke a pre-commit hook each time when git commit is called though it is from VS Code?

like image 675
dnaveen Avatar asked Sep 11 '25 00:09

dnaveen


1 Answers

Can you show the logs from vscode? To know how to do that you can look up what others did on this similar issue.

I think that if you modify the husky command and make it look like this:

"husky": {
  "hooks": {
    "pre-commit": "npx lint-staged"
  }
}

It will work.

like image 104
edu.nicastro Avatar answered Sep 12 '25 15:09

edu.nicastro