commit-msg hook chạy sau khi developer viết commit message — có thể reject nếu message không hợp lệ.
Setup: npm i -D @commitlint/cli @commitlint/config-conventional, file .husky/commit-msg (Husky v9) chỉ chứa 1 dòng npx --no -- commitlint --edit $1.
commitlint.config.js:
js
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [2, "always", [
"feat", "fix", "docs", "style", "refactor",
"test", "chore", "perf", "ci", "build", "revert", "wip"
]],
"subject-max-length": [1, "always", 100], // warn, not error
"body-max-line-length": [0], // disable
}
};Cho phép WIP commits (không block nhưng vẫn có format): thêm "wip" vào type-enum → wip: payment refactor halfway pass.
Bypass khi thực sự cần (emergency): git commit --no-verify — bỏ qua TẤT CẢ client-side hooks.
Lưu ý: commitlint enforce trên client — developer vẫn có thể bypass bằng --no-verify. Server-side enforcement cần CI check (dùng commitlint trong GitHub Actions trên PR title).