Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make parsing Maven projects recursive, and check if the same dir cont… #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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