ferrous_forge/commands/
validate.rs1use crate::{doc_coverage, formatting, security, validation::RustValidator, Result};
4use console::style;
5use std::path::PathBuf;
6
7pub async fn execute(path: Option<PathBuf>) -> Result<()> {
9 let project_path = path.unwrap_or_else(|| std::env::current_dir().unwrap_or_default());
10
11 println!(
12 "{}",
13 style("🦀 Running Ferrous Forge validation...")
14 .bold()
15 .cyan()
16 );
17 println!("📁 Project: {}", project_path.display());
18 println!();
19
20 let validator = RustValidator::new(project_path.clone())?;
22
23 let violations = validator.validate_project().await?;
25
26 let report = validator.generate_report(&violations);
28 println!("{}", report);
29
30 println!(
32 "{}",
33 style("🔧 Running Clippy with strict configuration...")
34 .bold()
35 .yellow()
36 );
37 let clippy_result = validator.run_clippy().await?;
38
39 if !clippy_result.success {
40 println!("{}", style("❌ Clippy found issues:").red());
41 println!("{}", clippy_result.output);
42 } else {
43 println!("{}", style("✅ Clippy validation passed!").green());
44 }
45
46 println!();
48 println!(
49 "{}",
50 style("📚 Checking documentation coverage...")
51 .bold()
52 .yellow()
53 );
54 match doc_coverage::check_documentation_coverage(&project_path).await {
55 Ok(coverage) => {
56 println!("{}", coverage.report());
57 if coverage.coverage_percent < 80.0 {
58 println!("{}", style("⚠️ Documentation coverage below 80%").yellow());
59 }
60 }
61 Err(e) => {
62 println!(
63 "{}",
64 style(format!("⚠️ Could not check documentation: {}", e)).yellow()
65 );
66 }
67 }
68
69 println!();
71 println!(
72 "{}",
73 style("📝 Checking code formatting...").bold().yellow()
74 );
75 match formatting::check_formatting(&project_path).await {
76 Ok(format_result) => {
77 println!("{}", format_result.report());
78 }
79 Err(e) => {
80 println!(
81 "{}",
82 style(format!("⚠️ Could not check formatting: {}", e)).yellow()
83 );
84 }
85 }
86
87 println!();
89 println!("{}", style("🔒 Running security audit...").bold().yellow());
90 match security::run_security_audit(&project_path).await {
91 Ok(audit_report) => {
92 println!("{}", audit_report.report());
93 }
94 Err(e) => {
95 println!(
96 "{}",
97 style(format!("⚠️ Could not run security audit: {}", e)).yellow()
98 );
99 }
100 }
101
102 if !violations.is_empty() || !clippy_result.success {
104 std::process::exit(1);
105 } else {
106 println!();
107 println!(
108 "{}",
109 style("🎉 All validations passed! Code meets Ferrous Forge standards.")
110 .bold()
111 .green()
112 );
113 }
114
115 Ok(())
116}