Fix some clippy lints, and format
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Alexandru Macovei · committed by David Peter · parent f31fb9b · Browse files · 5 files·+22 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+22 added−28 removed
- tests:+5 added−14 removed
- other:+17 added−14 removed
Provenance
- Commit
4f43301- Tree
1ebfffe- Author
Alexandru Macovei <alexnmaco@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
f31fb9b
5 files changed+22 added−28 removed
modified:src/exec/input.rs+3 added-3 removed
3 unmodified lines4 use crate::filesystem::strip_current_dir;5 6 /// Removes the parent component of the path7 pub fn basename(path: &Path) -> &OsStr {8- path.file_name().unwrap_or(path.as_os_str())8+ path.file_name().unwrap_or_else(|| path.as_os_str())9 }10 11 /// Removes the extension from the path12 pub fn remove_extension(path: &Path) -> OsString {13 let dirname = dirname(path);14- let stem = path.file_stem().unwrap_or(path.as_os_str());14+ let stem = path.file_stem().unwrap_or_else(|| path.as_os_str());15 16 let path = PathBuf::from(dirname).join(stem);17 18 strip_current_dir(&path).to_owned().into_os_string()8 unmodified lines27 } else {28 p.as_os_str().to_owned()29 }30 })31- .unwrap_or(path.as_os_str().to_owned())31+ .unwrap_or_else(|| path.as_os_str().to_owned())32 }33 34 #[cfg(test)]35 mod path_tests {52 unmodified linesmodified:src/exec/mod.rs+1 added-1 removed
199 unmodified lines200 _ => false,201 }202 }203 204- pub fn generate<'a>(&'a self, path: impl AsRef<Path>) -> OsString {204+ pub fn generate(&self, path: impl AsRef<Path>) -> OsString {205 use self::Token::*;206 207 match *self {208 ArgumentTemplate::Tokens(ref tokens) => {132 unmodified linesmodified:src/main.rs+12 added-9 removed
63 unmodified lines64 // Get the search pattern65 let pattern = matches66 .value_of_os("pattern")67 .map(|p| {68- p.to_str().ok_or(anyhow!(69- "The search pattern includes invalid UTF-8 sequences."70- ))68+ p.to_str()69+ .ok_or_else(|| anyhow!("The search pattern includes invalid UTF-8 sequences."))70 })71 .transpose()?72 .unwrap_or("");73 46 unmodified lines120 sep = std::path::MAIN_SEPARATOR,121 ));122 }123 125- let pattern_regex = if matches.is_present("glob") && pattern.len() > 0 {124+ let pattern_regex = if matches.is_present("glob") && !pattern.is_empty() {125 let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;126 glob.regex().to_owned()127 } else if matches.is_present("fixed-strings") {128 // Treat pattern as literal string if '--fixed-strings' is used44 unmodified lines173 ]174 };175 176 let cmd: Vec<&str> = if cfg!(unix) {178- if !cfg!(any(target_os = "macos", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")) {177+ if !cfg!(any(178+ target_os = "macos",179+ target_os = "dragonfly",180+ target_os = "freebsd",181+ target_os = "netbsd",182+ target_os = "openbsd"183+ )) {184 // Assume ls is GNU ls185 gnu_ls("ls")186 } else {187 // MacOS, DragonFlyBSD, FreeBSD55 unmodified lines243 };244 245 let size_limits = if let Some(vs) = matches.values_of("size") {246 vs.map(|sf| {242- SizeFilter::from_string(sf).ok_or(anyhow!(243- "'{}' is not a valid size constraint. See 'fd --help'.",244- sf245- ))247+ SizeFilter::from_string(sf)248+ .ok_or_else(|| anyhow!("'{}' is not a valid size constraint. See 'fd --help'.", sf))249 })250 .collect::<Result<Vec<_>>>()?251 } else {252 vec![]151 unmodified linesmodified:src/output.rs+1 added-1 removed
9 unmodified lines10 use crate::exit_codes::ExitCode;11 use crate::filesystem::strip_current_dir;12 use crate::options::Options;13 14-pub fn replace_path_separator<'a>(path: &str, new_path_separator: &str) -> String {14+pub fn replace_path_separator(path: &str, new_path_separator: &str) -> String {15 path.replace(std::path::MAIN_SEPARATOR, &new_path_separator)16 }17 18 // TODO: this function is performance critical and can probably be optimized102 unmodified linesmodified:tests/tests.rs+5 added-14 removed
7 unmodified lines8 use regex::escape;9 10 use crate::testenv::TestEnv;11 12-static DEFAULT_DIRS: &'static [&'static str] = &["one/two/three", "one/two/three/directory_foo"];12+static DEFAULT_DIRS: &[&str] = &["one/two/three", "one/two/three/directory_foo"];13 14-static DEFAULT_FILES: &'static [&'static str] = &[14+static DEFAULT_FILES: &[&str] = &[15 "a.foo",16 "one/b.foo",17 "one/two/c.foo",18 "one/two/C.Foo2",68 unmodified lines87 one/two/three/d.foo88 one/two/three/directory_foo89 symlink";90 91- te.assert_output(92- &["--regex"],93- expected,94- );95- te.assert_output(96- &["--fixed-strings"],97- expected,98- );99- te.assert_output(100- &["--glob"],101- expected,102- );91+ te.assert_output(&["--regex"], expected);92+ te.assert_output(&["--fixed-strings"], expected);93+ te.assert_output(&["--glob"], expected);94 }95 96 /// Test multiple directory searches97 #[test]1477 unmodified lines