commitlint
commitlint checks if your commit messages meets the conventional commit format
Table of Contents
Installation
Releases
Download binary from releases and add it to your PATH
Using go
go install github.com/conventionalcommit/commitlint@latest
Enable in Git Repo
Quick Test
# invalid commit message
echo "fear: do not fear for commit message" | commitlint lint
# ❌ type-enum: type 'fear' is not allowed, you can use one of [feat fix docs style refactor perf test build ci chore revert merge]
# valid commit message
echo "feat: good commit message" | commitlint lint
# ✔ commit message
Benefits of using conventional commit
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Commit Types
Commonly used commit types from Conventional Commit Types
Type |
Description |
feat |
A new feature |
fix |
A bug fix |
docs |
Documentation only changes |
style |
Changes that do not affect the meaning of the code (white-space, formatting etc) |
refactor |
A code change that neither fixes a bug nor adds a feature |
perf |
A code change that improves performance |
test |
Adding missing tests or correcting existing tests |
build |
Changes that affect the build system or external dependencies |
ci |
Changes to our CI configuration files and scripts |
chore |
Other changes that don't modify src or test files |
revert |
Reverts a previous commit |
merge |
Merges a branch |
Commands
Custom config for each repo
-
run commitlint create config
in repo root directory
this will create commitlint.yaml
in that directory, you can customise the config to your need
Verify config file
Rules
The list of available lint rules
name |
argument |
flags |
description |
header-min-length |
int |
n/a |
checks the min length of header (first line) |
header-max-length |
int |
n/a |
checks the max length of header (first line) |
body-max-line-length |
int |
n/a |
checks the max length of each line in body |
footer-max-line-length |
int |
n/a |
checks the max length of each line in footer |
type-enum |
[]string |
n/a |
restrict type to given list of string |
scope-enum |
[]string |
allow-empty: bool |
restrict scope to given list of string |
type-min-length |
int |
n/a |
checks the min length of type |
type-max-length |
int |
n/a |
checks the max length of type |
scope-min-length |
int |
n/a |
checks the min length of scope |
scope-max-length |
int |
n/a |
checks the max length of scope |
description-min-length |
int |
n/a |
checks the min length of description |
description-max-length |
int |
n/a |
checks the max length of description |
body-min-length |
int |
n/a |
checks the min length of body |
body-max-length |
int |
n/a |
checks the max length of body |
footer-min-length |
int |
n/a |
checks the min length of footer |
footer-max-length |
int |
n/a |
checks the max length of footer |
type-charset |
string |
n/a |
restricts type to given charset |
scope-charset |
string |
n/a |
restricts scope to given charset |
Library
Config Precedence
commitlint.yaml
config file in current directory
- config file passed with
--config
command-line argument
- default config
Commit Message Precedence
stdin
pipe stream
- commit message file passed with
--message
command-line argument
.git/COMMIT_EDITMSG
in current directory
Default Config
formatter: default
rules:
header-min-length:
enabled: true
severity: error
argument: 10
header-max-length:
enabled: true
severity: error
argument: 50
body-max-line-length:
enabled: true
severity: error
argument: 72
footer-max-line-length:
enabled: true
severity: error
argument: 72
type-enum:
enabled: true
severity: error
argument:
- feat
- fix
- docs
- style
- refactor
- perf
- test
- build
- ci
- chore
- revert
- merge
License
All packages are licensed under MIT License