From 0751e3bb830614e671b0baa750c38cb9b9946ee1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 30 Dec 2020 16:25:07 +0800 Subject: [PATCH] Fix all feasible clippy issues (#687) And the ones not deemed feasible were officialy allowed so folks running `cargo clippy` should see no warnings. --- src/cli_utils.rs | 6 +++--- src/config.rs | 1 + src/language/language_type.rs | 2 +- src/language/syntax.rs | 6 +++--- src/utils/fs.rs | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cli_utils.rs b/src/cli_utils.rs index 50c2d4b..e6d3559 100644 --- a/src/cli_utils.rs +++ b/src/cli_utils.rs @@ -242,7 +242,7 @@ impl Printer { Ok(()) } - fn print_code_stats<'a, 'b>( + fn print_code_stats( &mut self, language_type: LanguageType, stats: &[CodeStats], @@ -283,7 +283,7 @@ impl Printer { .collect::>(), )?; } - let mut subtotal = tokei::Report::new(format!("(Total)").into()); + let mut subtotal = tokei::Report::new("(Total)".into()); let summary = parent.summarise(); subtotal.stats.code += summary.code; subtotal.stats.comments += summary.comments; @@ -394,7 +394,7 @@ impl Printer { return Ok(()); } - let mut subtotal = tokei::Report::new(format!("|- (Total)").into()); + let mut subtotal = tokei::Report::new("|- (Total)".into()); subtotal.stats.code += report.stats.code; subtotal.stats.comments += report.stats.comments; subtotal.stats.blanks += report.stats.blanks; diff --git a/src/config.rs b/src/config.rs index 3056984..f1fe308 100644 --- a/src/config.rs +++ b/src/config.rs @@ -97,6 +97,7 @@ impl Config { .and_then(Self::get_config) .unwrap_or_else(Self::default); + #[allow(clippy::or_fun_call)] Config { columns: current_dir .columns diff --git a/src/language/language_type.rs b/src/language/language_type.rs index 71a3dbc..6e1e1e6 100644 --- a/src/language/language_type.rs +++ b/src/language/language_type.rs @@ -72,7 +72,7 @@ impl LanguageType { // Get the position of the last line before the important // syntax. text[..=m.start()] - .into_iter() + .iter() .rev() .position(|&c| c == b'\n') .filter(|&p| p != 0) diff --git a/src/language/syntax.rs b/src/language/syntax.rs index 6e64fee..efd56c5 100644 --- a/src/language/syntax.rs +++ b/src/language/syntax.rs @@ -316,6 +316,7 @@ impl SyntaxCounter { }; // `Some(true)` in order to respect the current configuration. + #[allow(clippy::if_same_then_else)] if self.quote.is_some() { if self.quote_is_doc_quote && config.treat_doc_strings_as_comments == Some(true) { self.quote.map_or(false, |q| line.starts_with(q.as_bytes())) @@ -335,10 +336,8 @@ impl SyntaxCounter { true } else if started_in_comments { true - } else if (starts_with_comment)() { - true } else { - false + (starts_with_comment)() } } @@ -437,6 +436,7 @@ impl SyntaxCounter { doc_block, )) } + #[allow(clippy::trivial_regex)] LanguageType::Html | LanguageType::RubyHtml | LanguageType::Svelte diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 9393850..46a3801 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -103,7 +103,7 @@ pub fn get_all_files>( } }; - if let Some(types) = config.types.as_ref().map(|v| &**v) { + if let Some(types) = config.types.as_deref() { rx_iter.filter(|(_, l)| types.contains(l)).for_each(process) } else { rx_iter.for_each(process)