Fix lint issues
This commit is contained in:
@@ -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();
|
||||
|
||||
25
src/main.rs
25
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 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::<Vec<String>>()
|
||||
}
|
||||
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<FileMatch> {
|
||||
|
||||
Ok(FileMatch {
|
||||
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 {
|
||||
file.print(config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user