From 1f20152f006274692b27acd861b0cd7aa7c63060 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Tue, 28 Jan 2020 19:35:44 +0100 Subject: [PATCH] Make parsing Maven projects recursive, and check if the same dir contains multipe projects, for example Maven and Node --- kondo-lib/src/lib.rs | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/kondo-lib/src/lib.rs b/kondo-lib/src/lib.rs index 81b30a8..a0676ba 100644 --- a/kondo-lib/src/lib.rs +++ b/kondo-lib/src/lib.rs @@ -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() @@ -193,15 +199,14 @@ fn is_hidden(entry: &walkdir::DirEntry) -> bool { struct ProjectIter { it: walkdir::IntoIter, + found_projects: Vec, } -impl Iterator for ProjectIter { - type Item = Project; - - fn next(&mut self) -> Option { +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, }; @@ -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, @@ -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 { + if self.found_projects.is_empty() { + self.walk(); + if self.found_projects.is_empty() { + return None; + } } + self.found_projects.pop() } } @@ -256,6 +281,7 @@ pub fn scan>(p: &P) -> impl Iterator { it: walkdir::WalkDir::new(p) .follow_links(SYMLINK_FOLLOW) .into_iter(), + found_projects: Vec::new(), } }