diff --git a/.coderabbit.yml b/.coderabbit.yml new file mode 100644 index 0000000..8a57812 --- /dev/null +++ b/.coderabbit.yml @@ -0,0 +1,6 @@ +reviews: + path_filters: + - "**/*.yml" + - "**/*.yaml" + - "**/*.toml" + - "**/*.rs" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e51fa37 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "clippy_test" +version = "0.1.0" +edition = "2021" + + diff --git a/src/app/example.rs b/src/app/example.rs new file mode 100644 index 0000000..7935773 --- /dev/null +++ b/src/app/example.rs @@ -0,0 +1,42 @@ +fn main() { + // Unnecessary clone + let x = String::from("hello"); + let y = x.clone(); // Clippy will warn here about the unnecessary clone + println!("{}", y); + + // Unused variable + let unused_var = 42; // Clippy will warn about this + + // Possible panic on unwrap + let result: Result = Err("error"); + + + // // NEED TO TEST FURTHER, MIGHT CAUSE "cause a runtime panic" + // // https://github.com/coderabbitai/pr-reviewer_test/pull/10606#discussion_r2087234807 + // let value = result.unwrap(); // This would trigger clippy::unwrap_used + + // Instead, use pattern matching or the ? operator + let value = match result { + Ok(v) => v, + Err(e) => { + eprintln!("Error: {}", e); + -1 // Providing a default value for the example + } + }; + + // Redundant reference + let z = &y; // Clippy might suggest removing the reference here + println!("{}", z); + + // Inefficient `for` loop + let vec = vec![1, 2, 3, 4]; + for i in vec.iter() { // Clippy may suggest using a `for` loop by value + println!("{}", i); + } + + // Excessive type annotation + let a: i32 = 5; // Clippy will suggest removing the type annotation since it's obvious + + // Missing documentation + let un_documented_function = |x: i32| x * 2; // Clippy may warn about missing documentation +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..dcadbe8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,11 @@ +fn main() { + let x: Vec = vec![]; + let y = x.len() == 0; + + let mut a = 5; + a = a; + + let name = String::from("clippy"); + println!("Name: {}", &name[..]); +} +