| title | Quality Gates - AllSource Core | |||
|---|---|---|---|---|
| status | CURRENT | |||
| last_updated | 2026-02-02 | |||
| version | 1.0 | |||
| related |
|
MSRV: Rust 1.70.0
This document describes the quality gates enforced for AllSource Core to maintain code quality, consistency, and reliability.
Quality gates are automated checks that must pass before code can be merged. They enforce:
- Code formatting standards (rustfmt)
- Code quality standards (clippy)
- Dependency organization (cargo-sort)
- Test coverage (cargo test)
- Build verification (cargo build)
# Run all quality gates (recommended before commit)
make check
# Auto-fix formatting and sorting
make format
make format-sort
# Full CI pipeline locally
make ci# Check formatting (no changes)
make lint
# Check Cargo.toml sorting (no changes)
make lint-sort
# Auto-format code
make format
# Auto-sort Cargo.toml
make format-sort
# Run tests
make test
# Build project
make buildEnforce consistent code style across the entire codebase using rustfmt.
File: apps/core/rustfmt.toml
edition = "2021"
max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Unix"
# Import organization
reorder_imports = true
reorder_modules = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
# Formatting
remove_nested_parens = true
format_strings = true
format_macro_matchers = true
format_macro_bodies = true
# Comments
normalize_comments = true
normalize_doc_attributes = true
wrap_comments = true
comment_width = 80cargo fmt --checkcargo fmt- ✅ Code indentation (4 spaces, no tabs)
- ✅ Line width (max 100 characters)
- ✅ Import organization (std → external → crate)
- ✅ Comment formatting (max 80 characters)
- ✅ Macro formatting
- ✅ String formatting
Failure: Line too long
// ❌ BEFORE (110 characters)
let result = some_very_long_function_name_that_exceeds_the_maximum_line_width(arg1, arg2, arg3, arg4);
// ✅ AFTER (auto-formatted)
let result = some_very_long_function_name_that_exceeds_the_maximum_line_width(
arg1, arg2, arg3, arg4,
);Failure: Imports not organized
// ❌ BEFORE
use crate::domain::entities::Event;
use std::sync::Arc;
use serde::{Serialize, Deserialize};
// ✅ AFTER (auto-formatted)
use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::domain::entities::Event;Catch common mistakes, anti-patterns, and performance issues using Rust's official linter.
File: apps/core/.clippy.toml
msrv = "1.70.0"
warn-on-all-wildcard-imports = truecargo clippy --all-targets --all-features -- -D warnings--all-targets: Check lib, bins, tests, benches--all-features: Enable all feature flags (postgres, rocksdb)-D warnings: Treat all warnings as errors (zero tolerance)
- ✅ Wildcard imports (
use foo::*;→ forbidden) - ✅ Unused variables
- ✅ Unnecessary clones
- ✅ Inefficient loops
- ✅ Missing documentation
- ✅ Type complexity
- ✅ Redundant pattern matching
- ✅ Performance anti-patterns
Failure: Wildcard import
// ❌ FORBIDDEN
use crate::domain::entities::*;
// ✅ REQUIRED
use crate::domain::entities::{Event, EventStream, Projection};Failure: Unnecessary clone
// ❌ BEFORE
fn process_event(event: &Event) {
let event_clone = event.clone(); // clippy: unnecessary clone
do_something(event_clone);
}
// ✅ AFTER
fn process_event(event: &Event) {
do_something(event); // Pass by reference
}Failure: Unused variable
// ❌ BEFORE
fn load_stream(id: &str) -> Result<Stream> {
let stream = repository.load(id)?;
let version = stream.version(); // clippy: unused variable
Ok(stream)
}
// ✅ AFTER
fn load_stream(id: &str) -> Result<Stream> {
let stream = repository.load(id)?;
let _version = stream.version(); // Prefix with _ to suppress warning
Ok(stream)
}Maintain alphabetically sorted dependencies in Cargo.toml for easier navigation and merge conflict reduction.
File: apps/core/cargo-sort.toml
sort = true
expand = true
group_imports = truecargo sort --checkcargo sort -w- ✅
[dependencies]sorted alphabetically - ✅
[dev-dependencies]sorted alphabetically - ✅
[build-dependencies]sorted alphabetically - ✅ Feature flags sorted
Before:
[dependencies]
serde = "1.0"
tokio = "1.36"
arrow = "53.3"After (auto-sorted):
[dependencies]
arrow = "53.3"
serde = "1.0"
tokio = "1.36"Ensure all unit and integration tests pass before code is merged.
cargo test --lib- ✅ All unit tests in
src/**/*.rspass - ✅ All doc tests pass
- ✅ No test panics
- ✅ Test coverage maintained
apps/core/src/
├── domain/
│ ├── entities/
│ │ ├── event.rs # Contains #[cfg(test)] mod tests
│ │ ├── event_stream.rs # Contains #[cfg(test)] mod tests
│ └── value_objects/
│ ├── tenant_id.rs # Contains #[cfg(test)] mod tests
├── application/
│ └── use_cases/
│ ├── manage_schema.rs # Contains #[cfg(test)] mod tests
└── infrastructure/
└── repositories/
├── in_memory_event_stream_repository.rs # Contains #[cfg(test)] mod tests
- Domain layer: 100% coverage required
- Application layer: 90%+ coverage required
- Infrastructure layer: 80%+ coverage required
Verify the project compiles successfully in release mode.
cargo build --lib --release- ✅ Project compiles without errors
- ✅ All dependencies resolve correctly
- ✅ Feature flags work correctly
- ✅ Release optimizations don't break compilation
File: .github/workflows/rust-quality.yml
Triggers:
- Push to
mainordevelopbranches - Pull requests to
mainordevelopbranches - Changes in
apps/core/**paths
Jobs:
-
quality-gates - Full quality gate pipeline
- Format check (rustfmt)
- Cargo.toml sort check (cargo-sort)
- Lint check (clippy -D warnings)
- Test execution (cargo test --lib)
- Build verification (cargo build --lib --release)
-
msrv-check - Minimum Supported Rust Version check
- Verifies compilation with Rust 1.70.0
name: Rust Quality Gates
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
quality-gates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- run: cargo install cargo-sort
- run: cargo fmt --check
- run: cargo sort --check
- run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo test --lib
- run: cargo build --lib --release# Install pre-commit hook
cd apps/core
cat > .git/hooks/pre-commit << 'HOOK'
#!/bin/bash
cd apps/core
make check
HOOK
chmod +x .git/hooks/pre-commitAutomatically runs make check before every commit, preventing broken code from being committed.
| Command | Description | Exit Code |
|---|---|---|
make help |
Show all available commands | - |
make check |
Run all quality gates | 0 = pass, 1 = fail |
make ci |
Full CI pipeline (check + build) | 0 = pass, 1 = fail |
make lint |
Check formatting + clippy | 0 = pass, 1 = fail |
make lint-sort |
Check Cargo.toml sorting | 0 = pass, 1 = fail |
make format |
Auto-format code | - |
make format-sort |
Auto-sort Cargo.toml | - |
make test |
Run all tests | 0 = pass, 1 = fail |
make build |
Build project | 0 = pass, 1 = fail |
make clean |
Clean build artifacts | - |
Before starting work:
make format
make format-sortBefore committing:
make check # Must pass before commitBefore pushing:
make ci # Full pipeline verification⚠️ NEVER bypass in normal development⚠️ Only in critical production incidents⚠️ Must be approved by 2+ maintainers⚠️ Must be fixed in follow-up PR within 24 hours
# WARNING: Use only in emergencies!
git commit --no-verify -m "EMERGENCY: fix critical prod issue"# Add [skip ci] to commit message
git commit -m "EMERGENCY: critical fix [skip ci]"Cause: Code not formatted according to rustfmt.toml
Fix:
make format # Auto-fix formatting
git add .
git commitCause: Code quality issues detected by clippy
Fix:
# See all warnings
cargo clippy --all-targets --all-features
# Fix suggested changes manually
# OR use clippy auto-fix (use with caution)
cargo clippy --fix --all-targets --all-featuresCause: Dependencies not alphabetically sorted
Fix:
make format-sort # Auto-sort Cargo.toml
git add Cargo.toml
git commitCause: Different Rust version or cached artifacts
Fix:
# Clean and rebuild
make clean
rustup update
make checkCause: Feature flags or dependencies missing in CI
Fix:
- Check
.github/workflows/rust-quality.yml - Ensure all required dependencies in
Cargo.toml - Verify feature flags are configured correctly
# Always pass quality gates locally first
make check && git commit# Let tools fix what they can
make format
make format-sort
# Then review changes
git diff// Don't silence warnings unless absolutely necessary
#![allow(clippy::some_lint)] // ❌ Avoid
// Instead, fix the underlying issue
// ✅ Proper fix// Add tests in same file using #[cfg(test)]
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_feature() {
// Test implementation
}
}# After adding dependencies
cargo add some-crate
make format-sort# 1. Edit rustfmt.toml
nano apps/core/rustfmt.toml
# 2. Reformat all code
make format
# 3. Verify no regressions
make check# 1. Edit .clippy.toml
nano apps/core/.clippy.toml
# 2. Run clippy with new config
make lint
# 3. Fix any new warnings
# (may require code changes)# 1. Edit .clippy.toml
# msrv = "1.75.0" # Update version
# 2. Update CI workflow
# .github/workflows/rust-quality.yml
# - uses: dtolnay/[email protected]
# 3. Test with new MSRV
rustup install 1.75.0
rustup default 1.75.0
make check