Skip to content
Myr

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

5 files+22 added−28 removed

modified:src/exec/input.rs+3 added-3 removed
3 unmodified lines
4use crate::filesystem::strip_current_dir;56/// Removes the parent component of the path7pub 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}1011/// Removes the extension from the path12pub 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());1516 let path = PathBuf::from(dirname).join(stem);1718 strip_current_dir(&path).to_owned().into_os_string()
8 unmodified lines
27 } 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}3334#[cfg(test)]35mod path_tests {
52 unmodified lines
modified:src/exec/mod.rs+1 added-1 removed
199 unmodified lines
200 _ => false,201 }202 }203204 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::*;206207 match *self {208 ArgumentTemplate::Tokens(ref tokens) => {
132 unmodified lines
modified:src/main.rs+12 added-9 removed
63 unmodified lines
64 // 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 lines
120 sep = std::path::MAIN_SEPARATOR,121 ));122 }123125 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 used
44 unmodified lines
173 ]174 };175176 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, FreeBSD
55 unmodified lines
243 };244245 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 lines
modified:src/output.rs+1 added-1 removed
9 unmodified lines
10use crate::exit_codes::ExitCode;11use crate::filesystem::strip_current_dir;12use crate::options::Options;1314pub fn replace_path_separator<'a>(path: &str, new_path_separator: &str) -> String {14pub fn replace_path_separator(path: &str, new_path_separator: &str) -> String {15 path.replace(std::path::MAIN_SEPARATOR, &new_path_separator)16}1718// TODO: this function is performance critical and can probably be optimized
102 unmodified lines
modified:tests/tests.rs+5 added-14 removed
7 unmodified lines
8use regex::escape;910use crate::testenv::TestEnv;1112static DEFAULT_DIRS: &'static [&'static str] = &["one/two/three", "one/two/three/directory_foo"];12static DEFAULT_DIRS: &[&str] = &["one/two/three", "one/two/three/directory_foo"];1314static DEFAULT_FILES: &'static [&'static str] = &[14static DEFAULT_FILES: &[&str] = &[15 "a.foo",16 "one/b.foo",17 "one/two/c.foo",18 "one/two/C.Foo2",
68 unmodified lines
87 one/two/three/d.foo88 one/two/three/directory_foo89 symlink";9091 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}9596/// Test multiple directory searches97#[test]
1477 unmodified lines