Enforce clean commit messages
Consistent commit messages make history searchable, power automatic changelogs, and let tools like semantic-release decide version bumps. commitlint checks each message against a ruleset, and this builder generates a commitlint.config.js that extends the conventional preset with your own type list, scope rules, and length limits.
How it works
The config exports an object that extends @commitlint/config-conventional, giving you the standard Conventional Commits parser and defaults. Your custom rules then refine that baseline. Each rule is a tuple [level, applicability, value]: the level is 2 for error, 1 for warning, or 0 to disable; applicability is always or never; the value is the rule’s argument.
type-enum restricts the allowed types — feat, fix, docs, and so on. scope-enum optionally limits scopes to a fixed list, and scope-empty set to never makes a scope mandatory. subject-case enforces casing, subject-empty requires a subject, and subject-full-stop forbids a trailing period. header-max-length and body-max-line-length cap line lengths so messages stay readable in git tooling.
A message like feat(api): add pagination to search endpoint passes; Added stuff. fails on type, case, and full-stop rules.
Tips and notes
- Wire this config to a Husky commit-msg hook so it runs on every commit.
- Keep
header-max-lengthat 72 to match git log conventions. - Leave scopes empty to allow any scope, or list them to standardize across a team.
- Run commitlint in CI too, since local hooks can be bypassed with
--no-verify.