commitlint

Lint commit messages.

Usage

In general the pattern mostly looks like this:

type(scope?): subject

scope is optional; multiple scopes are supported (current delimiter options: "/", "\" and ",")

fix(server): send cors headers

Common types according to commitlint-config-conventional can be:

  • build: Builds - Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • chore: Chores - Other changes that don't modify src or test files
  • ci: Continuous Integrations - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • docs: Documentation - Documentation only changes
  • feat: Features - A new feature
  • fix: Bug Fixes - A bug fix
  • perf: Performance Improvements - A code change that improves performance
  • refactor: Code Refactoring - A code change that neither fixes a bug nor adds a feature
  • revert: Reverts - Reverts a previous commit
  • style: Styles - Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Tests - Adding missing tests or correcting existing tests

Integration with husky

Install commitlint cli and conventional config.

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

Configure commitlint to use conventional config.

echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

Add hook:

cat <<EEE > .husky/commit-msg
#!/bin/sh
. "\$(dirname "\$0")/_/husky.sh"

npx --no -- commitlint --edit "\${1}"
EEE

Make hook executable

chmod a+x .husky/commit-msg

Integration with pre-commit

A pre-commit hook for commitlint

repos:
  - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
    rev: v8.0.0
    hooks:
      - id: commitlint
        stages: [commit-msg]
        additional_dependencies: ['@commitlint/config-conventional']