encode clippy rules in .cursorrules

This commit is contained in:
Greg Shuflin
2025-07-26 23:47:00 -07:00
parent 216708a19e
commit ffe6a7d8fa
+48
View File
@@ -8,3 +8,51 @@ When generating Rust code:
- Follow Rust formatting conventions strictly
- Use consistent indentation (4 spaces as configured in rustfmt.toml)
- Respect the max_width = 100 setting from rustfmt.toml
# Clippy Compliance Rules
When generating Rust code, ensure Clippy compliance by following these guidelines:
## General Best Practices:
- Use `&str` instead of `&String` for function parameters when possible
- Prefer `String::new()` over `String::from("")`
- Use `is_empty()` instead of `len() == 0` for collections
- Use `is_some()` and `is_none()` instead of `matches!(option, Some(_))`
- Prefer `if let` over `match` when only one pattern is needed
- Use `cloned()` instead of `map(|x| x.clone())` for iterators
## Error Handling:
- Use `?` operator instead of `unwrap()` or `expect()` when appropriate
- Prefer `Result<T, E>` over `Option<T>` for operations that can fail
- Use `map_err()` to convert error types instead of manual error handling
- Consider using `anyhow` or `thiserror` for error types when appropriate
## Performance:
- Use `&[T]` instead of `&Vec<T>` for function parameters
- Prefer `collect::<Vec<_>>()` over `collect()` when type inference is unclear
- Use `into_iter()` when consuming collections
- Avoid unnecessary allocations with `to_string()` when `to_owned()` suffices
## Code Style:
- Use `#[derive(Debug, Clone)]` when appropriate
- Prefer `const` over `static` for simple values
- Use `#[allow(clippy::...)]` sparingly and only with justification
- Avoid `#[allow(unused_variables)]` - use `_` prefix instead
- Use `#[allow(dead_code)]` only when necessary for public APIs
## Memory Safety:
- Prefer `&str` over `&String` for string slices
- Use `Cow<'a, str>` when you might need owned or borrowed strings
- Avoid `clone()` when not necessary
- Use `Arc` and `Mutex` appropriately for shared state
## Async/Await:
- Use `tokio::spawn` for spawning async tasks
- Prefer `tokio::select!` over manual polling
- Use `tokio::time::sleep` instead of `std::thread::sleep` in async contexts
- Handle cancellation properly with `tokio::select!`
## Testing:
- Use `#[cfg(test)]` for test modules
- Prefer `assert_eq!` and `assert_ne!` over `assert!`
- Use `#[test]` functions instead of manual test runners
- Consider using `proptest` for property-based testing when appropriate