MANDATORY: All code must be properly formatted before committing. This project enforces strict formatting standards to maintain code consistency and readability.
Before every commit, you MUST:
-
Format your code:
cargo fmt --all
-
Verify formatting:
cargo fmt --all --check
-
Pass clippy checks:
cargo clippy --all-targets --all-features -- -D warnings
-
Ensure compilation:
cargo check --all-targets
We provide convenient Makefile targets for common tasks:
# Format all code
make fmt
# Check if code is properly formatted
make fmt-check
# Run clippy checks
make clippy
# Run compilation check
make check
# Run tests
make test
# Run all pre-commit checks (format + clippy + check + test)
make pre-commit
# Setup git hooks (one-time setup)
make setup-hooksThis project includes a pre-commit hook that automatically runs before each commit to ensure:
- ✅ Code is properly formatted (
cargo fmt --all --check) - ✅ No clippy warnings (
cargo clippy --all-targets --all-features -- -D warnings) - ✅ Code compiles successfully (
cargo check --all-targets)
Run this command once after cloning the repository:
make setup-hooksOr manually:
chmod +x .git/hooks/pre-commitThe project uses the following rustfmt configuration (defined in rustfmt.toml):
max_width = 130
fn_call_width = 90
single_line_let_else_max_width = 100If your code doesn't meet the formatting requirements, the pre-commit hook will:
- Block the commit and show clear error messages
- Provide exact commands to fix the issues
- Guide you through the resolution process
Example output when formatting fails:
❌ Code formatting check failed!
💡 Please run 'cargo fmt --all' to format your code before committing.
🔧 Quick fix:
cargo fmt --all
git add .
git commit
- Make your changes
- Format your code:
make fmtorcargo fmt --all - Run pre-commit checks:
make pre-commit - Commit your changes:
git commit -m "your message" - Push to your branch:
git push
Install the rust-analyzer extension and add to your settings.json:
{
"rust-analyzer.rustfmt.extraArgs": ["--config-path", "./rustfmt.toml"],
"editor.formatOnSave": true,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}Configure your IDE to:
- Use the project's
rustfmt.tomlconfiguration - Format on save
- Run clippy checks
- Never bypass formatting checks - they are there for a reason
- All CI/CD pipelines will also enforce these same checks
- Pull requests will be automatically rejected if formatting checks fail
- Consistent formatting improves code readability and reduces merge conflicts
# Check if hook is executable
ls -la .git/hooks/pre-commit
# Make it executable if needed
chmod +x .git/hooks/pre-commit# Format all code
cargo fmt --all
# Check specific issues
cargo fmt --all --check --verbose# See detailed clippy output
cargo clippy --all-targets --all-features -- -D warnings
# Fix automatically fixable issues
cargo clippy --fix --all-targets --all-featuresFollowing these guidelines ensures high code quality and smooth collaboration across the RustFS project! 🚀