A lightweight Rust library and CLI tool for validating Git commit messages according to the Conventional Commits specification.
- β Validates commit messages against Conventional Commits v1.0.0
- π§ Configurable validation rules
- π Can be used as a library or CLI tool
- π Lightweight with minimal dependencies
- π― Supports all standard commit types
- π Detects breaking changes
- π Provides helpful error messages and examples
cargo install conventional-commits
git clone https://codeberg.org/slundi/conventional-commits
cd conventional-commits
cargo build --release# Validate a commit message commit-check --message "feat: add user authentication" # Read from stdin echo "fix: resolve login issue" | commit-check # Validate with verbose output commit-check --message "feat(auth): add OAuth support" --verbose
# Show examples of valid commits commit-check examples # Show available commit types commit-check types # Validate with custom configuration commit-check --message "feat: new feature" --max-length 50 --allow-custom-types=false
| Flag | Default | Description |
|---|---|---|
--max-length <N> |
72 |
Maximum description length |
--min-length <N> |
0 |
Minimum description length |
--allow-custom-types <BOOL> |
true |
Allow custom commit types |
--enforce-lowercase <BOOL> |
true |
Enforce lowercase first letter in description |
--disallow-period <BOOL> |
true |
Disallow period at end of description |
--scopes <SCOPES> |
β | Comma-separated list of allowed scopes |
--enforce-lowercase-scope <BOOL> |
false |
Reject scopes with uppercase letters |
--require-scope <BOOL> |
false |
Require a scope on every commit |
--issue-pattern <PATTERN> |
β | Regex that at least one footer must match |
--fix |
β | Auto-correct common header mistakes and print the result |
--format <text|json> |
text |
Output format |
--verbose |
β | Detailed output |
Automated tools (AI assistants, CI bots) often append trailers like Co-authored-by: or Signed-off-by: to commit bodies. Use clean rules to strip these lines before validation:
# Remove lines by prefix commit-check --message "$(cat .git/COMMIT_EDITMSG)" \ --clean-starts-with "Co-authored-by" \ --clean-starts-with "Signed-off-by" # Remove lines by regex (can be combined with starts-with rules) commit-check --message "$(cat .git/COMMIT_EDITMSG)" \ --clean-regex "^π€.*" # Both flags are repeatable and additive with rules from .commit-check.toml
Cleaning also collapses consecutive blank lines and trims trailing whitespace. Each removed line is printed as Removed: <line> so you can see what was stripped.
See Integration.
The Conventional Commits specification defines the following format:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
feat- A new featurefix- A bug fixdocs- Documentation only changesstyle- Changes that do not affect the meaning of the coderefactor- A code change that neither fixes a bug nor adds a featureperf- A code change that improves performancetest- Adding missing tests or correcting existing testsbuild- Changes to the build process or auxiliary toolsci- Changes to CI configuration files and scriptschore- Other changes that don't modify src or test filesrevert- Reverts a previous commit
feat: add email notifications
fix(auth): resolve token expiration issue
feat!: remove deprecated API endpoints
docs(readme): update installation instructions
feat: add user profiles
Allow users to create and customize their profiles
with avatar upload and bio sections.
Closes #123
BREAKING CHANGE: User model schema has changed
You can integrate this tool with Git hooks to automatically validate commit messages:
Create .git/hooks/commit-msg:
#!/bin/sh commit-check --message "$(cat "1γγ«")"
Make it executable:
chmod +x .git/hooks/commit-msg
Add to your .pre-commit-config.yaml:
repos: - repo: local hooks: - id: conventional-commits name: Conventional Commits entry: commit-check language: system stages: [commit-msg] args: ["--message"]
validate_commit(message: &str)- Validates a commit message with default configurationvalidate_commit_with_config(message: &str, config: &ValidationConfig)- Validates with custom configurationfix_commit_message(message: &str)- Auto-corrects common header mistakesclean_commit_body(message, starts_with_rules, regex_rules)- Strips unwanted body lines, collapses blank lines, trims trailing whitespace; returnsCleanResult
ConventionalCommit- Represents a parsed commitCommitType- Enum of commit typesValidationConfig- Configuration for validation rulesCommitValidationError- Error types for validation failuresCleanResult- Result ofclean_commit_body:cleaned_message+removed_lines
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
See Development
This project is licensed under the MIT License - see the LICENSE file for details.
- Conventional Commits specification
- commitlint for inspiration
- commitizen for reference implementation
The conventionnal commits checker is developed on Codeberg and mirrored to GitHub.
- Primary Repo: Codeberg main repo
- Mirror: GitHub repo