Skip to content

Commit

Permalink
chore: apply clippy::unnecessary_map_or lint suggestions
Browse files Browse the repository at this point in the history
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 +     })
  • Loading branch information
jqnatividad committed Nov 16, 2024
1 parent 8f2b516 commit 5169350
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/cmd/luau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/searchset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/sqlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl From<ValidationError<'_>> 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 {
Expand Down

0 comments on commit 5169350

Please sign in to comment.