Recipe

Commitlint Setup

Enforce conventional commit messages across your team with commitlint and husky. Stop “fix stuff” commits before they reach your repo.

Install

npm install --save-dev @commitlint/cli @commitlint/config-conventional husky

Config

Create commitlint.config.js:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2,
      'always',
      ['feat', 'fix', 'docs', 'chore', 'refactor', 'test', 'ci'],
    ],
  },
}

Hook

Wire husky to run commitlint on every commit:

npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'

Verify

Try a bad commit message. It should be rejected. Valid examples: feat: add login, fix: resolve timeout.