use crate::{
Result, doc_coverage, formatting, security, test_coverage::CoverageAnalyzer,
validation::RustValidator,
};
use std::path::Path;
pub async fn run_additional_checks(project_path: &Path) {
check_documentation_coverage(project_path).await;
check_code_formatting(project_path).await;
run_security_audit_check(project_path).await;
check_test_coverage(project_path).await;
}
async fn check_documentation_coverage(project_path: &Path) {
println!("๐ Checking documentation coverage...");
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
match doc_coverage::check_documentation_coverage(project_path).await {
Ok(coverage) => {
println!("{}", coverage.report());
if coverage.coverage_percent < 80.0 {
println!("โ ๏ธ Documentation coverage below 80%");
}
}
Err(e) => {
println!("โ Documentation coverage check failed: {}", e);
}
}
println!();
}
async fn check_code_formatting(project_path: &Path) {
println!("๐ Checking code formatting...");
match formatting::check_formatting(project_path).await {
Ok(format_result) => {
println!("{}", format_result.report());
if !format_result.unformatted_files.is_empty() {
println!("Files needing formatting:");
for file in &format_result.unformatted_files {
println!(" {}", file);
}
}
}
Err(e) => {
println!("โ Code formatting check failed: {}", e);
}
}
println!();
}
async fn run_security_audit_check(project_path: &Path) {
println!("๐ Running security audit...");
match security::run_security_audit(project_path).await {
Ok(audit_report) => {
println!("{}", audit_report.report());
}
Err(e) => {
println!("โ Security audit failed: {}", e);
}
}
}
async fn check_test_coverage(project_path: &Path) {
println!("๐งช Checking test coverage...");
let analyzer = CoverageAnalyzer::new();
match analyzer.check_tarpaulin_installed() {
Ok(true) => {
match analyzer.run_coverage(project_path).await {
Ok(report) => {
println!("โ
Test coverage: {:.1}%", report.line_coverage);
println!(
" Lines tested: {}/{}",
report.lines_tested, report.total_lines
);
println!(
" Functions tested: {}/{}",
report.functions_tested, report.total_functions
);
let threshold = 80.0;
if let Err(e) = analyzer.enforce_minimum_coverage(&report, threshold) {
println!("โ ๏ธ {}", e);
}
}
Err(e) => {
println!("โ ๏ธ Test coverage check failed: {}", e);
println!(" This may be due to test failures or configuration issues");
}
}
}
Ok(false) => {
println!("โ ๏ธ cargo-tarpaulin not installed");
println!(" Install with: cargo install cargo-tarpaulin");
println!(" Skipping test coverage check");
}
Err(e) => {
println!("โ ๏ธ Failed to check for cargo-tarpaulin: {}", e);
}
}
println!();
}
pub async fn run_clippy_validation(
validator: &RustValidator,
) -> Result<crate::validation::ClippyResult> {
println!("๐ง Running Clippy with strict configuration...");
let clippy_result = validator.run_clippy().await?;
if !clippy_result.success {
println!("โ Clippy found issues:");
println!("{}", clippy_result.output);
} else {
println!("โ
Clippy validation passed!");
}
Ok(clippy_result)
}