Skip to content

Commit

Permalink
feat(config): check if the commit message is a conventional commit
Browse files Browse the repository at this point in the history
- For the husky v.8 not use the `.huskyrc` file for set the configuration.
Set the configuration inside the `.husky` folder, in the individual files as the `commit-msg` hook.
https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v8

Steps:
- Add the next command to the `commit-msg` hook:
`npx --no -- commitlint --edit $1`

Error:
- Error: Cannot find module "@commitlint/config-conventional" from "/Applications/MAMP/htdocs/vue-todolist" at resolveId (/Users/beatrizsmerino/.npm/_npx/16d437951fea4b5e/node_modules/@commitlint/resolve-extends/src/index.ts:131:14)
- ✖   body's lines must not be longer than 100 characters [body-max-line-length]
✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Solution:
- Install locally the packages:
`npm install @commitlint/cli @commitlint/config-conventional --save-dev`
`npm install commitizen cz-conventional-changelog --save-dev`
- Update the configuration `commitlint`, increase the `body-max-line-length`

References:
- https://www.youtube.com/watch?v=jNxDNoYEGVU
- https://www.youtube.com/watch?v=OJqUWvmf4gg
- https://gist.github.com/qoomon/5dfcdf8eec66a051ecd85625518cfd13
- https://github.com/qoomon/git-conventional-commits
- https://remarkablemark.org/blog/2019/05/29/git-husky-commitlint/
- https://typicode.github.io/husky/#/?id=husky_git_params-ie-commitlint-
- https://stackoverflow.com/a/67074398
- https://rahulgurung.com/How-to-use-the-latest-Husky-8-with-Commitizen-for-adding-git-hooks-to-your-projects/
- https://www.techiediaries.com/git-hooks-husky-commitlint/
- https://www.freecodecamp.org/news/how-to-use-commitlint-to-write-good-commit-messages/
- https://medium.com/dottech/mejorando-los-mensajes-de-git-commit-con-husky-y-commitlint-7bddf6ab22c2
- commitizen/cz-cli#289
- https://github.com/conventional-changelog/commitlint
- conventional-changelog/commitlint#613
- https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/config-conventional/index.js
- https://github.com/conventional-changelog/commitlint/blob/master/docs/reference-rules.md#body-max-line-length
  • Loading branch information
beatrizsmerino committed Aug 15, 2022
1 parent 2d46888 commit d8bfa38
Show file tree
Hide file tree
Showing 4 changed files with 2,215 additions and 659 deletions.
15 changes: 11 additions & 4 deletions .commitlintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module.exports = {
extends: [
{
"extends": [
"@commitlint/config-conventional"
]
};
],
"rules": {
"body-max-line-length": [
2,
"always",
2000
]
}
}
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

echo "pre-received"
npx --no -- commitlint --edit "$1"
Loading

0 comments on commit d8bfa38

Please sign in to comment.