Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod env_validator;

mod readme;
use std::fs;

fn main() {
Expand Down Expand Up @@ -28,4 +28,11 @@ fn main() {

println!();
env_validator::validate_env(&extracted, &env);




readme::detector::detect();
println!();
readme::quality_scoring::score();
}
58 changes: 58 additions & 0 deletions src/readme/detector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;

pub fn detect() {
let file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("README.md");

let content = match fs::read_to_string(&file_path) {
Ok(data) => data,
Err(err) => {
println!("Failed to read README.md at {:?}: {}", file_path, err);
return;
}
};

let mut sections: HashSet<String> = HashSet::new();

for line in content.lines() {
let trimmed = line.trim();

if trimmed.starts_with('#') {
let heading = trimmed.trim_start_matches('#').trim().to_lowercase();
sections.insert(heading);
}
}

println!(
"========== README Section Detection ==========
"
);
println!("Detected Sections:");
for section in &sections {
println!("• {}", section);
}

println!(
"
========== Validation =========="
);

let required_sections = vec![
"installation",
"usage",
"license",
"contributing",
"features",
"api",
"examples",
];

for section in required_sections {
if sections.contains(section) {
println!("✅ {} - Found", section);
} else {
println!("❌ {} - Missing", section);
}
}
}
2 changes: 2 additions & 0 deletions src/readme/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod detector;
pub mod quality_scoring;
87 changes: 87 additions & 0 deletions src/readme/quality_scoring.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;

pub fn score() {
let file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("README.md");

let content = match fs::read_to_string(&file_path) {
Ok(data) => data,
Err(err) => {
println!("Error reading README.md at {:?}: {}", file_path, err);
return;
}
};

let mut sections: HashSet<String> = HashSet::new();

for line in content.lines() {
let trimmed = line.trim();

if trimmed.starts_with('#') {
let heading = trimmed.trim_start_matches('#').trim().to_lowercase();
sections.insert(heading);
}
}

let scoring = vec![
("installation", 20),
("usage", 20),
("features", 15),
("contributing", 15),
("license", 10),
("api", 10),
("examples", 10),
];

let mut score = 0;
let mut missing = Vec::new();

println!(
"
========== README QUALITY REPORT ==========
"
);

for (section, points) in scoring {
if sections.contains(section) {
println!("✅ {:15} +{} points", section, points);
score += points;
} else {
println!("❌ {:15} Missing", section);
missing.push(section);
}
}

println!(
"
=========================================="
);
println!("README Quality Score: {}/100", score);

if missing.is_empty() {
println!("Excellent! README contains all recommended sections.");
} else {
println!(
"
Missing Sections:"
);
for section in missing {
println!(" - {}", section);
}
}

println!();

if score >= 90 {
println!("Grade: A ⭐⭐⭐⭐⭐");
} else if score >= 75 {
println!("Grade: B ⭐⭐⭐⭐");
} else if score >= 60 {
println!("Grade: C ⭐⭐⭐");
} else if score >= 40 {
println!("Grade: D ⭐⭐");
} else {
println!("Grade: F ⭐");
}
}