mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-13 07:56:29 +00:00
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.
This commit is contained in:
parent
3dc86c99ad
commit
002080cde8
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
// C-style `blkcnt_t` types don’t follow Rust’s rules!
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(clippy::struct_excessive_bools)]
|
||||
|
||||
|
||||
/// The type of a file’s block count.
|
||||
|
@ -337,19 +337,19 @@ impl<'dir> File<'dir> {
|
||||
|
||||
/// This file’s last changed timestamp, if available on this platform.
|
||||
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 nsec > 0 {
|
||||
if nanosec > 0 {
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
15
src/main.rs
15
src/main.rs
@ -6,6 +6,21 @@
|
||||
#![warn(trivial_casts, trivial_numeric_casts)]
|
||||
#![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::ffi::{OsStr, OsString};
|
||||
use std::io::{self, Write, ErrorKind};
|
||||
|
@ -128,7 +128,7 @@ impl Options {
|
||||
let strictness = match vars.get(vars::EXA_STRICT) {
|
||||
None => 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) {
|
||||
|
@ -262,18 +262,17 @@ impl TimeFormat {
|
||||
|
||||
/// Determine how time should be formatted in timestamp columns.
|
||||
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()
|
||||
}
|
||||
None => {
|
||||
else {
|
||||
use crate::options::vars;
|
||||
match vars.get(vars::TIME_STYLE) {
|
||||
Some(ref t) if ! t.is_empty() => t.clone(),
|
||||
_ => return Ok(Self::DefaultFormat)
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
if &word == "default" {
|
||||
Ok(Self::DefaultFormat)
|
||||
|
@ -8,11 +8,11 @@ use crate::output::time::TimeFormat;
|
||||
|
||||
|
||||
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> {
|
||||
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 {
|
||||
if let Some(ref tz) = tz {
|
||||
format.format_zoned(time, tz)
|
||||
|
@ -225,6 +225,7 @@ impl TimeType {
|
||||
/// There should always be at least one of these — there’s no way to disable
|
||||
/// the time columns entirely (yet).
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct TimeTypes {
|
||||
pub modified: bool,
|
||||
pub changed: bool,
|
||||
@ -308,7 +309,7 @@ pub struct Table<'a> {
|
||||
colours: &'a Colours,
|
||||
env: &'a Environment,
|
||||
widths: TableWidths,
|
||||
time_format: &'a TimeFormat,
|
||||
time_format: TimeFormat,
|
||||
size_format: SizeFormat,
|
||||
git: Option<&'a GitCache>,
|
||||
}
|
||||
@ -330,8 +331,8 @@ impl<'a, 'f> Table<'a> {
|
||||
columns,
|
||||
git,
|
||||
env,
|
||||
time_format: &options.time_format,
|
||||
size_format: options.size_format,
|
||||
time_format: options.time_format,
|
||||
size_format: options.size_format,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ pub enum TimeFormat {
|
||||
// timestamps are separate types.
|
||||
|
||||
impl TimeFormat {
|
||||
pub fn format_local(&self, time: SystemTime) -> String {
|
||||
pub fn format_local(self, time: SystemTime) -> String {
|
||||
match self {
|
||||
Self::DefaultFormat => default_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 {
|
||||
Self::DefaultFormat => default_zoned(time, zone),
|
||||
Self::ISOFormat => iso_zoned(time, zone),
|
||||
|
Loading…
Reference in New Issue
Block a user