Re-enable code style check

This commit is contained in:
sharkdp 2018-01-01 12:16:43 +01:00 committed by David Peter
parent aeb3722b69
commit a5f5ad6254
13 changed files with 102 additions and 146 deletions

View File

@ -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

View File

@ -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")

View File

@ -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())

View File

@ -150,7 +150,7 @@ impl ArgumentTemplate {
#[cfg(test)]
mod tests {
use super::{CommandTemplate, ArgumentTemplate, Token};
use super::{ArgumentTemplate, CommandTemplate, Token};
#[test]
fn tokens() {

View File

@ -23,9 +23,12 @@ pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {
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)
}

View File

@ -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,

View File

@ -18,43 +18,9 @@ pub type ExtensionStyles = HashMap<String, Style>;
pub type FilenameStyles = HashMap<String, Style>;
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.

View File

@ -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::<Vec<_>>()
}
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::<Vec<_>>(),
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()),
}

View File

@ -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 {

View File

@ -49,9 +49,9 @@ pub enum FileType {
/// path will simply be written to standard output.
pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
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<Regex>, config: Arc<FdOptions>) {
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<Regex>, config: Arc<FdOptions>) {
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<Regex>, config: Arc<FdOptions>) {
}
// 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;
}

View File

@ -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;

View File

@ -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::<Vec<_>>();

View File

@ -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");
}