Explorar el Código

Clippy pedantic lints

This commit fixes a couple of Clippy warnings, and adds the list of lints we're OK with.

It does raise some important warnings, such as those to do with casting, which aren't allowed so they can be fixed later.
Benjamin Sago hace 5 años
padre
commit
002080cde8
Se han modificado 9 ficheros con 42 adiciones y 28 borrados
  1. 8 10
      src/fs/feature/git.rs
  2. 1 0
      src/fs/fields.rs
  3. 5 5
      src/fs/file.rs
  4. 15 0
      src/main.rs
  5. 1 1
      src/options/mod.rs
  6. 4 5
      src/options/view.rs
  7. 2 2
      src/output/render/times.rs
  8. 4 3
      src/output/table.rs
  9. 2 2
      src/output/time.rs

+ 8 - 10
src/fs/feature/git.rs

@@ -167,16 +167,14 @@ impl GitRepo {
             }
             }
         };
         };
 
 
-        match repo.workdir() {
-            Some(workdir) => {
-                let workdir = workdir.to_path_buf();
-                let contents = Mutex::new(GitContents::Before { repo });
-                Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() })
-            }
-            None => {
-                warn!("Repository has no workdir?");
-                Err(path)
-            }
+        if let Some(workdir) = repo.workdir() {
+            let workdir = workdir.to_path_buf();
+            let contents = Mutex::new(GitContents::Before { repo });
+            Ok(Self { contents, workdir, original_path: path, extra_paths: Vec::new() })
+        }
+        else {
+            warn!("Repository has no workdir?");
+            Err(path)
         }
         }
     }
     }
 }
 }

+ 1 - 0
src/fs/fields.rs

@@ -13,6 +13,7 @@
 
 
 // C-style `blkcnt_t` types don’t follow Rust’s rules!
 // C-style `blkcnt_t` types don’t follow Rust’s rules!
 #![allow(non_camel_case_types)]
 #![allow(non_camel_case_types)]
+#![allow(clippy::struct_excessive_bools)]
 
 
 
 
 /// The type of a file’s block count.
 /// The type of a file’s block count.

+ 5 - 5
src/fs/file.rs

