Back to Rustfs

Rust Code Quality Checklist

.agents/skills/rust-code-quality/references/checklist.md

1.0.0-beta.72.4 KB
Original Source

Rust Code Quality Checklist

Use this as a quick pre-merge checklist for every Rust code change.

Critical (P0 — block merge)

CheckCommand
No unwrap() in request/storage hot pathrg '\.unwrap\(\)' <files> | grep -v test
No as truncation on user inputrg ' as (u32|usize|i32)' <files>
Lock order consistent across call sitesManual: trace all lock acquisitions
Recursive functions have depth limitManual: check for max_depth or iterative pattern
No panic!/unwrap_or_else(panic!) in productionrg 'panic!|unwrap_or_else.*panic' <files> | grep -v test

High (P1 — must fix)

CheckCommand
No Result<_, String> in public APIrg 'Result<.*String>' <files> | grep -v test
No Box<dyn Error> in public traitrg 'Box<dyn.*Error' <files> | grep -v test
No unnecessary .clone() in hot pathManual: check loops and per-request paths
Error::source() implemented when inner error storedManual: check impl Error
No eprintln!/println! in productionrg 'println!|eprintln!' <files> | grep -v test

Medium (P2 — should fix)

CheckCommand
Tests have assertionsManual: check for assert in test functions
HashMap/Vec use with_capacity when size knownManual: check ::new() in loops
No #![allow(dead_code)] at crate rootrg 'allow.dead_code' <files> | grep 'lib.rs'
Serde structs from untrusted input have deny_unknown_fieldsManual: check #[derive(Deserialize)]

Low (P3 — nice to fix)

CheckCommand
No camelCase staticsrg 'static ref [a-z]' <files>
Arc::ptr_eq instead of as_ptr + ptr::eqrg 'as_ptr|ptr::eq' <files>
Public functions have doc commentsrg 'pub fn' <files> | grep -v '///'

Quick One-Liner

bash
# Run all automated checks on changed files
CHANGED=$(git diff --name-only HEAD~1 -- '*.rs' | grep -v test | grep -v bench)
echo "=== unwrap/expect ===" && rg -c '\.unwrap\(\)|\.expect\(' $CHANGED 2>/dev/null
echo "=== as casts ===" && rg -c ' as (u8|u16|u32|u64|usize|i8|i16|i32|i64|isize)\b' $CHANGED 2>/dev/null
echo "=== String errors ===" && rg -c 'Result<.*String>' $CHANGED 2>/dev/null
echo "=== println ===" && rg -c 'println!|eprintln!' $CHANGED 2>/dev/null
echo "=== Ordering::Relaxed ===" && rg -c 'Ordering::Relaxed' $CHANGED 2>/dev/null