commitlint checks if your commit message meets the conventional commit format
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Download binary from releases and add it to your PATH
go install github.com/conventionalcommit/commitlint@latest
cd
to repository directorycommitlint init
commitlint init --global
--hookspath
with desired locationcommitlint init --hookspath /path/to/hooks
commitlint init --global --hookspath /path/to/hooks
commitlint hook create
to create .commitlint/hooks
containing git hooks
--hookspath
to customize the hooks output pathgit config core.hooksPath /path/to/.commitlint/hooks
git config --global core.hooksPath /path/to/.commitlint/hooks
echo "feat: good commit message" | commitlint lint
# ✔ commit message
echo "fear: do not fear for commit message" | commitlint lint
# ❌ type-enum: type 'fear' is not allowed, you can use one of [build chore ci docs feat fix merge perf refactor revert style test]
To create config file, run commitlint config create
this will create commitlint.yaml
To validate config file, run commitlint config check --config=/path/to/conf.yaml
To lint a message, you can use any one of the following
commitlint lint --message=file
echo "message" | commitlint lint
commitlint lint < file
commitlint lint
follows below order for config
and message
--config
command-line argumentCOMMITLINT_CONFIG
env variablestdin
pipe stream--message
command-line argument.git/COMMIT_EDITMSG
in current directorycommitlint hook create
To prints useful information for debugging commitlint
run commitlint debug
version: v0.9.0
formatter: default
rules:
- header-min-length
- header-max-length
- body-max-line-length
- footer-max-line-length
- type-enum
severity:
default: error
settings:
body-max-line-length:
argument: 72
footer-max-line-length:
argument: 72
header-min-length:
argument: 10
header-max-length:
argument: 50
type-enum:
argument:
- feat
- fix
- docs
- style
- refactor
- perf
- test
- build
- ci
- chore
- revert
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 |
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 |
footer-enum | []string | n/a | restrict footer token 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 |
footer-type-enum | []{token, types, values} | n/a | enforces footer notes for given type |
commitlint
→ input: "fear: do not fear for ..."
Errors:
❌ type-enum: type 'fear' is not allowed, you can use one of [build chore ci docs feat fix perf refactor revert style test]
Total 1 errors, 0 warnings, 0 other severities
{"input":"fear: do not fear for commit message","issues":[{"description":"type 'fear' is not allowed, you can use one of [build chore ci docs feat fix perf refactor revert style test]","name":"type-enum","severity":"error"}]}
How to have custom config for each repository?
Place .commitlint.yaml
file in repo root directory. linter follows config precedence.
To create a sample config, run commitlint config create
How can I skip lint check for a commit?
use --no-verify
flag with git commit
which skips commit hooks
All packages are licensed under MIT License