From 516935058d3ffea5799b282cf2ca881933a9db5e Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Sat, 16 Nov 2024 07:54:17 -0500 Subject: [PATCH] chore: apply `clippy::unnecessary_map_or` lint suggestions warning: this `map_or` is redundant --> src/cmd/luau.rs:367:15 | 367 | } else if std::path::Path::new(&args.arg_main_script) | _______________^ 368 | | .extension() 369 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("luau")) | |______________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or = note: `#[warn(clippy::unnecessary_map_or)]` on by default help: use is_some_and instead | 367 ~ } else if std::path::Path::new(&args.arg_main_script) 368 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("luau")) | warning: this `map_or` is redundant --> src/cmd/luau.rs:370:12 | 370 | || std::path::Path::new(&args.arg_main_script) | ____________^ 371 | | .extension() 372 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("lua")) | |_________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 370 ~ || std::path::Path::new(&args.arg_main_script) 371 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("lua")) | warning: this `map_or` is redundant --> src/cmd/luau.rs:429:19 | 429 | } else if std::path::Path::new(begin) | ___________________^ 430 | | .extension() 431 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("luau")) | |__________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 429 ~ } else if std::path::Path::new(begin) 430 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("luau")) | warning: this `map_or` is redundant --> src/cmd/luau.rs:432:16 | 432 | || std::path::Path::new(begin) | ________________^ 433 | | .extension() 434 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("lua")) | |_____________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 432 ~ || std::path::Path::new(begin) 433 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("lua")) | warning: this `map_or` is redundant --> src/cmd/luau.rs:465:19 | 465 | } else if std::path::Path::new(end) | ___________________^ 466 | | .extension() 467 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("luau")) | |__________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 465 ~ } else if std::path::Path::new(end) 466 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("luau")) | warning: this `map_or` is redundant --> src/cmd/luau.rs:468:16 | 468 | || std::path::Path::new(end) | ________________^ 469 | | .extension() 470 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("lua")) | |_____________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 468 ~ || std::path::Path::new(end) 469 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("lua")) | warning: this `map_or` is redundant --> src/cmd/search.rs:168:21 | 168 | let flag_flag = args.flag_flag.map_or(false, |column_name| { | _____________________^ 169 | | // if --flag column is "M", then we only output the M column 170 | | if column_name == "M" { 171 | | headers.clear(); ... | 175 | | true 176 | | }); | |______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 168 ~ let flag_flag = args.flag_flag.is_some_and(|column_name| { 169 + // if --flag column is "M", then we only output the M column 170 + if column_name == "M" { 171 + headers.clear(); 172 + matches_only = true; 173 + } 174 + headers.push_field(column_name.as_bytes()); 175 + true 176 ~ }); | warning: this `map_or` is redundant --> src/cmd/searchset.rs:199:25 | 199 | let do_match_list = args.flag_flag.map_or(false, |column_name| { | _________________________^ 200 | | headers.push_field(column_name.as_bytes()); 201 | | true 202 | | }); | |______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 199 ~ let do_match_list = args.flag_flag.is_some_and(|column_name| { 200 + headers.push_field(column_name.as_bytes()); 201 + true 202 ~ }); | warning: this `map_or` is redundant --> src/cmd/sqlp.rs:634:25 | 634 | let is_sql_script = std::path::Path::new(&args.arg_sql) | _________________________^ 635 | | .extension() 636 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("sql")); | |_____________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 634 ~ let is_sql_script = std::path::Path::new(&args.arg_sql) 635 ~ .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("sql")); | warning: this `map_or` is redundant --> src/cmd/sqlp.rs:700:12 | 700 | && std::path::Path::new(&args.arg_input[0]) | ____________^ 701 | | .extension() 702 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("csv")) | |_________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 700 ~ && std::path::Path::new(&args.arg_input[0]) 701 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("csv")) | warning: this `map_or` is redundant --> src/cmd/sqlp.rs:994:12 | 994 | if std::path::Path::new(&output) | ____________^ 995 | | .extension() 996 | | .map_or(false, |ext| ext.eq_ignore_ascii_case("sz")) | |________________________________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_some_and instead | 994 ~ if std::path::Path::new(&output) 995 + .extension().is_some_and(|ext| ext.eq_ignore_ascii_case("sz")) | warning: this `map_or` is redundant --> src/cmd/validate.rs:307:5 | 307 | / Currency::from_str(s).map_or(false, |c| { 308 | | if c.symbol().is_empty() { 309 | | true // allow empty currency symbol 310 | | } else { 311 | | qsv_currency::Currency::is_iso_currency(&c) 312 | | } 313 | | }) | |______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or help: use is_ok_and instead | 307 ~ Currency::from_str(s).is_ok_and(|c| { 308 + if c.symbol().is_empty() { 309 + true // allow empty currency symbol 310 + } else { 311 + qsv_currency::Currency::is_iso_currency(&c) 312 + } 313 + }) --- src/cmd/luau.rs | 12 ++++++------ src/cmd/search.rs | 2 +- src/cmd/searchset.rs | 2 +- src/cmd/sqlp.rs | 6 +++--- src/cmd/validate.rs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cmd/luau.rs b/src/cmd/luau.rs index eceaedead..584553a63 100644 --- a/src/cmd/luau.rs +++ b/src/cmd/luau.rs @@ -366,10 +366,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> { } } else if std::path::Path::new(&args.arg_main_script) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("luau")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("luau")) || std::path::Path::new(&args.arg_main_script) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("lua")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("lua")) { match fs::read_to_string(args.arg_main_script.clone()) { Ok(file_contents) => file_contents, @@ -428,10 +428,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> { } } else if std::path::Path::new(begin) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("luau")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("luau")) || std::path::Path::new(begin) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("lua")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("lua")) { match fs::read_to_string(begin.clone()) { Ok(file_contents) => file_contents, @@ -464,10 +464,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> { } } else if std::path::Path::new(end) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("luau")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("luau")) || std::path::Path::new(end) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("lua")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("lua")) { match fs::read_to_string(end.clone()) { Ok(file_contents) => file_contents, diff --git a/src/cmd/search.rs b/src/cmd/search.rs index ba3307a6a..a65d898de 100644 --- a/src/cmd/search.rs +++ b/src/cmd/search.rs @@ -165,7 +165,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { let mut matches_only = false; - let flag_flag = args.flag_flag.map_or(false, |column_name| { + let flag_flag = args.flag_flag.is_some_and(|column_name| { // if --flag column is "M", then we only output the M column if column_name == "M" { headers.clear(); diff --git a/src/cmd/searchset.rs b/src/cmd/searchset.rs index f42080b73..068096ae0 100644 --- a/src/cmd/searchset.rs +++ b/src/cmd/searchset.rs @@ -196,7 +196,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { let mut headers = rdr.byte_headers()?.clone(); let sel = rconfig.selection(&headers)?; - let do_match_list = args.flag_flag.map_or(false, |column_name| { + let do_match_list = args.flag_flag.is_some_and(|column_name| { headers.push_field(column_name.as_bytes()); true }); diff --git a/src/cmd/sqlp.rs b/src/cmd/sqlp.rs index 2da13d806..3e4a5abbf 100644 --- a/src/cmd/sqlp.rs +++ b/src/cmd/sqlp.rs @@ -633,7 +633,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { // check if the input is a SQL script (ends with .sql) let is_sql_script = std::path::Path::new(&args.arg_sql) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("sql")); + .is_some_and(|ext| ext.eq_ignore_ascii_case("sql")); // if infer_len is 0, its not a SQL script, and there is only one input CSV, we can infer the // schema of the CSV more intelligently by counting the number of rows in the file instead of @@ -699,7 +699,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { && comment_char.is_none() && std::path::Path::new(&args.arg_input[0]) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("csv")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("csv")) { // replace all instances of the FROM clause case-insensitive in the SQL query with the // read_csv function using a regex @@ -993,7 +993,7 @@ pub fn compress_output_if_needed( if let Some(output) = output_file { if std::path::Path::new(&output) .extension() - .map_or(false, |ext| ext.eq_ignore_ascii_case("sz")) + .is_some_and(|ext| ext.eq_ignore_ascii_case("sz")) { log::info!("Compressing output with Snappy"); diff --git a/src/cmd/validate.rs b/src/cmd/validate.rs index d4ae82001..c9510a516 100644 --- a/src/cmd/validate.rs +++ b/src/cmd/validate.rs @@ -304,7 +304,7 @@ impl From> for CliError { #[inline] /// Checks if a given string represents a valid currency format. fn currency_format_checker(s: &str) -> bool { - Currency::from_str(s).map_or(false, |c| { + Currency::from_str(s).is_ok_and(|c| { if c.symbol().is_empty() { true // allow empty currency symbol } else {