Skip to content

Commit

Permalink
suggest is_some_and instead of map_or in `case_sensitive_file_ext…
Browse files Browse the repository at this point in the history
…ension_comparions`
  • Loading branch information
lapla-cogito committed Mar 6, 2025
1 parent 81643e2 commit 79f79f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(super) fn check<'tcx>(
&format!(
"std::path::Path::new({})
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case(\"{}\"))",
.is_some_and(|ext| ext.eq_ignore_ascii_case(\"{}\"))",
recv_source,
ext_str.strip_prefix('.').unwrap()
),
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/case_sensitive_file_extension_comparisons.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ impl TestStruct {
fn is_rust_file(filename: &str) -> bool {
std::path::Path::new(filename)
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
.is_some_and(|ext| ext.eq_ignore_ascii_case("rs"))
//~^ case_sensitive_file_extension_comparisons
}

fn main() {
// std::string::String and &str should trigger the lint failure with .ext12
let _ = std::path::Path::new(&String::new())
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
.is_some_and(|ext| ext.eq_ignore_ascii_case("ext12"));
//~^ case_sensitive_file_extension_comparisons
let _ = std::path::Path::new("str")
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
.is_some_and(|ext| ext.eq_ignore_ascii_case("ext12"));
//~^ case_sensitive_file_extension_comparisons

// The fixup should preserve the indentation level
{
let _ = std::path::Path::new("str")
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
.is_some_and(|ext| ext.eq_ignore_ascii_case("ext12"));
//~^ case_sensitive_file_extension_comparisons
}

Expand All @@ -42,11 +42,11 @@ fn main() {
// std::string::String and &str should trigger the lint failure with .EXT12
let _ = std::path::Path::new(&String::new())
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
.is_some_and(|ext| ext.eq_ignore_ascii_case("EXT12"));
//~^ case_sensitive_file_extension_comparisons
let _ = std::path::Path::new("str")
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
.is_some_and(|ext| ext.eq_ignore_ascii_case("EXT12"));
//~^ case_sensitive_file_extension_comparisons

// Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/case_sensitive_file_extension_comparisons.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ help: use std::path::Path
|
LL ~ std::path::Path::new(filename)
LL + .extension()
LL + .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
LL + .is_some_and(|ext| ext.eq_ignore_ascii_case("rs"))
|

error: case-sensitive file extension comparison
Expand All @@ -25,7 +25,7 @@ help: use std::path::Path
|
LL ~ let _ = std::path::Path::new(&String::new())
LL + .extension()
LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
LL ~ .is_some_and(|ext| ext.eq_ignore_ascii_case("ext12"));
|

error: case-sensitive file extension comparison
Expand All @@ -39,7 +39,7 @@ help: use std::path::Path
|
LL ~ let _ = std::path::Path::new("str")
LL + .extension()
LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
LL ~ .is_some_and(|ext| ext.eq_ignore_ascii_case("ext12"));
|

error: case-sensitive file extension comparison
Expand All @@ -53,7 +53,7 @@ help: use std::path::Path
|
LL ~ let _ = std::path::Path::new("str")
LL + .extension()
LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
LL ~ .is_some_and(|ext| ext.eq_ignore_ascii_case("ext12"));
|

error: case-sensitive file extension comparison
Expand All @@ -67,7 +67,7 @@ help: use std::path::Path
|
LL ~ let _ = std::path::Path::new(&String::new())
LL + .extension()
LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
LL ~ .is_some_and(|ext| ext.eq_ignore_ascii_case("EXT12"));
|

error: case-sensitive file extension comparison
Expand All @@ -81,7 +81,7 @@ help: use std::path::Path
|
LL ~ let _ = std::path::Path::new("str")
LL + .extension()
LL ~ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
LL ~ .is_some_and(|ext| ext.eq_ignore_ascii_case("EXT12"));
|

error: aborting due to 6 previous errors
Expand Down

0 comments on commit 79f79f7

Please sign in to comment.