From 61ec153bcd543ad320c418ad81af5aba89fecffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 30 Apr 2021 15:37:31 +0200 Subject: [PATCH 1/3] Cleanup clippy warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit warning: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) --> src/output/escape.rs:4:1 | 4 | pub fn escape<'a>(string: String, bits: &mut Vec>, good: Style, bad: Style) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | warning: this lifetime isn't used in the function definition --> src/output/escape.rs:4:15 | 4 | pub fn escape<'a>(string: String, bits: &mut Vec>, good: Style, bad: Style) { | ^^ | warning: single-character string constant used as pattern --> src/output/table.rs:310:41 | 310 | if file.starts_with(":") { | ^^^ help: try using a `char` instead: `':'` | warning: single-character string constant used as pattern --> src/output/table.rs:310:41 | 310 | if file.starts_with(":") { | ^^^ help: try using a `char` instead: `':'` | warning: methods called `new` usually return `Self` --> src/output/render/git.rs:38:5 | 38 | fn new(&self) -> Style; | ^^^^^^^^^^^^^^^^^^^^^^^ | warning: this lifetime isn't used in the function definition --> src/output/icons.rs:40:22 | 40 | pub fn iconify_style<'a>(style: Style) -> Style { | ^^ | warning: lint `clippy::find_map` has been removed: this lint has been replaced by `manual_find_map`, a more specific lint --> src/main.rs:11:10 | 11 | #![allow(clippy::find_map)] | ^^^^^^^^^^^^^^^^ | warning: redundant else block --> src/fs/dir.rs:124:18 | 124 | else { | __________________^ 125 | | return None 126 | | } | |_____________^ | warning: redundant else block --> src/options/view.rs:60:18 | 60 | else { | __________________^ 61 | | // the --tree case is handled by the DirAction parser later 62 | | return Ok(Self::Details(details)); 63 | | } | |_____________^ | warning: all variants have the same postfix: `Bytes` --> src/output/table.rs:170:1 | 170 | / pub enum SizeFormat { 171 | | 172 | | /// Format the file size using **decimal** prefixes, such as “kilo”, 173 | | /// “mega”, or “giga”. ... | 181 | | JustBytes, 182 | | } | |_^ | warning: all variants have the same postfix: `Bytes` --> src/output/table.rs:171:1 | 171 | / pub enum SizeFormat { 172 | | 173 | | /// Format the file size using **decimal** prefixes, such as “kilo”, 174 | | /// “mega”, or “giga”. ... | 182 | | JustBytes, 183 | | } | |_^ | warning: useless use of `format!` --> src/options/mod.rs:181:50 | 181 | return Err(OptionsError::Unsupported(format!( | __________________________________________________^ 182 | | "Options --git and --git-ignore can't be used because `git` feature was disabled in this build of exa" 183 | | ))); | |_____________^ help: consider using `.to_string()`: `"Options --git and --git-ignore can't be used because `git` feature was disabled in this build of exa".to_string()` | warning: stripping a prefix manually --> src/fs/filter.rs:287:33 | 287 | if n.starts_with('.') { &n[1..] } | ^^^^^^^ | warning: case-sensitive file extension comparison --> src/info/filetype.rs:24:19 | 24 | file.name.ends_with(".ninja") || | ^^^^^^^^^^^^^^^^^^^ | --- src/fs/dir.rs | 5 ++--- src/fs/filter.rs | 6 ++++-- src/info/filetype.rs | 1 + src/main.rs | 2 +- src/options/mod.rs | 2 +- src/options/view.rs | 7 +++---- src/output/escape.rs | 2 +- src/output/icons.rs | 2 +- src/output/render/git.rs | 1 + src/output/table.rs | 6 ++++-- 10 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/fs/dir.rs b/src/fs/dir.rs index 7f7b067..1a6ce01 100644 --- a/src/fs/dir.rs +++ b/src/fs/dir.rs @@ -121,9 +121,8 @@ impl<'dir, 'ig> Files<'dir, 'ig> { return Some(File::from_args(path.clone(), self.dir, filename) .map_err(|e| (path.clone(), e))) } - else { - return None - } + + return None } } } diff --git a/src/fs/filter.rs b/src/fs/filter.rs index 4cd6ad2..08770e6 100644 --- a/src/fs/filter.rs +++ b/src/fs/filter.rs @@ -284,8 +284,10 @@ impl SortField { } fn strip_dot(n: &str) -> &str { - if n.starts_with('.') { &n[1..] } - else { n } + match n.strip_prefix('.') { + Some(s) => s, + None => n, + } } } diff --git a/src/info/filetype.rs b/src/info/filetype.rs index 8f54281..1def7a2 100644 --- a/src/info/filetype.rs +++ b/src/info/filetype.rs @@ -19,6 +19,7 @@ impl FileExtensions { /// An “immediate” file is something that can be run or activated somehow /// in order to kick off the build of a project. It’s usually only present /// in directories full of source code. + #[allow(clippy::case_sensitive_file_extension_comparisons)] fn is_immediate(&self, file: &File<'_>) -> bool { file.name.to_lowercase().starts_with("readme") || file.name.ends_with(".ninja") || diff --git a/src/main.rs b/src/main.rs index 84f36b7..4d762b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::enum_glob_use)] -#![allow(clippy::find_map)] #![allow(clippy::map_unwrap_or)] #![allow(clippy::match_same_arms)] #![allow(clippy::missing_const_for_fn)] @@ -19,6 +18,7 @@ #![allow(clippy::option_if_let_else)] #![allow(clippy::too_many_lines)] #![allow(clippy::unused_self)] +#![allow(clippy::upper_case_acronyms)] #![allow(clippy::wildcard_imports)] use std::env; diff --git a/src/options/mod.rs b/src/options/mod.rs index 747213b..528ba43 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -178,7 +178,7 @@ impl Options { fn deduce(matches: &MatchedFlags<'_>, vars: &V) -> Result { if cfg!(not(feature = "git")) && matches.has_where_any(|f| f.matches(&flags::GIT) || f.matches(&flags::GIT_IGNORE)).is_some() { - return Err(OptionsError::Unsupported(format!( + return Err(OptionsError::Unsupported(String::from( "Options --git and --git-ignore can't be used because `git` feature was disabled in this build of exa" ))); } diff --git a/src/options/view.rs b/src/options/view.rs index 6d7abac..fe42838 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -57,10 +57,9 @@ impl Mode { let grid_details = grid_details::Options { grid, details, row_threshold }; return Ok(Self::GridDetails(grid_details)); } - else { - // the --tree case is handled by the DirAction parser later - return Ok(Self::Details(details)); - } + + // the --tree case is handled by the DirAction parser later + return Ok(Self::Details(details)); } Self::strict_check_long_flags(matches)?; diff --git a/src/output/escape.rs b/src/output/escape.rs index b4e801d..4c9f86c 100644 --- a/src/output/escape.rs +++ b/src/output/escape.rs @@ -1,7 +1,7 @@ use ansi_term::{ANSIString, Style}; -pub fn escape<'a>(string: String, bits: &mut Vec>, good: Style, bad: Style) { +pub fn escape(string: String, bits: &mut Vec>, good: Style, bad: Style) { if string.chars().all(|c| c >= 0x20 as char && c != 0x7f as char) { bits.push(good.paint(string)); return; diff --git a/src/output/icons.rs b/src/output/icons.rs index 8c024dc..eea0286 100644 --- a/src/output/icons.rs +++ b/src/output/icons.rs @@ -37,7 +37,7 @@ impl Icons { /// - If neither is set, just use the default style. /// - Attributes such as bold or underline should not be used to paint the /// icon, as they can make it look weird. -pub fn iconify_style<'a>(style: Style) -> Style { +pub fn iconify_style(style: Style) -> Style { style.background.or(style.foreground) .map(Style::from) .unwrap_or_default() diff --git a/src/output/render/git.rs b/src/output/render/git.rs index 7ec9589..3740d40 100644 --- a/src/output/render/git.rs +++ b/src/output/render/git.rs @@ -35,6 +35,7 @@ impl f::GitStatus { pub trait Colours { fn not_modified(&self) -> Style; + #[allow(clippy::new_ret_no_self)] fn new(&self) -> Style; fn modified(&self) -> Style; fn deleted(&self) -> Style; diff --git a/src/output/table.rs b/src/output/table.rs index fbe716c..1680ec7 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -28,6 +28,7 @@ pub struct Options { } /// Extra columns to display in the table. +#[allow(clippy::struct_excessive_bools)] #[derive(PartialEq, Debug, Copy, Clone)] pub struct Columns { @@ -166,6 +167,7 @@ impl Column { /// Formatting options for file sizes. +#[allow(clippy::pub_enum_variant_names)] #[derive(PartialEq, Debug, Copy, Clone)] pub enum SizeFormat { @@ -303,11 +305,11 @@ impl Environment { fn determine_time_zone() -> TZResult { if let Ok(file) = env::var("TZ") { TimeZone::from_file({ - if file.starts_with("/") { + if file.starts_with('/') { file } else { format!("/usr/share/zoneinfo/{}", { - if file.starts_with(":") { + if file.starts_with(':') { file.replacen(":", "", 1) } else { file From d253893614797206f684da30694678fde2b51274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 30 Apr 2021 15:37:39 +0200 Subject: [PATCH 2/3] Cleanup clippy warnings Enable clippy::missing_errors_doc warning: docs for function returning `Result` missing `# Errors` section --> src/main.rs:164:5 | 164 | / pub fn run(mut self) -> io::Result { 165 | | debug!("Running with options: {:#?}", self.options); 166 | | 167 | | let mut files = Vec::new(); ... | 202 | | self.print_dirs(dirs, no_files, is_only_dir, exit_status) 203 | | } | |_____^ | --- src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.rs b/src/main.rs index 4d762b5..116062a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,6 +155,9 @@ fn git_options(options: &Options, args: &[&OsStr]) -> Option { } impl<'args> Exa<'args> { + /// # Errors + /// + /// Will return `Err` if printing to stderr fails. pub fn run(mut self) -> io::Result { debug!("Running with options: {:#?}", self.options); From ae62f5d18e039159b6e7628090391d2cab1c557e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 30 Apr 2021 15:37:43 +0200 Subject: [PATCH 3/3] Cleanup clippy warnings Drop unused allow overrides --- src/main.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 116062a..92a9424 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,10 +10,7 @@ #![allow(clippy::enum_glob_use)] #![allow(clippy::map_unwrap_or)] #![allow(clippy::match_same_arms)] -#![allow(clippy::missing_const_for_fn)] -#![allow(clippy::missing_errors_doc)] #![allow(clippy::module_name_repetitions)] -#![allow(clippy::must_use_candidate)] #![allow(clippy::non_ascii_literal)] #![allow(clippy::option_if_let_else)] #![allow(clippy::too_many_lines)]