Fix lint issues

This commit is contained in:
Cameron Cordes
2020-05-22 16:17:03 -04:00
parent a403dbda76
commit 276db68727
2 changed files with 15 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ pub struct FileMatch {
impl FileMatch { impl FileMatch {
pub fn print(&self, config: &Config) { pub fn print(&self, config: &Config) {
let cp = ColorPrinter { let cp = ColorPrinter {
config: config, config,
file_match: self, file_match: self,
}; };
cp.print(); cp.print();

View File

@@ -11,19 +11,18 @@ fn main() {
let config = Config::from_args(); let config = Config::from_args();
let search_path = &config.path; let search_path = &config.path;
let path = match search_path.starts_with('/') { let path = if search_path.starts_with('/') {
true => Path::new(search_path), Path::new(search_path)
false => { } else {
let p: &'static str = Box::leak(Box::new(String::from("./") + search_path)); let p: &'static str = Box::leak(Box::new(String::from("./") + search_path));
Path::new(p) Path::new(p)
}
}; };
let results = traverse_dir(&config, path, Option::None, |config, path| { let results = traverse_dir(&config, path, Option::None, |config, path| {
check_file(config, path) check_file(config, path)
}); });
match results { 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::Ok(matches) => print_report(&config, &matches),
Result::Err(msg) => println!("Error while parsing: {}", msg), Result::Err(msg) => println!("Error while parsing: {}", msg),
} }
@@ -48,10 +47,10 @@ fn traverse_dir(
let file = io::BufReader::new(File::open(g.path())?); let file = io::BufReader::new(File::open(g.path())?);
file.lines() file.lines()
.map(|line| line.unwrap().trim().to_owned()) .map(|line| line.unwrap().trim().to_owned())
.filter(|line| line.len() > 0 && !line.starts_with('#')) .filter(|line| !line.is_empty() && !line.starts_with('#'))
.collect::<Vec<String>>() .collect::<Vec<String>>()
} }
None => gitignore_entries.unwrap_or(Vec::new()), None => gitignore_entries.unwrap_or_default(),
}; };
for entry in entries { for entry in entries {
@@ -74,7 +73,7 @@ fn traverse_dir(
traverse_dir(&config, &entry.path(), Some(gitignore.clone()), operation)?; traverse_dir(&config, &entry.path(), Some(gitignore.clone()), operation)?;
let has_results = results let has_results = results
.iter() .iter()
.filter({ |mat| mat.matches.len() > 0 }) .filter(|mat| !mat.matches.is_empty())
.count() .count()
> 0; > 0;
@@ -83,9 +82,9 @@ fn traverse_dir(
} }
} else { } else {
if config.use_gitignore { 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") || entry.path().to_str().unwrap().contains("/.git")
{ {
continue; continue;
@@ -93,7 +92,7 @@ fn traverse_dir(
} }
let result = operation(&config, &entry.path()); let result = operation(&config, &entry.path());
match result { 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<FileMatch> {
Ok(FileMatch { Ok(FileMatch {
file_name: path.to_str().unwrap().trim_start_matches("./").to_string(), file_name: path.to_str().unwrap().trim_start_matches("./").to_string(),
matches: matches, matches,
}) })
} }
fn print_report(config: &Config, matches: &Vec<FileMatch>) { fn print_report(config: &Config, matches: &[FileMatch]) {
for file in matches { for file in matches {
file.print(config) file.print(config)
} }