Skip to content

Commit

Permalink
Make parsing Maven projects recursive, and check if the same dir cont…
Browse files Browse the repository at this point in the history
…ains multipe projects, for example Maven and Node
  • Loading branch information
gzsombor committed Feb 19, 2021
1 parent e6c658c commit 1f20152
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions kondo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ impl Project {
}
}

impl ProjectType {
fn is_recursive(&self) -> bool {
matches!(self, ProjectType::Maven)
}
}

fn is_hidden(entry: &walkdir::DirEntry) -> bool {
entry
.file_name()
Expand All @@ -193,15 +199,14 @@ fn is_hidden(entry: &walkdir::DirEntry) -> bool {

struct ProjectIter {
it: walkdir::IntoIter,
found_projects: Vec<Project>,
}

impl Iterator for ProjectIter {
type Item = Project;

fn next(&mut self) -> Option<Self::Item> {
impl ProjectIter {
fn walk(&mut self) {
loop {
let entry: walkdir::DirEntry = match self.it.next() {
None => return None,
None => return,
Some(Err(_)) => continue,
Some(Ok(entry)) => entry,
};
Expand All @@ -216,6 +221,7 @@ impl Iterator for ProjectIter {
Err(_) => continue,
Ok(rd) => rd,
};
let mut skip_dir = false;
for dir_entry in rd.filter_map(|rd| rd.ok()) {
let file_name = match dir_entry.file_name().into_string() {
Err(_) => continue,
Expand All @@ -240,14 +246,33 @@ impl Iterator for ProjectIter {
_ => None,
};
if let Some(project_type) = p_type {
self.it.skip_current_dir();
return Some(Project {
if !project_type.is_recursive() {
skip_dir = true;
}
self.found_projects.push(Project {
project_type,
path: entry.path().to_path_buf(),
});
}
}
if skip_dir {
self.it.skip_current_dir()
}
}
}
}

impl Iterator for ProjectIter {
type Item = Project;

fn next(&mut self) -> Option<Self::Item> {
if self.found_projects.is_empty() {
self.walk();
if self.found_projects.is_empty() {
return None;
}
}
self.found_projects.pop()
}
}

Expand All @@ -256,6 +281,7 @@ pub fn scan<P: AsRef<path::Path>>(p: &P) -> impl Iterator<Item = Project> {
it: walkdir::WalkDir::new(p)
.follow_links(SYMLINK_FOLLOW)
.into_iter(),
found_projects: Vec::new(),
}
}

Expand Down

0 comments on commit 1f20152

Please sign in to comment.