From 49e383d014867665d63cbdc5eb3a7fcc486c156b Mon Sep 17 00:00:00 2001 From: Mohamed Abdelnour Date: Fri, 21 May 2021 14:19:15 +0200 Subject: [PATCH 1/7] Use `!theme.is_empty()` --- src/assets.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assets.rs b/src/assets.rs index bac0c430d2..8850978852 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -201,7 +201,7 @@ impl HighlightingAssets { bat_warning!("Theme '{}' is deprecated, using 'ansi' instead.", theme); return self.get_theme("ansi"); } - if theme != "" { + if !theme.is_empty() { bat_warning!("Unknown theme '{}', using default.", theme) } &self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())] From c42382949e41852f875bbd2e5ba15e1516dc9b42 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelnour Date: Fri, 21 May 2021 14:53:39 +0200 Subject: [PATCH 2/7] Use `matches` macro --- src/pager.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/pager.rs b/src/pager.rs index c6a4170d90..3bd294ad87 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -98,18 +98,21 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result, Par Some((bin, args)) => { let kind = PagerKind::from_bin(bin); - let use_less_instead = match (&source, &kind) { - // 'more' and 'most' do not supports colors; automatically use 'less' instead - // if the problematic pager came from the generic PAGER env var - (PagerSource::EnvVarPager, PagerKind::More) => true, - (PagerSource::EnvVarPager, PagerKind::Most) => true, - - // If PAGER=bat, silently use 'less' instead to prevent recursion ... - (PagerSource::EnvVarPager, PagerKind::Bat) => true, - - // Never silently use less if BAT_PAGER or --pager has been specified - _ => false, - }; + // Is false if the given expression does not match any of the + // patterns; this ensures 'less' is never silently used if BAT_PAGER + // or --pager has been specified. + let use_less_instead = matches!( + (&source, &kind), + // 'more' and 'most' do not supports colors; automatically use + // 'less' instead if the problematic pager came from the + // generic PAGER env var + (PagerSource::EnvVarPager, PagerKind::More) + | (PagerSource::EnvVarPager, PagerKind::Most) + + // If PAGER=bat, silently use 'less' instead to prevent + // recursion ... + | (PagerSource::EnvVarPager, PagerKind::Bat) + ); Ok(Some(if use_less_instead { let no_args = vec![]; From 8dd7f4c50f3f1895729e63358e0a2ffc099788e0 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelnour Date: Fri, 21 May 2021 15:04:53 +0200 Subject: [PATCH 3/7] Use the functional update syntax --- src/pretty_printer.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index 7f1c2b7f34..1d81dc8159 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -40,10 +40,11 @@ pub struct PrettyPrinter<'a> { impl<'a> PrettyPrinter<'a> { pub fn new() -> Self { - let mut config = Config::default(); - - config.colored_output = true; - config.true_color = true; + let config = Config { + colored_output: true, + true_color: true, + ..Default::default() + }; PrettyPrinter { inputs: vec![], From b80d53322f4e546aabed6efbe0831d07fab3ab5a Mon Sep 17 00:00:00 2001 From: Mohamed Abdelnour Date: Fri, 21 May 2021 15:41:51 +0200 Subject: [PATCH 4/7] Implement `From<..>` instead of `Into<..>` --- src/pretty_printer.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index 1d81dc8159..f60c829d47 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -336,14 +336,14 @@ impl<'a> Input<'a> { } } -impl<'a> Into> for input::Input<'a> { - fn into(self) -> Input<'a> { - Input { input: self } +impl<'a> From> for Input<'a> { + fn from(input: input::Input<'a>) -> Self { + Self { input } } } -impl<'a> Into> for Input<'a> { - fn into(self) -> input::Input<'a> { - self.input +impl<'a> From> for input::Input<'a> { + fn from(Input { input }: Input<'a>) -> Self { + input } } From 37593bac222992052b82bb3fc6194f8f66997d87 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelnour Date: Fri, 21 May 2021 15:47:27 +0200 Subject: [PATCH 5/7] Use the functional update syntax --- src/printer.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/printer.rs b/src/printer.rs index 45caf15787..11db95636d 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -447,8 +447,10 @@ impl<'a> Printer for InteractivePrinter<'a> { if text.len() != text_trimmed.len() { if let Some(background_color) = background_color { - let mut ansi_style = Style::default(); - ansi_style.background = to_ansi_color(background_color, true_color); + let ansi_style = Style { + background: to_ansi_color(background_color, true_color), + ..Default::default() + }; let width = if cursor_total <= cursor_max { cursor_max - cursor_total + 1 } else { @@ -588,8 +590,10 @@ impl<'a> Printer for InteractivePrinter<'a> { } if let Some(background_color) = background_color { - let mut ansi_style = Style::default(); - ansi_style.background = to_ansi_color(background_color, self.config.true_color); + let ansi_style = Style { + background: to_ansi_color(background_color, self.config.true_color), + ..Default::default() + }; write!( handle, From abe062c378f7083a7585baf355555cc13d284353 Mon Sep 17 00:00:00 2001 From: Mohamed Abdelnour Date: Fri, 21 May 2021 22:55:02 +0200 Subject: [PATCH 6/7] Update `CHANGELOG.md` for #1661 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61947b3f7f..e7dd47f287 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ## Other +- Fix Clippy lints, see #1661 (@mohamed-abdelnour) + ## Syntaxes From 42af1603b21d9ec31495fc0348726605c33995fc Mon Sep 17 00:00:00 2001 From: Mohamed Abdelnour Date: Sat, 22 May 2021 12:13:02 +0200 Subject: [PATCH 7/7] Refactor "Use `matches` macro" --- src/pager.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/pager.rs b/src/pager.rs index 3bd294ad87..3473aa67da 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -98,21 +98,18 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result, Par Some((bin, args)) => { let kind = PagerKind::from_bin(bin); - // Is false if the given expression does not match any of the - // patterns; this ensures 'less' is never silently used if BAT_PAGER - // or --pager has been specified. - let use_less_instead = matches!( - (&source, &kind), + let use_less_instead = if source == PagerSource::EnvVarPager { // 'more' and 'most' do not supports colors; automatically use // 'less' instead if the problematic pager came from the - // generic PAGER env var - (PagerSource::EnvVarPager, PagerKind::More) - | (PagerSource::EnvVarPager, PagerKind::Most) - + // generic PAGER env var. // If PAGER=bat, silently use 'less' instead to prevent - // recursion ... - | (PagerSource::EnvVarPager, PagerKind::Bat) - ); + // recursion. + // Never silently use 'less' if BAT_PAGER or --pager has been + // specified. + matches!(kind, PagerKind::More | PagerKind::Most | PagerKind::Bat) + } else { + false + }; Ok(Some(if use_less_instead { let no_args = vec![];