diff --git a/src/engine/mod.rs b/src/engine/mod.rs index e0df9bc..c15ce36 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -100,12 +100,38 @@ impl AnalyzeDependenciesOutcome { self.crates.iter().any(|&(_, ref deps)| deps.any_outdated()) } + // TODO(feliix42): Why is this different from the any_outdated() function above? + /// Checks if any insecure main or build dependencies exist in the scanned crates pub fn any_insecure(&self) -> bool { self.crates .iter() .any(|&(_, ref deps)| deps.count_insecure() > 0) } + /// Checks if any dev-dependencies in the scanned crates are either outdated or insecure + pub fn any_dev_issues(&self) -> bool { + self.crates + .iter() + .any(|&(_, ref deps)| deps.any_dev_issues()) + } + + /// Returns the number of outdated dev-dependencies + pub fn count_dev_outdated(&self) -> usize { + self.crates + .iter() + .map(|&(_, ref deps)| deps.count_dev_outdated()) + .sum() + } + + /// Returns the number of insecure dev-dependencies + pub fn count_dev_insecure(&self) -> usize { + self.crates + .iter() + .map(|&(_, ref deps)| deps.count_dev_insecure()) + .sum() + } + + /// Returns the number of outdated and the number of total main and build dependencies pub fn outdated_ratio(&self) -> (usize, usize) { self.crates .iter() diff --git a/src/models/crates.rs b/src/models/crates.rs index 09354bf..e0c6901 100644 --- a/src/models/crates.rs +++ b/src/models/crates.rs @@ -152,41 +152,58 @@ impl AnalyzedDependencies { AnalyzedDependencies { main, dev, build } } + /// Counts the total number of main and build dependencies pub fn count_total(&self) -> usize { - self.main.len() + self.dev.len() + self.build.len() + self.main.len() + self.build.len() } + /// Returns the number of outdated main and build dependencies pub fn count_outdated(&self) -> usize { let main_outdated = self .main .iter() .filter(|&(_, dep)| dep.is_outdated()) .count(); - let dev_outdated = self - .dev - .iter() - .filter(|&(_, dep)| dep.is_outdated()) - .count(); let build_outdated = self .build .iter() .filter(|&(_, dep)| dep.is_outdated()) .count(); - main_outdated + dev_outdated + build_outdated + main_outdated + build_outdated } + /// Returns the number of insecure main and build dependencies pub fn count_insecure(&self) -> usize { let main_insecure = self.main.iter().filter(|&(_, dep)| dep.insecure).count(); - let dev_insecure = self.dev.iter().filter(|&(_, dep)| dep.insecure).count(); let build_insecure = self.build.iter().filter(|&(_, dep)| dep.insecure).count(); - main_insecure + dev_insecure + build_insecure + main_insecure + build_insecure } + /// Checks if any outdated main or build dependencies exist pub fn any_outdated(&self) -> bool { let main_any_outdated = self.main.iter().any(|(_, dep)| dep.is_outdated()); - let dev_any_outdated = self.dev.iter().any(|(_, dep)| dep.is_outdated()); let build_any_outdated = self.build.iter().any(|(_, dep)| dep.is_outdated()); - main_any_outdated || dev_any_outdated || build_any_outdated + main_any_outdated || build_any_outdated + } + + /// Counts the number of outdated `dev-dependencies` + pub fn count_dev_outdated(&self) -> usize { + self.dev + .iter() + .filter(|&(_, dep)| dep.is_outdated()) + .count() + } + + /// Counts the number of insecure `dev-dependencies` + pub fn count_dev_insecure(&self) -> usize { + self.dev.iter().filter(|&(_, dep)| dep.insecure).count() + } + + /// Returns `true` if any dev-dependencies are either insecure or outdated. + pub fn any_dev_issues(&self) -> bool { + self.dev + .iter() + .any(|(_, dep)| dep.is_outdated() || dep.insecure) } } diff --git a/src/server/views/html/status.rs b/src/server/views/html/status.rs index 46ab2a1..f3044c1 100644 --- a/src/server/views/html/status.rs +++ b/src/server/views/html/status.rs @@ -119,6 +119,22 @@ fn render_title(subject_path: &SubjectPath) -> Markup { } } +fn render_dev_dependency_box(outcome: &AnalyzeDependenciesOutcome) -> Markup { + let insecure = outcome.count_dev_insecure(); + let outdated = outcome.count_dev_outdated(); + let text = if insecure > 0 { + format!("{} insecure development dependencies", insecure) + } else { + format!("{} outdated development dependencies", outdated) + }; + + html! { + div class="notification is-warning" { + p { "This project contains " b { (text) } "." } + } + } +} + fn render_failure(subject_path: SubjectPath) -> Markup { html! { section class="hero is-light" { @@ -192,6 +208,9 @@ fn render_success( } section class="section" { div class="container" { + @if analysis_outcome.any_dev_issues() { + (render_dev_dependency_box(&analysis_outcome)) + } @for (crate_name, deps) in analysis_outcome.crates { (dependency_tables(crate_name, deps)) }