Videos
hi there, I was trying to set up pre commit hook in my projects and I find it difficult although it's simple. why ?
-
There is not a proper blog or documentation for setting it in a standard way..
-
Which are already exists are outdated why bcz I often encounter the eslint.config.js does not exist error.
-
not properly define way that how to define those hooks like it should run eslint , prettier test cases (the standard procedure)
-
Most of the blogs are not detailed.
So if you have the lastest doc or something then do share.
» npm install husky
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.
I found an easier way to do this without having to initiate the installation of husky by myself.
I installed lint-staged and tested husky pre-commit hooks that was setup by it by running the following commands:
npx mrm@2 lint-staged
yarn install
The first line installs lint-staged and husky and adds the right sections with a sample script in the target package.json file for you to use or modify.
Stage and commit the target package.json into git (local git is enough). Make a change that should cause the eslint find errors and the commit to fail. Try committing again to test the lint-staged setup. Lint-staged should prevent the files from being committed this time around.
Husky can prevent you from bad git commit, git push, and more. If you are getting this error check your code syntax. In case you are getting this error even if your code is valid, please use the below solution.
#Solution 1:
Delete the .git/hooks folder and then do the npm install to reinstall husky. There are chances for conflicts with husky-generated files in the .git/hooks/ files.
#Solution 2:
this is a temporary/quick solution.
git commit -m "message" --no-verify
I find two temporary solution like that
git config --unset core.hooksPath
or
git commit -m "message" --no-verify