Categorygithub.com/conventionalcommit/commitlint
repositorypackage
0.10.1
Repository: https://github.com/conventionalcommit/commitlint.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

PkgGoDev

commitlint

commitlint checks if your commit message meets the conventional commit format

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Table of Contents

Installation

Releases

Download binary from releases and add it to your PATH

Using go

go install github.com/conventionalcommit/commitlint@latest

Setup

  • Enable for a single git repository, cd to repository directory
commitlint init
  • Enable globally for all git repositories
commitlint init --global
  • to customize hooks destination pass --hookspath with desired location
commitlint init --hookspath /path/to/hooks
commitlint init --global --hookspath /path/to/hooks

Manual

  • run commitlint hook create to create .commitlint/hooks containing git hooks
    • pass --hookspath to customize the hooks output path
  • To enable in single repo
    • run git config core.hooksPath /path/to/.commitlint/hooks
  • To enable globally
    • run git config --global core.hooksPath /path/to/.commitlint/hooks

Quick Test

  • Valid commit message
echo "feat: good commit message" | commitlint lint
# ✔ commit message
  • 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 [build chore ci docs feat fix merge perf refactor revert style test]

Commands

config

  • 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

lint

To lint a message, you can use any one of the following

  • run commitlint lint --message=file
  • run echo "message" | commitlint lint
  • run commitlint lint < file

Precedence

commitlint lint follows below order for config and message

Config
  • config file passed to --config command-line argument
  • COMMITLINT_CONFIG env variable
  • config file in current directory or git repo root in the below order
    • .commitlint.yml
    • .commitlint.yaml
    • commitlint.yml
    • commitlint.yaml
  • default config
Message
  • stdin pipe stream
  • commit message file passed to --message command-line argument
  • .git/COMMIT_EDITMSG in current directory

hook

  • To create hook files, run commitlint hook create

debug

To prints useful information for debugging commitlint

run commitlint debug

Default Config

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

Commit Types

Commonly used commit types from Conventional Commit Types

TypeDescription
featA new feature
fixA bug fix
docsDocumentation only changes
styleChanges that do not affect the meaning of the code (white-space, formatting etc)
refactorA code change that neither fixes a bug nor adds a feature
perfA code change that improves performance
testAdding missing tests or correcting existing tests
buildChanges that affect the build system or external dependencies
ciChanges to our CI configuration files and scripts
choreOther changes that don't modify src or test files
revertReverts a previous commit

Available Rules

The list of available lint rules

nameargumentflagsdescription
header-min-lengthintn/achecks the min length of header (first line)
header-max-lengthintn/achecks the max length of header (first line)
body-max-line-lengthintn/achecks the max length of each line in body
footer-max-line-lengthintn/achecks the max length of each line in footer
type-enum[]stringn/arestrict type to given list of string
scope-enum[]stringallow-empty: boolrestrict scope to given list of string
footer-enum[]stringn/arestrict footer token to given list of string
type-min-lengthintn/achecks the min length of type
type-max-lengthintn/achecks the max length of type
scope-min-lengthintn/achecks the min length of scope
scope-max-lengthintn/achecks the max length of scope
description-min-lengthintn/achecks the min length of description
description-max-lengthintn/achecks the max length of description
body-min-lengthintn/achecks the min length of body
body-max-lengthintn/achecks the max length of body
footer-min-lengthintn/achecks the min length of footer
footer-max-lengthintn/achecks the max length of footer
type-charsetstringn/arestricts type to given charset
scope-charsetstringn/arestricts scope to given charset
footer-type-enum[]{token, types, values}n/aenforces footer notes for given type

Available Formatters

  • default
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
  • JSON
{"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"}]}

Extensibility

FAQ

  • 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

License

All packages are licensed under MIT License