Quick reference for daily use.
# Search for secrets
rg "(?i)(password|secret|api_key|token|private_key).*=.*['\"]" --type rust
# Search for SQL injections
rg "format!.*SELECT|execute.*&format!" --type rust
# Search for command injections
rg "Command::new.*format!" --type rustChecklist:
- No hardcoded credentials
- SQL queries parameterized
- All input data validated
- auth_date checked for replay attack protection
- No weak algorithms (MD5, SHA1)
# Find all unwrap/expect/panic
rg "\.unwrap\(\)|\.expect\(|panic!" --type rust --glob '!tests'Rule: No panic in production code (only Result).
// Long chains
let value = parse(input).map_err(E::A)?.validate().map_err(E::B)?;
// Readable code
let Ok(value) = parse(input) else { return Err(E::A); };
let Ok(value) = value.validate() else { return Err(E::B); };Rule: let-else for multiple steps, map_err for single step.
# Nested loops (potential O(n^2))
rg "for.*\{[\s\S]{1,200}for" --type rust
# Vec::new without with_capacity
rg "Vec::new\(\)" --type rust
# contains in loop
rg "\.contains\(" --type rust
# Unnecessary clone
rg "\.clone\(\)" --type rustQuestions:
- Parsing happens once?
- with_capacity used for Vec?
- No O(n^2) where O(n) is possible?
- Iterators used instead of intermediate Vec?
- No secrets in code
- No unwrap/expect
- Input data validated
- No SQL/Command injections
- No obvious O(n^2)
- No duplicate operations
- Vec::with_capacity where needed
- No code duplication (> 3 times)
- Functions < 50 lines
- Sensible variable names
- Tests for new logic
// BAD
fn validate(raw: &str, hash: &str) -> bool {
compute_hash(raw) == hash // No time check!
}
// GOOD
fn validate(raw: &str, hash: &str, max_age: u64) -> bool {
check_timestamp(raw, max_age) && compute_hash(raw) == hash
}// BAD - parsing twice
fn validate(raw: &str) -> bool {
let data = parse(raw); // 1
check(data);
hash(raw) // parse() called inside again! 2
}
// GOOD
fn validate(raw: &str) -> bool {
let data = parse(raw); // 1 time
check(&data);
hash(&data) // pass reference
}// BAD
for id in ids {
let user = db.get(id).await; // N queries
}
// GOOD
let users = db.get_many(ids).await; // 1 query// BAD
fn process(data: Vec<String>) -> usize {
data.len() // Takes ownership needlessly
}
// GOOD
fn process(data: &[String]) -> usize {
data.len()
}# All unwrap/expect
rg "\.unwrap\(\)|\.expect\(" --type rust --glob '!tests'
# Magic numbers
rg "\b[0-9]{3,}\b" --type rust
# TODO/FIXME
rg "TODO|FIXME" --type rust
# Long functions (>50 lines)
# (needs script or manual check)# Test coverage
cargo tarpaulin --out Xml
# Clippy
cargo clippy -- -D warnings
# Formatting
cargo +nightly fmt --check
# Tests
cargo test
# Benchmarks
cargo bench- Security vulnerabilities
- Panic in production
- Logic errors
- Broken tests
- Performance issues (>10% degradation)
- Code duplication (>3 times)
- Missing tests for critical logic
- Refactoring for readability
- Additional tests
- Documentation improvements
- "This is bad"
- "Redo this"
- "There's a problem here"
- "SQL injection possible on line 42. Use parameterized query:
query_as!(...)" - "This function is called in a loop, giving O(n^2). Can use HashMap for O(n)"
- "No auth_date check - replay attack vulnerability. Add time validation per Telegram docs"
Formula:
- What is wrong
- Why it's a problem
- How to fix (or suggest options)
- Security
- Panic/unwrap
- Obvious bugs
- Duplicate operations
- Inefficient algorithms
- Unnecessary allocations
- Code duplication
- Readability
- Tests
- Documentation
- Architecture
- Edge cases in tests
- Long-term maintainability
## Security
- [ ] auth_date validation missing (replay attack) - line 42
- [ ] SQL injection in `get_user()` - line 156
## Performance
- [ ] Double parsing of initData - lines 50, 75
- [ ] O(n^2) in `remove_duplicates()` - line 200
## Quality
- [ ] Hash computation duplicated 3 times - suggest extract function
- [ ] Missing tests for error cases
## Suggestions
- Consider using HashMap instead of Vec::find for O(1) lookups
- Add doc comments for public API- Open PR -> view diff
- Security (5 min):
rgsecrets, unwrap, injections
- Performance (5 min):
- Duplication, O(n^2), allocations
- Quality (5 min):
- DRY, readability, tests
- Write comments - specific with solutions
- Approve or Request Changes
Total: 15-20 minutes for typical PR
See details in: