| name | code-quality-check |
| description | This skill should be used before committing code to ensure it meets Breenix quality standards. Use for running clippy checks, fixing compiler warnings, verifying no log side-effects, checking for dead code, and enforcing project coding standards from CLAUDE.md. |
Code Quality Checks for Breenix
Pre-commit code quality verification for Breenix kernel development.
Purpose
Breenix enforces strict code quality standards. This skill provides the checks and fixes required before committing code.
Core Quality Standards (from CLAUDE.md)
- Fix ALL compiler warnings before committing
- Fix ALL clippy warnings
- Use proper patterns (e.g.,
Once) to avoid unsafe warnings
- Only
#[allow(dead_code)] for legitimate API functions
Pre-Commit Checklist
Before every commit:
cd kernel
cargo build --target x86_64-unknown-none 2>&1 | grep warning
cargo clippy --target x86_64-unknown-none
cd ..
cargo test
grep -R "log::trace!.*(" kernel/src/ | grep -vE '\".*\"' | grep -vE '\.(as_|to_|into_|len|is_|get)'
Clippy Configuration
Project-Specific Clippy Flags
cd kernel
RUSTFLAGS="-Aclippy::redundant_closure_for_method_calls" \
cargo clippy --target x86_64-unknown-none \
-- -Dclippy::debug_assert_with_mut_call \
-Dclippy::print_stdout \
-Wclippy::suspicious_operation_groupings
What These Check
debug_assert_with_mut_call: Prevent side-effects in debug assertions
print_stdout: No print!/println! in kernel (use log! macros)
suspicious_operation_groupings: Catch likely logic errors
Common Issues and Fixes
Compiler Warnings
Unused imports:
use x86_64::{VirtAddr, PageTable, PageTableFlags};
use x86_64::{VirtAddr, PageTableFlags};
Unused variables:
let result = some_function();
let _result = some_function();
some_function();
Dead code:
fn helper_function() { ... }
#[allow(dead_code)]
pub fn dealloc_stack(&mut self, stack_id: usize) { ... }
Clippy Warnings
Redundant closure:
items.map(|x| x.to_string())
items.map(ToString::to_string)
Debug assert with mutation:
debug_assert!(list.pop().is_some());
let item = list.pop();
debug_assert!(item.is_some());
Log Side-Effects
Problem: Function calls in log statements execute even when logging disabled.
log::trace!("State: {:?}", get_state());
let state = get_state();
log::trace!("State: {:?}", state);
if log::log_enabled!(log::Level::Trace) {
let state = expensive_get_state();
log::trace!("State: {:?}", state);
}
CI Code Quality Workflow
The .github/workflows/code-quality.yml runs these checks automatically:
- Clippy checks with project-specific flags
- Log side-effects scan for trace statements with function calls
- Complex log expression check for multi-argument format strings
- Log level regression guard - ensures feature flags control log level
Quick Reference
Before Commit
cd kernel
cargo build --target x86_64-unknown-none 2>&1 | tee /tmp/build-warnings.txt
cargo clippy --target x86_64-unknown-none 2>&1 | tee /tmp/clippy-warnings.txt
grep warning /tmp/build-warnings.txt
less /tmp/clippy-warnings.txt
Common Warning Fixes
| Warning | Fix |
|---|
| unused import | Remove from use statement |
| unused variable | Prefix with _ or remove |
| dead code | Remove or add #[allow(dead_code)] for API |
| redundant closure | Allow via RUSTFLAGS or fix |
| print_stdout | Replace print! with log::info! |
| debug_assert mutation | Extract to separate statement |
Integration with Git Workflow
git status
cd kernel
cargo clippy --target x86_64-unknown-none
git add kernel/src/...
git commit -m "Fix: ..."
Best Practices
- Fix warnings as you go: Don't accumulate them
- Run clippy frequently: Catch issues early
- Use proper logging: log! macros, not print!
- Avoid side-effects in logs: Especially in trace/debug
- Comment allowed dead code: Explain why it's part of the API
- Use feature flags: Control debug vs release behavior
- Test before committing: cargo test if touching core code
Summary
Code quality standards enforce:
- Zero compiler warnings
- Zero clippy warnings
- No side-effects in log statements
- Appropriate use of #[allow] attributes
- Proper logging practices
Run checks before every commit to maintain high code quality.