Skip to content

Commit 2f8aac3

Browse files
committed
Fix formatting and update clippy allow attributes
- Apply proper code formatting to Java security analysis - Update clippy allow attributes in Java, Python, and Rust analyzers - Update rust.mdc rules documentation These changes resolve pre-commit formatting issues and ensure consistent code style across the language analysis modules.
1 parent 43342c0 commit 2f8aac3

4 files changed

Lines changed: 1284 additions & 747 deletions

File tree

.cursor/rules/rust.mdc

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,49 @@ pub fn read_config(path: &Path) -> Config {
3838
}
3939
```
4040

41+
**Rule: Use doc test features to ensure examples remain accurate and demonstrate different scenarios.**
42+
Why: Doc tests are automatically run by `cargo test`, ensuring examples never become outdated. Use different doc test attributes to show various use cases and error conditions.
43+
44+
**Run doc tests with:** `cargo test --doc` or `cargo test` (includes all tests)
45+
46+
**Doc test best practices:**
47+
```rust
48+
/// Parses configuration from various sources.
49+
///
50+
/// # Examples
51+
///
52+
/// Basic usage:
53+
/// ```
54+
/// let config = parse_config("app.toml")?;
55+
/// assert!(config.port > 0);
56+
/// # Ok::<(), ConfigError>(())
57+
/// ```
58+
///
59+
/// This example doesn't run but shows the API:
60+
/// ```no_run
61+
/// let config = parse_config("/etc/myapp/config.toml")?;
62+
/// deploy_with_config(config);
63+
/// # Ok::<(), Box<dyn std::error::Error>>(())
64+
/// ```
65+
///
66+
/// Demonstrating error handling:
67+
/// ```should_panic
68+
/// let config = parse_config("nonexistent.toml").unwrap();
69+
/// ```
70+
///
71+
/// Hidden setup code (lines starting with #):
72+
/// ```
73+
/// # use std::fs;
74+
/// # fs::write("test.toml", "port = 8080").unwrap();
75+
/// let config = parse_config("test.toml")?;
76+
/// assert_eq!(config.port, 8080);
77+
/// # fs::remove_file("test.toml").unwrap();
78+
/// # Ok::<(), ConfigError>(())
79+
/// ```
80+
pub fn parse_config(path: &str) -> Result<Config, ConfigError> {
81+
// Implementation
82+
}
83+
4184
**Rule: Create specific error types instead of using generic errors.**
4285
Why: Specific errors enable proper error handling by callers and provide better debugging information. Use `thiserror` to reduce boilerplate.
4386

@@ -66,17 +109,26 @@ pub fn process_user_data(id: u32) -> Result<UserProfile, UserError> {
66109

67110
## Documentation Standards
68111

69-
**Rule: Every public function, struct, and module must have rustdoc comments.**
70-
Why: Documentation is part of the API contract. Good docs prevent misuse, reduce support burden, and make your code maintainable. Include examples and error conditions.
112+
**Rule: Every public function, struct, and module must have rustdoc comments with working code examples.**
113+
Why: Documentation is part of the API contract. Good docs prevent misuse, reduce support burden, and make your code maintainable. Code examples are automatically tested by `cargo test`, ensuring documentation stays accurate.
71114

72-
**Every public item needs rustdoc:**
115+
**Every public item needs rustdoc with examples:**
73116
```rust
74117
/// Represents a user in the system.
75118
///
76119
/// # Examples
120+
///
121+
/// Creating a valid user:
77122
/// ```
78123
/// let user = User::new("alice@example.com", "Alice Smith")?;
79124
/// assert_eq!(user.email(), "alice@example.com");
125+
/// assert_eq!(user.name(), "Alice Smith");
126+
/// # Ok::<(), UserError>(())
127+
/// ```
128+
///
129+
/// Handling invalid email:
130+
/// ```should_panic
131+
/// let user = User::new("invalid-email", "Alice Smith").unwrap();
80132
/// ```
81133
///
82134
/// # Errors
@@ -89,6 +141,15 @@ pub struct User {
89141

90142
impl User {
91143
/// Creates a new user with validated email.
144+
///
145+
/// # Examples
146+
/// ```
147+
/// use my_crate::User;
148+
///
149+
/// let user = User::new("bob@example.com", "Bob Jones")?;
150+
/// assert!(user.email().contains("@"));
151+
/// # Ok::<(), my_crate::UserError>(())
152+
/// ```
92153
pub fn new(email: impl Into<String>, name: impl Into<String>) -> Result<Self, UserError> {
93154
let email = email.into();
94155
validate_email(&email)?;
@@ -291,7 +352,8 @@ Before outputting Rust code, verify:
291352
- [ ] Compiles without warnings
292353
- [ ] Uses Result<T, E> for fallible operations
293354
- [ ] No unwrap() in production paths
294-
- [ ] Public items have rustdoc comments
355+
- [ ] Public items have rustdoc comments with working examples
356+
- [ ] Doc tests demonstrate both success and error cases
295357
- [ ] Includes basic unit tests
296358
- [ ] Uses appropriate derives
297359
- [ ] Validates external inputs

0 commit comments

Comments
 (0)