From 276db6872767dd2e2a9b3247d78432956b0810db Mon Sep 17 00:00:00 2001 From: Cameron Cordes Date: Fri, 22 May 2020 16:17:03 -0400 Subject: [PATCH] Fix lint issues --- src/filematch.rs | 2 +- src/main.rs | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/filematch.rs b/src/filematch.rs index 200e808..c64bca4 100644 --- a/src/filematch.rs +++ b/src/filematch.rs @@ -10,7 +10,7 @@ pub struct FileMatch { impl FileMatch { pub fn print(&self, config: &Config) { let cp = ColorPrinter { - config: config, + config, file_match: self, }; cp.print(); diff --git a/src/main.rs b/src/main.rs index 40f3bb7..968e25b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,19 +11,18 @@ fn main() { let config = Config::from_args(); let search_path = &config.path; - let path = match search_path.starts_with('/') { - true => Path::new(search_path), - false => { - let p: &'static str = Box::leak(Box::new(String::from("./") + search_path)); - Path::new(p) - } + let path = if search_path.starts_with('/') { + Path::new(search_path) + } else { + let p: &'static str = Box::leak(Box::new(String::from("./") + search_path)); + Path::new(p) }; let results = traverse_dir(&config, path, Option::None, |config, path| { check_file(config, path) }); match results { - Result::Ok(matches) if matches.len() == 0 => println!("No matches :("), + Result::Ok(matches) if matches.is_empty() => println!("No matches :("), Result::Ok(matches) => print_report(&config, &matches), Result::Err(msg) => println!("Error while parsing: {}", msg), } @@ -48,10 +47,10 @@ fn traverse_dir( let file = io::BufReader::new(File::open(g.path())?); file.lines() .map(|line| line.unwrap().trim().to_owned()) - .filter(|line| line.len() > 0 && !line.starts_with('#')) + .filter(|line| !line.is_empty() && !line.starts_with('#')) .collect::>() } - None => gitignore_entries.unwrap_or(Vec::new()), + None => gitignore_entries.unwrap_or_default(), }; for entry in entries { @@ -74,7 +73,7 @@ fn traverse_dir( traverse_dir(&config, &entry.path(), Some(gitignore.clone()), operation)?; let has_results = results .iter() - .filter({ |mat| mat.matches.len() > 0 }) + .filter(|mat| !mat.matches.is_empty()) .count() > 0; @@ -83,9 +82,9 @@ fn traverse_dir( } } else { if config.use_gitignore { - let should_ignore = gitignore.iter().find(|&line| path.contains(&line.clone())); + let should_ignore: Option<&String> = gitignore.iter().find(|&line| path.contains(&line.clone())); - if should_ignore.unwrap_or(&String::from("")).len() > 0 + if !should_ignore.unwrap_or(&String::from("")).is_empty() || entry.path().to_str().unwrap().contains("/.git") { continue; @@ -93,7 +92,7 @@ fn traverse_dir( } let result = operation(&config, &entry.path()); match result { - Result::Ok(result) if result.matches.len() > 0 => matches.push(result), + Result::Ok(result) if !result.matches.is_empty() => matches.push(result), _ => (), } } @@ -136,11 +135,11 @@ fn check_file(config: &Config, path: &Path) -> io::Result { Ok(FileMatch { file_name: path.to_str().unwrap().trim_start_matches("./").to_string(), - matches: matches, + matches, }) } -fn print_report(config: &Config, matches: &Vec) { +fn print_report(config: &Config, matches: &[FileMatch]) { for file in matches { file.print(config) }