mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-09-27 20:59:02 +00:00
Merge pull request #154 from neosilky/clippy-fixes
Fix some issues indicated by clippy
This commit is contained in:
commit
3087565c01
@ -70,7 +70,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
||||
self.args.push(".".to_owned());
|
||||
}
|
||||
|
||||
for file_name in self.args.iter() {
|
||||
for file_name in &self.args {
|
||||
match File::from_path(Path::new(&file_name), None) {
|
||||
Err(e) => {
|
||||
exit_status = 2;
|
||||
|
@ -45,16 +45,16 @@ impl Dir {
|
||||
|
||||
/// Produce an iterator of IO results of trying to read all the files in
|
||||
/// this directory.
|
||||
pub fn files<'dir>(&'dir self) -> Files<'dir> {
|
||||
pub fn files(&self) -> Files {
|
||||
Files {
|
||||
inner: self.contents.iter(),
|
||||
dir: &self,
|
||||
dir: self,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether this directory contains a file with the given path.
|
||||
pub fn contains(&self, path: &Path) -> bool {
|
||||
self.contents.iter().any(|ref p| p.as_path() == path)
|
||||
self.contents.iter().any(|p| p.as_path() == path)
|
||||
}
|
||||
|
||||
/// Append a path onto the path specified by this directory.
|
||||
|
@ -15,11 +15,11 @@ pub trait FileAttributes {
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
impl FileAttributes for Path {
|
||||
fn attributes(&self) -> io::Result<Vec<Attribute>> {
|
||||
list_attrs(lister::Lister::new(FollowSymlinks::Yes), &self)
|
||||
list_attrs(&lister::Lister::new(FollowSymlinks::Yes), self)
|
||||
}
|
||||
|
||||
fn symlink_attributes(&self) -> io::Result<Vec<Attribute>> {
|
||||
list_attrs(lister::Lister::new(FollowSymlinks::No), &self)
|
||||
list_attrs(&lister::Lister::new(FollowSymlinks::No), self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ pub struct Attribute {
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
||||
pub fn list_attrs(lister: lister::Lister, path: &Path) -> io::Result<Vec<Attribute>> {
|
||||
pub fn list_attrs(lister: &lister::Lister, path: &Path) -> io::Result<Vec<Attribute>> {
|
||||
use std::ffi::CString;
|
||||
|
||||
let c_path = match path.to_str().and_then(|s| { CString::new(s).ok() }) {
|
||||
|
@ -154,7 +154,7 @@ impl<'dir> File<'dir> {
|
||||
/// beginning with a dot represent system or configuration files, and
|
||||
/// should be hidden by default.
|
||||
pub fn is_dotfile(&self) -> bool {
|
||||
self.name.starts_with(".")
|
||||
self.name.starts_with('.')
|
||||
}
|
||||
|
||||
/// Assuming the current file is a symlink, follows the link and
|
||||
@ -403,7 +403,7 @@ impl<'dir> File<'dir> {
|
||||
|
||||
impl<'a> AsRef<File<'a>> for File<'a> {
|
||||
fn as_ref(&self) -> &File<'a> {
|
||||
&self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,8 @@ impl<'a> File<'a> {
|
||||
}
|
||||
|
||||
pub fn is_temp(&self) -> bool {
|
||||
self.name.ends_with("~")
|
||||
|| (self.name.starts_with("#") && self.name.ends_with("#"))
|
||||
self.name.ends_with('~')
|
||||
|| (self.name.starts_with('#') && self.name.ends_with('#'))
|
||||
|| self.extension_is_one_of( &[ "tmp", "swp", "swo", "swn", "bak" ])
|
||||
}
|
||||
|
||||
|
@ -138,9 +138,9 @@ impl Options {
|
||||
/// Determines the complete set of options based on the given command-line
|
||||
/// arguments, after they’ve been parsed.
|
||||
fn deduce(matches: &getopts::Matches) -> Result<Options, Misfire> {
|
||||
let dir_action = DirAction::deduce(&matches)?;
|
||||
let filter = FileFilter::deduce(&matches)?;
|
||||
let view = View::deduce(&matches, filter.clone(), dir_action)?;
|
||||
let dir_action = DirAction::deduce(matches)?;
|
||||
let filter = FileFilter::deduce(matches)?;
|
||||
let view = View::deduce(matches, filter.clone(), dir_action)?;
|
||||
|
||||
Ok(Options {
|
||||
dir_action: dir_action,
|
||||
|
@ -91,9 +91,9 @@ impl View {
|
||||
|
||||
if let Some(&width) = term_width.as_ref() {
|
||||
let colours = match term_colours {
|
||||
TerminalColours::Always => Colours::colourful(colour_scale()),
|
||||
TerminalColours::Always
|
||||
| TerminalColours::Automatic => Colours::colourful(colour_scale()),
|
||||
TerminalColours::Never => Colours::plain(),
|
||||
TerminalColours::Automatic => Colours::colourful(colour_scale()),
|
||||
};
|
||||
|
||||
if matches.opt_present("oneline") {
|
||||
@ -137,8 +137,7 @@ impl View {
|
||||
|
||||
let colours = match term_colours {
|
||||
TerminalColours::Always => Colours::colourful(colour_scale()),
|
||||
TerminalColours::Never => Colours::plain(),
|
||||
TerminalColours::Automatic => Colours::plain(),
|
||||
TerminalColours::Never | TerminalColours::Automatic => Colours::plain(),
|
||||
};
|
||||
|
||||
if matches.opt_present("tree") {
|
||||
@ -221,9 +220,9 @@ impl TerminalWidth {
|
||||
|
||||
fn as_ref(&self) -> Option<&usize> {
|
||||
match *self {
|
||||
TerminalWidth::Set(ref width) => Some(width),
|
||||
TerminalWidth::Terminal(ref width) => Some(width),
|
||||
TerminalWidth::Unset => None,
|
||||
TerminalWidth::Set(ref width)
|
||||
| TerminalWidth::Terminal(ref width) => Some(width),
|
||||
TerminalWidth::Unset => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -345,7 +344,7 @@ impl TerminalColours {
|
||||
|
||||
/// Determine which terminal colour conditions to use.
|
||||
fn deduce(matches: &getopts::Matches) -> Result<TerminalColours, Misfire> {
|
||||
if let Some(word) = matches.opt_str("color").or(matches.opt_str("colour")) {
|
||||
if let Some(word) = matches.opt_str("color").or_else(|| matches.opt_str("colour")) {
|
||||
match &*word {
|
||||
"always" => Ok(TerminalColours::Always),
|
||||
"auto" | "automatic" => Ok(TerminalColours::Automatic),
|
||||
|
@ -27,11 +27,11 @@ impl Column {
|
||||
/// Get the alignment this column should use.
|
||||
pub fn alignment(&self) -> Alignment {
|
||||
match *self {
|
||||
Column::FileSize(_) => Alignment::Right,
|
||||
Column::HardLinks => Alignment::Right,
|
||||
Column::Inode => Alignment::Right,
|
||||
Column::Blocks => Alignment::Right,
|
||||
Column::GitStatus => Alignment::Right,
|
||||
Column::FileSize(_)
|
||||
| Column::HardLinks
|
||||
| Column::Inode
|
||||
| Column::Blocks
|
||||
| Column::GitStatus => Alignment::Right,
|
||||
_ => Alignment::Left,
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ impl Details {
|
||||
// Build the table to put rows in.
|
||||
let mut table = Table {
|
||||
columns: &*columns_for_dir,
|
||||
opts: &self,
|
||||
opts: self,
|
||||
env: env,
|
||||
rows: Vec::new(),
|
||||
};
|
||||
@ -306,7 +306,7 @@ impl Details {
|
||||
let mut width = DisplayWidth::from(&*egg.file.name);
|
||||
|
||||
if egg.file.dir.is_none() {
|
||||
if let Some(ref parent) = egg.file.path.parent() {
|
||||
if let Some(parent) = egg.file.path.parent() {
|
||||
width = width + 1 + DisplayWidth::from(parent.to_string_lossy().as_ref());
|
||||
}
|
||||
}
|
||||
@ -456,7 +456,7 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
|
||||
let mut width = DisplayWidth::from(&*file.name);
|
||||
|
||||
if file.dir.is_none() {
|
||||
if let Some(ref parent) = file.path.parent() {
|
||||
if let Some(parent) = file.path.parent() {
|
||||
width = width + 1 + DisplayWidth::from(parent.to_string_lossy().as_ref());
|
||||
}
|
||||
}
|
||||
@ -481,7 +481,7 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
|
||||
/// Use the list of columns to find which cells should be produced for
|
||||
/// this file, per-column.
|
||||
pub fn cells_for_file(&self, file: &File, xattrs: bool) -> Vec<TextCell> {
|
||||
self.columns.clone().iter()
|
||||
self.columns.iter()
|
||||
.map(|c| self.display(file, c, xattrs))
|
||||
.collect()
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ impl Grid {
|
||||
let mut width = DisplayWidth::from(&*file.name);
|
||||
|
||||
if file.dir.is_none() {
|
||||
if let Some(ref parent) = file.path.parent() {
|
||||
if let Some(parent) = file.path.parent() {
|
||||
width = width + 1 + DisplayWidth::from(parent.to_string_lossy().as_ref());
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ impl GridDetails {
|
||||
|
||||
if self.grid.across {
|
||||
for row in 0 .. height {
|
||||
for column in columns.iter() {
|
||||
for column in &columns {
|
||||
if row < column.len() {
|
||||
let cell = grid::Cell {
|
||||
contents: ANSIStrings(&column[row].contents).to_string(),
|
||||
@ -135,7 +135,7 @@ impl GridDetails {
|
||||
}
|
||||
}
|
||||
else {
|
||||
for column in columns.iter() {
|
||||
for column in &columns {
|
||||
for cell in column.iter() {
|
||||
let cell = grid::Cell {
|
||||
contents: ANSIStrings(&cell.contents).to_string(),
|
||||
|
@ -23,7 +23,7 @@ pub fn filename(file: &File, colours: &Colours, links: bool) -> TextCellContents
|
||||
let mut bits = Vec::new();
|
||||
|
||||
if file.dir.is_none() {
|
||||
if let Some(ref parent) = file.path.parent() {
|
||||
if let Some(parent) = file.path.parent() {
|
||||
let coconut = parent.components().count();
|
||||
|
||||
if coconut == 1 && parent.has_root() {
|
||||
@ -37,7 +37,7 @@ pub fn filename(file: &File, colours: &Colours, links: bool) -> TextCellContents
|
||||
}
|
||||
|
||||
if !file.name.is_empty() {
|
||||
bits.push(file_colour(colours, &file).paint(file.name.clone()));
|
||||
bits.push(file_colour(colours, file).paint(file.name.clone()));
|
||||
}
|
||||
|
||||
if links && file.is_link() {
|
||||
@ -47,7 +47,7 @@ pub fn filename(file: &File, colours: &Colours, links: bool) -> TextCellContents
|
||||
bits.push(colours.punctuation.paint("->"));
|
||||
bits.push(Style::default().paint(" "));
|
||||
|
||||
if let Some(ref parent) = target.path.parent() {
|
||||
if let Some(parent) = target.path.parent() {
|
||||
let coconut = parent.components().count();
|
||||
|
||||
if coconut == 1 && parent.has_root() {
|
||||
|
Loading…
Reference in New Issue
Block a user