Re-enable code style check
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by David Peter · parent aeb3722 · Browse files · 13 files·+102 added−146 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
13 files+102 added−146 removed
- tests:+10 added−17 removed
- other:+92 added−129 removed
Provenance
- Commit
a5f5ad6- Tree
42016ff- Author
sharkdp <davidpeter@web.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
aeb3722
13 files changed+102 added−146 removed
modified:src/exec/input.rs+1 added-1 removed
70 unmodified lines71 }72 73 #[cfg(test)]74 mod tests {75- use super::{MAIN_SEPARATOR, basename, dirname, remove_extension};75+ use super::{basename, dirname, remove_extension, MAIN_SEPARATOR};76 77 fn correct(input: &str) -> String {78 input.replace('/', &MAIN_SEPARATOR.to_string())79 }86 unmodified linesmodified:src/exec/mod.rs+1 added-1 removed
148 unmodified lines149 }150 151 #[cfg(test)]152 mod tests {153- use super::{CommandTemplate, ArgumentTemplate, Token};153+ use super::{ArgumentTemplate, CommandTemplate, Token};154 155 #[test]156 fn tokens() {157 let expected = CommandTemplate {20 unmodified linesmodified:src/fshelper/mod.rs+6 added-3 removed
21 unmodified lines22 pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {23 let path_buf = path_absolute_form(path)?;24 25 #[cfg(windows)]26- let path_buf = Path::new(path_buf.as_path().to_string_lossy().trim_left_matches(27- r"\\?\",28- )).to_path_buf();26+ let path_buf = Path::new(27+ path_buf28+ .as_path()29+ .to_string_lossy()30+ .trim_left_matches(r"\\?\"),31+ ).to_path_buf();32 33 Ok(path_buf)34 }35 9 unmodified linesmodified:src/lscolors/mod.rs+3 added-37 removed
16 unmodified lines17 /// Maps filenames to ANSI colors / styles.18 pub type FilenameStyles = HashMap<String, Style>;19 20 const LS_CODES: &[&str] = &[21- "no",22- "no",23- "fi",24- "rs",25- "di",26- "ln",27- "ln",28- "ln",29- "or",30- "mi",31- "pi",32- "pi",33- "so",34- "bd",35- "bd",36- "cd",37- "cd",38- "do",39- "ex",40- "lc",41- "lc",42- "rc",43- "rc",44- "ec",45- "ec",46- "su",47- "su",48- "sg",49- "sg",50- "st",51- "ow",52- "ow",53- "tw",54- "tw",55- "ca",56- "mh",57- "cl",21+ "no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi", "so", "bd", "bd", "cd",22+ "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec", "su", "su", "sg", "sg", "st", "ow", "ow",23+ "tw", "tw", "ca", "mh", "cl",24 ];25 26 /// Defines how different file system entries should be colorized / styled.27 #[derive(Debug, PartialEq)]205 unmodified linesmodified:src/app.rs+3 added-3 removed
28 unmodified lines29 30 pub fn build_app() -> App<'static, 'static> {31 let helps = usage();32 let arg = |name| {33- Arg::with_name(name).help(helps[name].short).long_help(34- helps[name].long,35- )33+ Arg::with_name(name)34+ .help(helps[name].short)35+ .long_help(helps[name].long)36 };37 38 App::new("fd")39 .version(crate_version!())188 unmodified linesmodified:src/internal.rs+4 added-7 removed
89 unmodified lines90 /// Determine if a regex expression contains a literal uppercase character.91 fn expr_has_uppercase_char(expr: &Expr) -> bool {92 match *expr {93 Expr::Literal { ref chars, .. } => chars.iter().any(|c| c.is_uppercase()),94- Expr::Class(ref ranges) => {95- ranges.iter().any(|r| {96- r.start.is_uppercase() || r.end.is_uppercase()97- })98- }99- Expr::Group { ref e, .. } |100- Expr::Repeat { ref e, .. } => expr_has_uppercase_char(e),94+ Expr::Class(ref ranges) => ranges95+ .iter()96+ .any(|r| r.start.is_uppercase() || r.end.is_uppercase()),97+ Expr::Group { ref e, .. } | Expr::Repeat { ref e, .. } => expr_has_uppercase_char(e),98 Expr::Concat(ref es) => es.iter().any(expr_has_uppercase_char),99 Expr::Alternate(ref es) => es.iter().any(expr_has_uppercase_char),100 _ => false,101 }1 unmodified linemodified:src/main.rs+42 added-39 removed
56 unmodified lines57 }58 59 //Get one or more root directories to search.60 let mut dir_vec: Vec<_> = match matches.values_of("path") {61- Some(paths) => {62- paths63- .map(|path| {64- let path_buffer = PathBuf::from(path);65- if !fshelper::is_dir(&path_buffer) {66- error(&format!(67- "Error: '{}' is not a directory.",68- path_buffer.to_string_lossy()69- ));70- }71- path_buffer72- })73- .collect::<Vec<_>>()61+ Some(paths) => paths62+ .map(|path| {63+ let path_buffer = PathBuf::from(path);64+ if !fshelper::is_dir(&path_buffer) {65+ error(&format!(66+ "Error: '{}' is not a directory.",67+ path_buffer.to_string_lossy()68+ ));69+ }70+ path_buffer71+ })72+ .collect::<Vec<_>>(),74- }73 None => vec![current_dir.to_path_buf()],74 };75 76 if matches.is_present("absolute-path") {4 unmodified lines81 }82 83 // The search will be case-sensitive if the command line flag is set or84 // if the pattern has an uppercase character (smart case).87- let case_sensitive = !matches.is_present("ignore-case") &&88- (matches.is_present("case-sensitive") || pattern_has_uppercase_char(pattern));85+ let case_sensitive = !matches.is_present("ignore-case")86+ && (matches.is_present("case-sensitive") || pattern_has_uppercase_char(pattern));87 88 let colored_output = match matches.value_of("color") {89 Some("always") => true,90 Some("never") => false,18 unmodified lines109 110 let config = FdOptions {111 case_sensitive,112 search_full_path: matches.is_present("full-path"),115- ignore_hidden: !(matches.is_present("hidden") ||116- matches.occurrences_of("rg-alias-hidden-ignore") >= 2),117- read_ignore: !(matches.is_present("no-ignore") ||118- matches.is_present("rg-alias-hidden-ignore")),119- read_gitignore: !(matches.is_present("no-ignore") ||120- matches.is_present("rg-alias-hidden-ignore") ||121- matches.is_present("no-ignore-vcs")),113+ ignore_hidden: !(matches.is_present("hidden")114+ || matches.occurrences_of("rg-alias-hidden-ignore") >= 2),115+ read_ignore: !(matches.is_present("no-ignore")116+ || matches.is_present("rg-alias-hidden-ignore")),117+ read_gitignore: !(matches.is_present("no-ignore")118+ || matches.is_present("rg-alias-hidden-ignore")119+ || matches.is_present("no-ignore-vcs")),120 follow_links: matches.is_present("follow"),121 null_separator: matches.is_present("null_separator"),124- max_depth: matches.value_of("depth").and_then(|n| {125- usize::from_str_radix(n, 10).ok()126- }),122+ max_depth: matches123+ .value_of("depth")124+ .and_then(|n| usize::from_str_radix(n, 10).ok()),125 threads: std::cmp::max(126 matches127 .value_of("threads")128 .and_then(|n| usize::from_str_radix(n, 10).ok())5 unmodified lines134 .and_then(|n| u64::from_str_radix(n, 10).ok())135 .map(time::Duration::from_millis),136 ls_colors,137 file_types: match matches.values_of("file-type") {140- None => vec![FileType::RegularFile,141- FileType::Directory,142- FileType::SymLink]143- .into_iter().collect(),144- Some(values) => values.map(|value| match value {145- "f" | "file" => FileType::RegularFile,146- "d" | "directory" => FileType::Directory,147- "l" | "symlink" => FileType::SymLink,148- _ => FileType::RegularFile,149- }).collect()138+ None => vec![139+ FileType::RegularFile,140+ FileType::Directory,141+ FileType::SymLink,142+ ].into_iter()143+ .collect(),144+ Some(values) => values145+ .map(|value| match value {146+ "f" | "file" => FileType::RegularFile,147+ "d" | "directory" => FileType::Directory,148+ "l" | "symlink" => FileType::SymLink,149+ _ => FileType::RegularFile,150+ })151+ .collect(),152 },153 extensions: matches.values_of("extension").map(|exts| {152- exts.map(|e| e.trim_left_matches('.').to_lowercase()).collect()154+ exts.map(|e| e.trim_left_matches('.').to_lowercase())155+ .collect()156 }),157 command,158 exclude_patterns: matches159 .values_of("exclude")160 .map(|v| v.map(|p| String::from("!") + p).collect())161 .unwrap_or_else(|| vec![]),162 };163 161-164 match RegexBuilder::new(pattern)165 .case_insensitive(!config.case_sensitive)166 .dot_matches_new_line(true)165- .build() {167+ .build()168+ {169 Ok(re) => walk::scan(&dir_vec, Arc::new(re), Arc::new(config)),170 Err(err) => error(err.description()),171 }172 }modified:src/output.rs+7 added-9 removed
10 unmodified lines11 12 use std::{fs, process};13 use std::io::{self, Write};14 use std::ops::Deref;15-use std::path::{self, Path, PathBuf, Component};15+use std::path::{self, Component, Path, PathBuf};16 use std::sync::Arc;17 use std::sync::atomic::{AtomicBool, Ordering};18 #[cfg(any(unix, target_os = "redox"))]19 use std::os::unix::fs::PermissionsExt;87 unmodified lines107 if metadata.as_ref().map(|md| md.is_dir()).unwrap_or(false) {108 Some(&ls_colors.directory)109 } else if metadata.map(|md| is_executable(&md)).unwrap_or(false) {110 Some(&ls_colors.executable)111- } else if let Some(filename_style) =112- path.file_name().and_then(|n| n.to_str()).and_then(|n| {113- ls_colors.filenames.get(n)114- })111+ } else if let Some(filename_style) = path.file_name()112+ .and_then(|n| n.to_str())113+ .and_then(|n| ls_colors.filenames.get(n))114 {115 Some(filename_style)117- } else if let Some(extension_style) =118- path.extension().and_then(|e| e.to_str()).and_then(|e| {119- ls_colors.extensions.get(e)120- })116+ } else if let Some(extension_style) = path.extension()117+ .and_then(|e| e.to_str())118+ .and_then(|e| ls_colors.extensions.get(e))119 {120 Some(extension_style)121 } else {122 None12 unmodified linesmodified:src/walk.rs+20 added-17 removed
47 unmodified lines48 /// jobs in parallel from a given command line and the discovered paths. Otherwise, each49 /// path will simply be written to standard output.50 pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {51 let mut path_iter = path_vec.iter();52- let first_path_buf = path_iter.next().expect(53- "Error: Path vector can not be empty",54- );52+ let first_path_buf = path_iter53+ .next()54+ .expect("Error: Path vector can not be empty");55 let (tx, rx) = channel();56 let threads = config.threads;57 58 let mut override_builder = OverrideBuilder::new(first_path_buf.as_path());28 unmodified lines87 88 let wants_to_quit = Arc::new(AtomicBool::new(false));89 if config.ls_colors.is_some() {90 let wq = Arc::clone(&wants_to_quit);91- ctrlc::set_handler(move || { wq.store(true, Ordering::Relaxed); }).unwrap();91+ ctrlc::set_handler(move || {92+ wq.store(true, Ordering::Relaxed);93+ }).unwrap();94 }95 96 // Spawn the thread that receives all results through the channel.97 let rx_config = Arc::clone(&config);36 unmodified lines134 // Start in buffering mode135 let mut mode = ReceiverMode::Buffering;136 137 // Maximum time to wait before we start streaming to the console.136- let max_buffer_time = rx_config.max_buffer_time.unwrap_or_else(137- || time::Duration::from_millis(100),138- );138+ let max_buffer_time = rx_config139+ .max_buffer_time140+ .unwrap_or_else(|| time::Duration::from_millis(100));141 142 for value in rx {143 match mode {144 ReceiverMode::Buffering => {46 unmodified lines191 return ignore::WalkState::Continue;192 }193 194 // Filter out unwanted file types.193- if (entry.file_type().map_or(false, |ft| ft.is_file()) &&194- !config.file_types.contains(&FileType::RegularFile)) ||195- (entry.file_type().map_or(false, |ft| ft.is_dir()) &&196- !config.file_types.contains(&FileType::Directory)) ||197- (entry.file_type().map_or(false, |ft| ft.is_symlink()) &&198- !config.file_types.contains(&FileType::SymLink)) {199- return ignore::WalkState::Continue;195+ if (entry.file_type().map_or(false, |ft| ft.is_file())196+ && !config.file_types.contains(&FileType::RegularFile))197+ || (entry.file_type().map_or(false, |ft| ft.is_dir())198+ && !config.file_types.contains(&FileType::Directory))199+ || (entry.file_type().map_or(false, |ft| ft.is_symlink())200+ && !config.file_types.contains(&FileType::SymLink))201+ {202+ return ignore::WalkState::Continue;203 }204 205 // Filter out unwanted extensions.206 if let Some(ref filter_exts) = config.extensions {204- let entry_ext = entry_path.extension().map(205- |e| e.to_string_lossy().to_lowercase(),206- );207+ let entry_ext = entry_path208+ .extension()209+ .map(|e| e.to_string_lossy().to_lowercase());210 if entry_ext.map_or(true, |ext| !filter_exts.contains(&ext)) {211 return ignore::WalkState::Continue;212 }213 }28 unmodified linesmodified:src/windows.rs+2 added-2 removed
7 unmodified lines8 9 extern crate kernel32;10 extern crate winapi;11 12-use self::kernel32::{GetStdHandle, GetConsoleMode, SetConsoleMode};13-use self::winapi::{STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE};12+use self::kernel32::{GetConsoleMode, GetStdHandle, SetConsoleMode};13+use self::winapi::{INVALID_HANDLE_VALUE, STD_OUTPUT_HANDLE};14 15 const ENABLE_VIRTUAL_TERMINAL_PROCESSING: u32 = 0x0004;16 17 // https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example22 unmodified linesmodified:tests/testenv/mod.rs+8 added-9 removed
50 unmodified lines51 for file in files {52 fs::File::create(root.join(file))?;53 }54 55+ #[cfg(unix)]55- #[cfg(unix)] unix::fs::symlink(root.join("one/two"), root.join("symlink"))?;56+ unix::fs::symlink(root.join("one/two"), root.join("symlink"))?;57 58 // Note: creating symlinks on Windows requires the `SeCreateSymbolicLinkPrivilege` which59 // is by default only granted for administrators.60+ #[cfg(windows)]59- #[cfg(windows)] windows::fs::symlink_dir(root.join("one/two"), root.join("symlink"))?;61+ windows::fs::symlink_dir(root.join("one/two"), root.join("symlink"))?;62 61- fs::File::create(root.join(".ignore"))?.write_all(62- b"ignored.foo",63- )?;63+ fs::File::create(root.join(".ignore"))?.write_all(b"ignored.foo")?;64 65- fs::File::create(root.join(".gitignore"))?.write_all(66- b"gitignored.foo",67- )?;65+ fs::File::create(root.join(".gitignore"))?.write_all(b"gitignored.foo")?;66 }67 68 Ok(temp_dir)69 }52 unmodified lines122 // Split into lines and normalize separators.123 let mut lines = s.replace('\0', "NULL\n")124 .lines()125 .map(|line| {126+ let line =128- let line = if trim_left { line.trim_left() } else { line };127+ if trim_left { line.trim_left() } else { line };128 line.replace('/', &std::path::MAIN_SEPARATOR.to_string())129 })130 .collect::<Vec<_>>();131 63 unmodified linesmodified:tests/tests.rs+2 added-8 removed
468 unmodified lines469 one/two/C.Foo2470 one/two/three/d.foo",471 );472 473- te.assert_output(474- &["--type", "f", "e1"],475- "e1 e2",476- );473+ te.assert_output(&["--type", "f", "e1"], "e1 e2");474 475 te.assert_output(476 &["--type", "d"],477 "one43 unmodified lines521 one/two/three/d.foo522 one/two/C.Foo2",523 );524 528- te.assert_output(529- &["--extension", ".foo", "a"],530- "a.foo",531- );525+ te.assert_output(&["--extension", ".foo", "a"], "a.foo");526 527 te.assert_output(&["--extension", "foo2"], "one/two/C.Foo2");528 }529 225 unmodified linesmodified:.travis.yml+3 added-10 removed
1 language: rust2 cache: cargo3 matrix:4- allow_failures:5- - rust: nightly4+ # allow_failures:5+ # - rust: nightly6 include:7 # Stable channel.8 - os: linux9 rust: stable63 unmodified lines73 - os: osx74 rust: 1.20.075 env: TARGET=x86_64-apple-darwin76 77- # # Code formatting check78- # - os: linux79- # rust: stable80- # # skip the global install step81- # install:82- # - which cargo-install-update || cargo install cargo-update83- # - cargo install-update -i rustfmt84- # script: cargo fmt -- --write-mode=diff77+ # Code formatting check78 - os: linux79 rust: nightly80 # skip the global install step81 install:59 unmodified lines