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);
}
Comment on lines +21 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Lines starting with # inside fenced code blocks are falsely detected as headings.

A # comment inside a ``` block (e.g., # Install dependencies in a bash snippet) would be extracted as a heading. If such a comment matches a required section name (e.g., # installation), the validator would report it as "Found" even though no real section exists, masking a genuinely missing section.

Track fenced code block state to skip lines inside ``` blocks:

🛡️ Proposed fix: skip headings inside code fences
     let mut sections: HashSet<String> = HashSet::new();
+    let mut in_code_block = false;

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

+        if trimmed.starts_with("```") {
+            in_code_block = !in_code_block;
+            continue;
+        }
+
+        if in_code_block {
+            continue;
+        }
+
         if trimmed.starts_with('#') {
             let heading = trimmed.trim_start_matches('#').trim().to_lowercase();
             sections.insert(heading);
         }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if trimmed.starts_with('#') {
let heading = trimmed.trim_start_matches('#').trim().to_lowercase();
sections.insert(heading);
}
let mut sections: HashSet<String> = HashSet::new();
let mut in_code_block = false;
for line in content.lines() {
let trimmed = line.trim();
if trimmed.starts_with("
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/readme/detector.rs` around lines 21 - 24, The heading extraction in the
readme detector is treating lines inside fenced code blocks as real headings.
Update the logic in the detector function that scans trimmed lines to track
fenced block state (for example, a boolean toggled when encountering a ```
fence) and skip any `trimmed.starts_with('#')` checks while inside a code fence.
Keep the heading normalization/insert logic the same, but ensure it only runs
for actual markdown content outside code blocks.

}

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",
];
Comment on lines +41 to +49

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Required sections list doesn't match the PR acceptance criteria.

The PR objectives specify four required sections: Installation, Usage, Contributing, License. The code checks seven, adding features, api, and examples. These extra sections will report false "Missing" status for READMEs that legitimately omit them, creating confusion since the issue only requires four.

🔧 Proposed fix: align required sections with PR objectives
     let required_sections = vec![
         "installation",
         "usage",
-        "license",
-        "contributing",
-        "features",
-        "api",
-        "examples",
+        "contributing",
+        "license",
     ];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let required_sections = vec![
"installation",
"usage",
"license",
"contributing",
"features",
"api",
"examples",
];
let required_sections = vec![
"installation",
"usage",
"contributing",
"license",
];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/readme/detector.rs` around lines 41 - 49, The required sections list in
the README detector is too broad and does not match the PR acceptance criteria.
Update the required_sections vector in the detector logic to check only the four
intended sections: Installation, Usage, Contributing, and License, and remove
the extra feature/api/examples entries so the missing-section report aligns with
the spec.


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;