From 43b2ee5e71f70b8f1f805d2c45331807ef20bafe Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Thu, 5 Nov 2020 22:29:04 +0100 Subject: [PATCH] fix some clippy warnings --- src/bin/bat/app.rs | 11 +++-------- src/bin/bat/config.rs | 2 +- src/controller.rs | 2 +- src/input.rs | 11 +++-------- src/output.rs | 6 +----- src/pretty_printer.rs | 2 +- src/printer.rs | 2 +- 7 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 8d09618c..76cd30dc 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -169,9 +169,7 @@ impl App { || match self.matches.value_of("color") { Some("always") => true, Some("never") => false, - Some("auto") | _ => { - env::var_os("NO_COLOR").is_none() && self.interactive_output - } + _ => env::var_os("NO_COLOR").is_none() && self.interactive_output, }, paging_mode, term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize), @@ -226,17 +224,14 @@ impl App { style_components, syntax_mapping, pager: self.matches.value_of("pager"), - use_italic_text: match self.matches.value_of("italic-text") { - Some("always") => true, - _ => false, - }, + use_italic_text: matches!(self.matches.value_of("italic-text"), Some("always")), highlighted_lines: self .matches .values_of("highlight-line") .map(|ws| ws.map(LineRange::from).collect()) .transpose()? .map(LineRanges::from) - .map(|lr| HighlightedLineRanges(lr)) + .map(HighlightedLineRanges) .unwrap_or_default(), }) } diff --git a/src/bin/bat/config.rs b/src/bin/bat/config.rs index 1f20a6f0..e7ede5a3 100644 --- a/src/bin/bat/config.rs +++ b/src/bin/bat/config.rs @@ -85,7 +85,7 @@ pub fn get_args_from_config_file() -> Result, shell_words::ParseEr .ok() .map(|content| get_args_from_str(&content)) .transpose()? - .unwrap_or_else(|| vec![])) + .unwrap_or_else(Vec::new)) } pub fn get_args_from_env_var() -> Option, shell_words::ParseError>> { diff --git a/src/controller.rs b/src/controller.rs index d9b8e809..2ccd6dfb 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -161,7 +161,7 @@ impl<'b> Controller<'b> { Ok(no_errors) } - fn print_file<'a>( + fn print_file( &self, printer: &mut dyn Printer, writer: &mut dyn Write, diff --git a/src/input.rs b/src/input.rs index 3a723631..1e7aec2f 100644 --- a/src/input.rs +++ b/src/input.rs @@ -137,17 +137,12 @@ impl<'a> Input<'a> { } pub fn is_stdin(&self) -> bool { - if let InputKind::StdIn = self.kind { - true - } else { - false - } + matches!(self.kind, InputKind::StdIn) } pub fn with_name(mut self, provided_name: Option<&OsStr>) -> Self { - match provided_name { - Some(name) => self.description.name = name.to_string_lossy().to_string(), - None => {} + if let Some(name) = provided_name { + self.description.name = name.to_string_lossy().to_string() } self.metadata.user_provided_name = provided_name.map(|n| n.to_owned()); diff --git a/src/output.rs b/src/output.rs index 689371b9..32a94a4c 100644 --- a/src/output.rs +++ b/src/output.rs @@ -150,11 +150,7 @@ impl OutputType { #[cfg(feature = "paging")] pub(crate) fn is_pager(&self) -> bool { - if let OutputType::Pager(_) = self { - true - } else { - false - } + matches!(self, OutputType::Pager(_)) } #[cfg(not(feature = "paging"))] diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index 89745eec..cdf22df9 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -338,7 +338,7 @@ impl<'a> Input<'a> { /// A new input from bytes. pub fn from_bytes(bytes: &'a [u8]) -> Self { - Input::from_reader(bytes).into() + Input::from_reader(bytes) } /// A new input from STDIN. diff --git a/src/printer.rs b/src/printer.rs index e0829874..ba74872a 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -311,7 +311,7 @@ impl<'a> Printer for InteractivePrinter<'a> { description .kind() .map(|kind| format!("{}: ", kind)) - .unwrap_or("".into()), + .unwrap_or_else(|| "".into()), self.colors.filename.paint(description.title()), mode )?;