Crates.io | conventional-commits-check |
lib.rs | conventional-commits-check |
version | 0.9.1 |
created_at | 2025-08-22 15:37:49.379989+00 |
updated_at | 2025-08-22 18:15:56.52926+00 |
description | A lightweight library and CLI tool for validating Conventional Commits |
homepage | |
repository | https://codeberg.org/slundi/conventional-commits |
max_upload_size | |
id | 1806527 |
size | 76,449 |
A lightweight Rust library and CLI tool for validating Git commit messages according to the Conventional Commits specification.
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
--max-length <N>
: Maximum description length (default: 72)--allow-custom-types <BOOL>
: Allow custom commit types (default: true)--enforce-lowercase <BOOL>
: Enforce lowercase description (default: true)--disallow-period <BOOL>
: Disallow period at end of description (default: true)--verbose
: Enable detailed outputAdd to your Cargo.toml
:
[dependencies]
conventional-commits = "0.1.0"
use conventional_commits::{validate_commit, CommitType};
fn main() {
let message = "feat: add user authentication";
match validate_commit(message) {
Ok(commit) => {
println!("Valid commit!");
println!("Type: {:?}", commit.commit_type);
println!("Description: {}", commit.description);
if commit.is_breaking_change() {
println!("⚠️ Breaking change detected!");
}
}
Err(e) => {
eprintln!("Invalid commit: {}", e);
}
}
}
use conventional_commits::{validate_commit_with_config, ValidationConfig};
let config = ValidationConfig {
max_description_length: 50,
allow_custom_types: false,
enforce_lowercase_description: true,
disallow_description_period: true,
};
let result = validate_commit_with_config("feat: add feature", &config);
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 commitfeat: 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 configurationConventionalCommit
- Represents a parsed commitCommitType
- Enum of commit typesValidationConfig
- Configuration for validation rulesCommitValidationError
- Error types for validation failuresContributions 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.
# Make scripts executable
chmod +x scripts/*.sh
# Run comprehensive tests
make test
# Run only unit tests
make test-unit
# Run tests safely with build step
make test-safe
# Format code
cargo fmt
# Run clippy
cargo clippy
This project is licensed under the MIT License - see the LICENSE file for details.