Implemented README section detection#17
Conversation
📝 WalkthroughWalkthroughAdds a new ChangesREADME Section Detection
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Main
participant Detector as readme::detector
participant FS as File System
Main->>Detector: detect()
Detector->>FS: read README.md
FS-->>Detector: file contents or error
Detector->>Detector: extract headings into HashSet
Detector->>Detector: check required sections
Detector-->>Main: print detected sections and validation report
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with 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.
Inline comments:
In `@src/readme/detector.rs`:
- Around line 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.
- Around line 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.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fcef3862-7e35-47ec-bc93-d071f9958c7b
📒 Files selected for processing (3)
src/main.rssrc/readme/detector.rssrc/readme/mod.rs
| if trimmed.starts_with('#') { | ||
| let heading = trimmed.trim_start_matches('#').trim().to_lowercase(); | ||
| sections.insert(heading); | ||
| } |
There was a problem hiding this comment.
🎯 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.
| 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.
| let required_sections = vec![ | ||
| "installation", | ||
| "usage", | ||
| "license", | ||
| "contributing", | ||
| "features", | ||
| "api", | ||
| "examples", | ||
| ]; |
There was a problem hiding this comment.
🎯 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.
| 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.
Summary
Implemented README section detection.
Changes
Closes #7
Summary by CodeRabbit