@@ -337,19 +337,19 @@ impl<'dir> File<'dir> {
 
 
     /// This file’s last changed timestamp, if available on this platform.
     /// This file’s last changed timestamp, if available on this platform.
     pub fn changed_time(&self) -> Option<SystemTime> {
     pub fn changed_time(&self) -> Option<SystemTime> {
-        let (mut sec, mut nsec) = (self.metadata.ctime(), self.metadata.ctime_nsec());
+        let (mut sec, mut nanosec) = (self.metadata.ctime(), self.metadata.ctime_nsec());
 
 
         if sec < 0 {
         if sec < 0 {
-            if nsec > 0 {
+            if nanosec > 0 {
                 sec += 1;
                 sec += 1;
-                nsec -= 1_000_000_000;
+                nanosec -= 1_000_000_000;
             }
             }
 
 
-            let duration = Duration::new(sec.abs() as u64, nsec.abs() as u32);
+            let duration = Duration::new(sec.abs() as u64, nanosec.abs() as u32);
             Some(UNIX_EPOCH - duration)
             Some(UNIX_EPOCH - duration)
         }
         }
         else {
         else {
-            let duration = Duration::new(sec as u64, nsec as u32);
+            let duration = Duration::new(sec as u64, nanosec as u32);
             Some(UNIX_EPOCH + duration)
             Some(UNIX_EPOCH + duration)
         }
         }
     }
     }

+ 15 - 0
src/main.rs

@@ -6,6 +6,21 @@
 #![warn(trivial_casts, trivial_numeric_casts)]
 #![warn(trivial_casts, trivial_numeric_casts)]
 #![warn(unused)]
 #![warn(unused)]
 
 
+#![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)]
+#![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)]
+#![allow(clippy::unused_self)]
+#![allow(clippy::wildcard_imports)]
+
 use std::env;
 use std::env;
 use std::ffi::{OsStr, OsString};
 use std::ffi::{OsStr, OsString};
 use std::io::{self, Write, ErrorKind};
 use std::io::{self, Write, ErrorKind};

+ 1 - 1
src/options/mod.rs

@@ -128,7 +128,7 @@ impl Options {
         let strictness = match vars.get(vars::EXA_STRICT) {
         let strictness = match vars.get(vars::EXA_STRICT) {
             None                         => Strictness::UseLastArguments,
             None                         => Strictness::UseLastArguments,
             Some(ref t) if t.is_empty()  => Strictness::UseLastArguments,
             Some(ref t) if t.is_empty()  => Strictness::UseLastArguments,
-            _                            => Strictness::ComplainAboutRedundantArguments,
+            Some(_)                      => Strictness::ComplainAboutRedundantArguments,
         };
         };
 
 
         let Matches { flags, frees } = match flags::ALL_ARGS.parse(args, strictness) {
         let Matches { flags, frees } = match flags::ALL_ARGS.parse(args, strictness) {

+ 4 - 5
src/options/view.rs

@@ -262,18 +262,17 @@ impl TimeFormat {
 
 
     /// Determine how time should be formatted in timestamp columns.
     /// Determine how time should be formatted in timestamp columns.
     fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
     fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
-        let word = match matches.get(&flags::TIME_STYLE)? {
-            Some(w) => {
+        let word =
+            if let Some(w) = matches.get(&flags::TIME_STYLE)? {
                 w.to_os_string()
                 w.to_os_string()
             }
             }
-            None => {
+            else {
                 use crate::options::vars;
                 use crate::options::vars;
                 match vars.get(vars::TIME_STYLE) {
                 match vars.get(vars::TIME_STYLE) {
                     Some(ref t) if ! t.is_empty()  => t.clone(),
                     Some(ref t) if ! t.is_empty()  => t.clone(),
                     _                              => return Ok(Self::DefaultFormat)
                     _                              => return Ok(Self::DefaultFormat)
                 }
                 }
-            },
-        };
+            };
 
 
         if &word == "default" {
         if &word == "default" {
             Ok(Self::DefaultFormat)
             Ok(Self::DefaultFormat)

+ 2 - 2
src/output/render/times.rs

@@ -8,11 +8,11 @@ use crate::output::time::TimeFormat;
 
 
 
 
 pub trait Render {
 pub trait Render {
-    fn render(self, style: Style, tz: &Option<TimeZone>, format: &TimeFormat) -> TextCell;
+    fn render(self, style: Style, tz: &Option<TimeZone>, format: TimeFormat) -> TextCell;
 }
 }
 
 
 impl Render for Option<SystemTime> {
 impl Render for Option<SystemTime> {
-    fn render(self, style: Style, tz: &Option<TimeZone>, format: &TimeFormat) -> TextCell {
+    fn render(self, style: Style, tz: &Option<TimeZone>, format: TimeFormat) -> TextCell {
         let datestamp = if let Some(time) = self {
         let datestamp = if let Some(time) = self {
             if let Some(ref tz) = tz {
             if let Some(ref tz) = tz {
                 format.format_zoned(time, tz)
                 format.format_zoned(time, tz)

+ 4 - 3
src/output/table.rs

@@ -225,6 +225,7 @@ impl TimeType {
 /// There should always be at least one of these — there’s no way to disable
 /// There should always be at least one of these — there’s no way to disable
 /// the time columns entirely (yet).
 /// the time columns entirely (yet).
 #[derive(PartialEq, Debug, Copy, Clone)]
 #[derive(PartialEq, Debug, Copy, Clone)]
+#[allow(clippy::struct_excessive_bools)]
 pub struct TimeTypes {
 pub struct TimeTypes {
     pub modified: bool,
     pub modified: bool,
     pub changed:  bool,
     pub changed:  bool,
@@ -308,7 +309,7 @@ pub struct Table<'a> {
     colours: &'a Colours,
     colours: &'a Colours,
     env: &'a Environment,
     env: &'a Environment,
     widths: TableWidths,
     widths: TableWidths,
-    time_format: &'a TimeFormat,
+    time_format: TimeFormat,
     size_format: SizeFormat,
     size_format: SizeFormat,
     git: Option<&'a GitCache>,
     git: Option<&'a GitCache>,
 }
 }
@@ -330,8 +331,8 @@ impl<'a, 'f> Table<'a> {
             columns,
             columns,
             git,
             git,
             env,
             env,
-            time_format: &options.time_format,
-            size_format:  options.size_format,
+            time_format: options.time_format,
+            size_format: options.size_format,
         }
         }
     }
     }
 
 

+ 2 - 2
src/output/time.rs

@@ -52,7 +52,7 @@ pub enum TimeFormat {
 // timestamps are separate types.
 // timestamps are separate types.
 
 
 impl TimeFormat {
 impl TimeFormat {
-    pub fn format_local(&self, time: SystemTime) -> String {
+    pub fn format_local(self, time: SystemTime) -> String {
         match self {
         match self {
             Self::DefaultFormat  => default_local(time),
             Self::DefaultFormat  => default_local(time),
             Self::ISOFormat      => iso_local(time),
             Self::ISOFormat      => iso_local(time),
@@ -61,7 +61,7 @@ impl TimeFormat {
         }
         }
     }
     }
 
 
-    pub fn format_zoned(&self, time: SystemTime, zone: &TimeZone) -> String {
+    pub fn format_zoned(self, time: SystemTime, zone: &TimeZone) -> String {
         match self {
         match self {
             Self::DefaultFormat  => default_zoned(time, zone),
             Self::DefaultFormat  => default_zoned(time, zone),
             Self::ISOFormat      => iso_zoned(time, zone),
             Self::ISOFormat      => iso_zoned(time, zone),