I'm using Husky. I have:
"scripts": {
"precommit": "lint-staged --verbose",
"commit": "git-cz",
},
"lint-staged": {
"*.js": [
"prettier --single-quote --semi=false --write",
"eslint --fix",
"git add"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
At first I thought perhaps the precommit script isn't needed anymore, so I remove the it and lint-staged doesn't run at all. Then I decided to commit without commitizen and realized that's where the problem is. lint-staged is called once before the commitizen command line form appears, and again after you submit it. Is that the expected behavior? What can be done about it?
If you always commit using npm run commit you could add lint-staged before calling git-cz and remove the precommit hook. I would not advise doing this, though.
Regarding running twice: it should not. Looking at your config I can't see the reason for that. So you should investigate and create a reproducible example on GitHub if the problem is with this package.
I have same issue here
https://github.com/Hotell/typescript-lib-starter

ha! so this isn't definitely issue with this library, rather than husky is the culprit here. I guess you can close this @okonet
https://github.com/typicode/husky/issues/110
Maybe it should be stated in your docs? If you're ok with that I'll submit PR
thanks!
PR would be awesome! Thanks for investigating.
Is there an issue in the husky repository to fix this?
this is fixed with latest husky 鉁岋笍
yarn add husky@next
"scripts": {
-"cz": "git-cz",
+"commit": "git-cz",
-"precommit": "lint-staged"
},
+"husky": {
+ "hooks": {
+ "pre-commit": "lint-staged"
+ }
+ }
humm so @Hotell juts to confirm steps to get this working:
"devDependencies": {
"cz-conventional-changelog": "^2.1.0",
"husky": "^0.14.3",
},
"commit": "git-cz",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
is all you need?
Because when I run git cz with the above config, it goes straight to commitizen and does not run any test.
@wearefridayhutber I get the same. My approach has been to simply run a specific script before husky.
"devDependencies": {
"cz-conventional-changelog": "^2.1.0",
"husky": "^0.14.3",
},
"scripts": {
"commit": "lint-staged && git-cz --no-verify",
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
The --no-verify flag prevents husky from being run after commitizen.
Or
"devDependencies": {
"cz-conventional-changelog": "^2.1.0",
"husky": "^0.14.3",
},
"scripts": {
"pre-commit": "lint staged",
"commit": "yarn run pre-commit && git-cz --no-verify",
},
"husky": {
"hooks": {
"pre-commit": "yarn pre-commit"
}
},
This approach ensures that husky is run before commitizen (but not after) and before a vanilla git commit
This seems to be happening again with [email protected]. @jcarroll2007's fix from the above comment seems to do the trick, though.
Most helpful comment
this is fixed with latest husky 鉁岋笍