API Reference

CLI Commands

install

Install git commit-msg hook for commit message validation.

cargo commitlint install

Installs a git hook that automatically validates commit messages using cargo commitlint.

uninstall

Remove git commit-msg hook.

cargo commitlint uninstall

Removes the commit-msg hook installed by cargo commitlint install.

check

Validate a commit message.

cargo commitlint check [OPTIONS]

Options:
  -m, --message <MESSAGE>    Commit message to validate
  -c, --config <CONFIG>      Path to configuration file
  -h, --help                 Print help

If --message is not provided, the commit message will be read from stdin. This is useful for git hooks.

# Examples:
cargo commitlint check --message "feat: add feature"
echo "fix: bug" | cargo commitlint check
cargo commitlint check --message "docs: update" --config ./custom.toml

Exit Codes

  • 0 - Success (commit message is valid)
  • 1 - Error (commit message validation failed or other error)

Configuration File Format

Configuration files use TOML format. See the Configuration page for detailed options.

[rules]
[rules.type]
enum = ["feat", "fix", "docs"]
case = "lowercase"

[rules.scope]
enum = []
case = "lowercase"

subject_case = ["sentence-case"]
header_max_length = 72

[parser]
pattern = "^(?P<type>\w+)(?:\((?P<scope>[^)]+)\))?(?P<breaking>!)?:\s(?P<subject>.*)$"

ignores = []

Environment Variables

Currently, cargo-commitlint does not use any environment variables. All configuration is done via TOML files or command-line arguments.