diff --git a/.travis.yml b/.travis.yml index 5dc7c43..e87317d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: rust cache: cargo matrix: - allow_failures: - - rust: nightly + # allow_failures: + # - rust: nightly include: # Stable channel. - os: linux @@ -74,14 +74,7 @@ matrix: rust: 1.20.0 env: TARGET=x86_64-apple-darwin - # # Code formatting check - # - os: linux - # rust: stable - # # skip the global install step - # install: - # - which cargo-install-update || cargo install cargo-update - # - cargo install-update -i rustfmt - # script: cargo fmt -- --write-mode=diff + # Code formatting check - os: linux rust: nightly # skip the global install step diff --git a/src/app.rs b/src/app.rs index efb44dd..a0d3e14 100644 --- a/src/app.rs +++ b/src/app.rs @@ -30,9 +30,9 @@ macro_rules! doc { pub fn build_app() -> App<'static, 'static> { let helps = usage(); let arg = |name| { - Arg::with_name(name).help(helps[name].short).long_help( - helps[name].long, - ) + Arg::with_name(name) + .help(helps[name].short) + .long_help(helps[name].long) }; App::new("fd") diff --git a/src/exec/input.rs b/src/exec/input.rs index 0edd1a9..51f8182 100644 --- a/src/exec/input.rs +++ b/src/exec/input.rs @@ -72,7 +72,7 @@ pub fn dirname(path: &str) -> &str { #[cfg(test)] mod tests { - use super::{MAIN_SEPARATOR, basename, dirname, remove_extension}; + use super::{basename, dirname, remove_extension, MAIN_SEPARATOR}; fn correct(input: &str) -> String { input.replace('/', &MAIN_SEPARATOR.to_string()) diff --git a/src/exec/mod.rs b/src/exec/mod.rs index ce6a7a6..aafe2a9 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -150,7 +150,7 @@ impl ArgumentTemplate { #[cfg(test)] mod tests { - use super::{CommandTemplate, ArgumentTemplate, Token}; + use super::{ArgumentTemplate, CommandTemplate, Token}; #[test] fn tokens() { diff --git a/src/fshelper/mod.rs b/src/fshelper/mod.rs index 232b4a9..b473a76 100644 --- a/src/fshelper/mod.rs +++ b/src/fshelper/mod.rs @@ -23,9 +23,12 @@ pub fn absolute_path(path: &Path) -> io::Result { let path_buf = path_absolute_form(path)?; #[cfg(windows)] - let path_buf = Path::new(path_buf.as_path().to_string_lossy().trim_left_matches( - r"\\?\", - )).to_path_buf(); + let path_buf = Path::new( + path_buf + .as_path() + .to_string_lossy() + .trim_left_matches(r"\\?\"), + ).to_path_buf(); Ok(path_buf) } diff --git a/src/internal.rs b/src/internal.rs index e841fe7..206c381 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -91,13 +91,10 @@ pub fn pattern_has_uppercase_char(pattern: &str) -> bool { fn expr_has_uppercase_char(expr: &Expr) -> bool { match *expr { Expr::Literal { ref chars, .. } => chars.iter().any(|c| c.is_uppercase()), - Expr::Class(ref ranges) => { - ranges.iter().any(|r| { - r.start.is_uppercase() || r.end.is_uppercase() - }) - } - Expr::Group { ref e, .. } | - Expr::Repeat { ref e, .. } => expr_has_uppercase_char(e), + Expr::Class(ref ranges) => ranges + .iter() + .any(|r| r.start.is_uppercase() || r.end.is_uppercase()), + Expr::Group { ref e, .. } | Expr::Repeat { ref e, .. } => expr_has_uppercase_char(e), Expr::Concat(ref es) => es.iter().any(expr_has_uppercase_char), Expr::Alternate(ref es) => es.iter().any(expr_has_uppercase_char), _ => false, diff --git a/src/lscolors/mod.rs b/src/lscolors/mod.rs index 65ac193..466c7d4 100644 --- a/src/lscolors/mod.rs +++ b/src/lscolors/mod.rs @@ -18,43 +18,9 @@ pub type ExtensionStyles = HashMap; pub type FilenameStyles = HashMap; const LS_CODES: &[&str] = &[ - "no", - "no", - "fi", - "rs", - "di", - "ln", - "ln", - "ln", - "or", - "mi", - "pi", - "pi", - "so", - "bd", - "bd", - "cd", - "cd", - "do", - "ex", - "lc", - "lc", - "rc", - "rc", - "ec", - "ec", - "su", - "su", - "sg", - "sg", - "st", - "ow", - "ow", - "tw", - "tw", - "ca", - "mh", - "cl", + "no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi", "so", "bd", "bd", "cd", + "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec", "su", "su", "sg", "sg", "st", "ow", "ow", + "tw", "tw", "ca", "mh", "cl", ]; /// Defines how different file system entries should be colorized / styled. diff --git a/src/main.rs b/src/main.rs index bc1ecf6..36900c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,20 +58,18 @@ fn main() { //Get one or more root directories to search. let mut dir_vec: Vec<_> = match matches.values_of("path") { - Some(paths) => { - paths - .map(|path| { - let path_buffer = PathBuf::from(path); - if !fshelper::is_dir(&path_buffer) { - error(&format!( - "Error: '{}' is not a directory.", - path_buffer.to_string_lossy() - )); - } - path_buffer - }) - .collect::>() - } + Some(paths) => paths + .map(|path| { + let path_buffer = PathBuf::from(path); + if !fshelper::is_dir(&path_buffer) { + error(&format!( + "Error: '{}' is not a directory.", + path_buffer.to_string_lossy() + )); + } + path_buffer + }) + .collect::>(), None => vec![current_dir.to_path_buf()], }; @@ -84,8 +82,8 @@ fn main() { // The search will be case-sensitive if the command line flag is set or // if the pattern has an uppercase character (smart case). - let case_sensitive = !matches.is_present("ignore-case") && - (matches.is_present("case-sensitive") || pattern_has_uppercase_char(pattern)); + let case_sensitive = !matches.is_present("ignore-case") + && (matches.is_present("case-sensitive") || pattern_has_uppercase_char(pattern)); let colored_output = match matches.value_of("color") { Some("always") => true, @@ -112,18 +110,18 @@ fn main() { let config = FdOptions { case_sensitive, search_full_path: matches.is_present("full-path"), - ignore_hidden: !(matches.is_present("hidden") || - matches.occurrences_of("rg-alias-hidden-ignore") >= 2), - read_ignore: !(matches.is_present("no-ignore") || - matches.is_present("rg-alias-hidden-ignore")), - read_gitignore: !(matches.is_present("no-ignore") || - matches.is_present("rg-alias-hidden-ignore") || - matches.is_present("no-ignore-vcs")), + ignore_hidden: !(matches.is_present("hidden") + || matches.occurrences_of("rg-alias-hidden-ignore") >= 2), + read_ignore: !(matches.is_present("no-ignore") + || matches.is_present("rg-alias-hidden-ignore")), + read_gitignore: !(matches.is_present("no-ignore") + || matches.is_present("rg-alias-hidden-ignore") + || matches.is_present("no-ignore-vcs")), follow_links: matches.is_present("follow"), null_separator: matches.is_present("null_separator"), - max_depth: matches.value_of("depth").and_then(|n| { - usize::from_str_radix(n, 10).ok() - }), + max_depth: matches + .value_of("depth") + .and_then(|n| usize::from_str_radix(n, 10).ok()), threads: std::cmp::max( matches .value_of("threads") @@ -137,19 +135,24 @@ fn main() { .map(time::Duration::from_millis), ls_colors, file_types: match matches.values_of("file-type") { - None => vec![FileType::RegularFile, - FileType::Directory, - FileType::SymLink] - .into_iter().collect(), - Some(values) => values.map(|value| match value { - "f" | "file" => FileType::RegularFile, - "d" | "directory" => FileType::Directory, - "l" | "symlink" => FileType::SymLink, - _ => FileType::RegularFile, - }).collect() + None => vec![ + FileType::RegularFile, + FileType::Directory, + FileType::SymLink, + ].into_iter() + .collect(), + Some(values) => values + .map(|value| match value { + "f" | "file" => FileType::RegularFile, + "d" | "directory" => FileType::Directory, + "l" | "symlink" => FileType::SymLink, + _ => FileType::RegularFile, + }) + .collect(), }, extensions: matches.values_of("extension").map(|exts| { - exts.map(|e| e.trim_left_matches('.').to_lowercase()).collect() + exts.map(|e| e.trim_left_matches('.').to_lowercase()) + .collect() }), command, exclude_patterns: matches @@ -158,11 +161,11 @@ fn main() { .unwrap_or_else(|| vec![]), }; - match RegexBuilder::new(pattern) .case_insensitive(!config.case_sensitive) .dot_matches_new_line(true) - .build() { + .build() + { Ok(re) => walk::scan(&dir_vec, Arc::new(re), Arc::new(config)), Err(err) => error(err.description()), } diff --git a/src/output.rs b/src/output.rs index 4a23881..a3cd36f 100644 --- a/src/output.rs +++ b/src/output.rs @@ -12,7 +12,7 @@ use lscolors::LsColors; use std::{fs, process}; use std::io::{self, Write}; use std::ops::Deref; -use std::path::{self, Path, PathBuf, Component}; +use std::path::{self, Component, Path, PathBuf}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; #[cfg(any(unix, target_os = "redox"))] @@ -108,16 +108,14 @@ fn get_path_style<'a>(path: &Path, ls_colors: &'a LsColors) -> Option<&'a ansi_t Some(&ls_colors.directory) } else if metadata.map(|md| is_executable(&md)).unwrap_or(false) { Some(&ls_colors.executable) - } else if let Some(filename_style) = - path.file_name().and_then(|n| n.to_str()).and_then(|n| { - ls_colors.filenames.get(n) - }) + } else if let Some(filename_style) = path.file_name() + .and_then(|n| n.to_str()) + .and_then(|n| ls_colors.filenames.get(n)) { Some(filename_style) - } else if let Some(extension_style) = - path.extension().and_then(|e| e.to_str()).and_then(|e| { - ls_colors.extensions.get(e) - }) + } else if let Some(extension_style) = path.extension() + .and_then(|e| e.to_str()) + .and_then(|e| ls_colors.extensions.get(e)) { Some(extension_style) } else { diff --git a/src/walk.rs b/src/walk.rs index 1d5ee65..9b8dd5d 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -49,9 +49,9 @@ pub enum FileType { /// path will simply be written to standard output. pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { let mut path_iter = path_vec.iter(); - let first_path_buf = path_iter.next().expect( - "Error: Path vector can not be empty", - ); + let first_path_buf = path_iter + .next() + .expect("Error: Path vector can not be empty"); let (tx, rx) = channel(); let threads = config.threads; @@ -88,7 +88,9 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { let wants_to_quit = Arc::new(AtomicBool::new(false)); if config.ls_colors.is_some() { let wq = Arc::clone(&wants_to_quit); - ctrlc::set_handler(move || { wq.store(true, Ordering::Relaxed); }).unwrap(); + ctrlc::set_handler(move || { + wq.store(true, Ordering::Relaxed); + }).unwrap(); } // Spawn the thread that receives all results through the channel. @@ -133,9 +135,9 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { let mut mode = ReceiverMode::Buffering; // Maximum time to wait before we start streaming to the console. - let max_buffer_time = rx_config.max_buffer_time.unwrap_or_else( - || time::Duration::from_millis(100), - ); + let max_buffer_time = rx_config + .max_buffer_time + .unwrap_or_else(|| time::Duration::from_millis(100)); for value in rx { match mode { @@ -190,20 +192,21 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { } // Filter out unwanted file types. - if (entry.file_type().map_or(false, |ft| ft.is_file()) && - !config.file_types.contains(&FileType::RegularFile)) || - (entry.file_type().map_or(false, |ft| ft.is_dir()) && - !config.file_types.contains(&FileType::Directory)) || - (entry.file_type().map_or(false, |ft| ft.is_symlink()) && - !config.file_types.contains(&FileType::SymLink)) { - return ignore::WalkState::Continue; + if (entry.file_type().map_or(false, |ft| ft.is_file()) + && !config.file_types.contains(&FileType::RegularFile)) + || (entry.file_type().map_or(false, |ft| ft.is_dir()) + && !config.file_types.contains(&FileType::Directory)) + || (entry.file_type().map_or(false, |ft| ft.is_symlink()) + && !config.file_types.contains(&FileType::SymLink)) + { + return ignore::WalkState::Continue; } // Filter out unwanted extensions. if let Some(ref filter_exts) = config.extensions { - let entry_ext = entry_path.extension().map( - |e| e.to_string_lossy().to_lowercase(), - ); + let entry_ext = entry_path + .extension() + .map(|e| e.to_string_lossy().to_lowercase()); if entry_ext.map_or(true, |ext| !filter_exts.contains(&ext)) { return ignore::WalkState::Continue; } diff --git a/src/windows.rs b/src/windows.rs index d728461..9a3ad82 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -9,8 +9,8 @@ extern crate kernel32; extern crate winapi; -use self::kernel32::{GetStdHandle, GetConsoleMode, SetConsoleMode}; -use self::winapi::{STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE}; +use self::kernel32::{GetConsoleMode, GetStdHandle, SetConsoleMode}; +use self::winapi::{INVALID_HANDLE_VALUE, STD_OUTPUT_HANDLE}; const ENABLE_VIRTUAL_TERMINAL_PROCESSING: u32 = 0x0004; diff --git a/tests/testenv/mod.rs b/tests/testenv/mod.rs index eb75d48..1446028 100644 --- a/tests/testenv/mod.rs +++ b/tests/testenv/mod.rs @@ -52,19 +52,17 @@ fn create_working_directory( fs::File::create(root.join(file))?; } - #[cfg(unix)] unix::fs::symlink(root.join("one/two"), root.join("symlink"))?; + #[cfg(unix)] + unix::fs::symlink(root.join("one/two"), root.join("symlink"))?; // Note: creating symlinks on Windows requires the `SeCreateSymbolicLinkPrivilege` which // is by default only granted for administrators. - #[cfg(windows)] windows::fs::symlink_dir(root.join("one/two"), root.join("symlink"))?; + #[cfg(windows)] + windows::fs::symlink_dir(root.join("one/two"), root.join("symlink"))?; - fs::File::create(root.join(".ignore"))?.write_all( - b"ignored.foo", - )?; + fs::File::create(root.join(".ignore"))?.write_all(b"ignored.foo")?; - fs::File::create(root.join(".gitignore"))?.write_all( - b"gitignored.foo", - )?; + fs::File::create(root.join(".gitignore"))?.write_all(b"gitignored.foo")?; } Ok(temp_dir) @@ -125,7 +123,8 @@ fn normalize_output(s: &str, trim_left: bool) -> String { let mut lines = s.replace('\0', "NULL\n") .lines() .map(|line| { - let line = if trim_left { line.trim_left() } else { line }; + let line = + if trim_left { line.trim_left() } else { line }; line.replace('/', &std::path::MAIN_SEPARATOR.to_string()) }) .collect::>(); diff --git a/tests/tests.rs b/tests/tests.rs index a550bd6..a756bcc 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -470,10 +470,7 @@ fn test_type() { one/two/three/d.foo", ); - te.assert_output( - &["--type", "f", "e1"], - "e1 e2", - ); + te.assert_output(&["--type", "f", "e1"], "e1 e2"); te.assert_output( &["--type", "d"], @@ -525,10 +522,7 @@ fn test_extension() { one/two/C.Foo2", ); - te.assert_output( - &["--extension", ".foo", "a"], - "a.foo", - ); + te.assert_output(&["--extension", ".foo", "a"], "a.foo"); te.assert_output(&["--extension", "foo2"], "one/two/C.Foo2"); }