Zero-config commitlint frontend for conventional commits
npm install conventional-commit-msgZero-config commitlint frontend for conventional commits.
Validates commit messages against the Conventional Commits specification using @commitlint/config-conventional.
1. Create .githooks/commit-msg:
``bash`
#!/bin/sh
npx -y conventional-commit-msg "$1"
2. Make it executable and enable the hooks directory:
`bash`
chmod +x .githooks/commit-msg
git config core.hooksPath .githooks
Now every commit message will be validated automatically.
`bashValidate last commit
npx -y conventional-commit-msg --last
Options
| Option | Description |
| --------------- | ----------------------------------- |
|
| Commit message file (git hook mode) |
| --last | Validate the last commit |
| --from | Start of commit range (CI mode) |
| --to | End of commit range (CI mode) |
| -v, --verbose | Show output on success |
| -V, --version | Output the version number |
| -h, --help | Display help for command |Pipeline Examples
`bash
Check if last commit is valid (for CI scripts)
npx -y conventional-commit-msg --last && echo "Valid" || echo "Invalid"Validate message from a file (silent on success, shows errors)
cat .git/COMMIT_EDITMSG | npx -y conventional-commit-msgValidate multiple messages from a file (one per line)
while IFS= read -r msg; do
echo "$msg" | npx -y conventional-commit-msg || echo "Invalid: $msg"
done < messages.txt
``MIT