fix: exclude CODE_REF comments in unclosed code blocks from validation#25
Conversation
Fixed an issue where CODE_REF comments inside unclosed markdown code blocks were not being excluded from validation. The getCodeBlockRanges() function now detects unclosed code blocks (starting ``` without closing ```) and treats them as code blocks from the start position to the end of the file. Changes: - Enhanced getCodeBlockRanges() to detect and handle unclosed code blocks - Added comprehensive test cases for code block exclusion scenarios: - CODE_REF in normal code blocks - CODE_REF in inline code - CODE_REF in unclosed code blocks - Multiple code blocks with mixed CODE_REFs This resolves the issue where documentation examples of CODE_REF syntax within code blocks were incorrectly validated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Code Review for PR #25SummaryThis PR fixes an issue where CODE_REF comments inside unclosed markdown code blocks were being incorrectly validated. The implementation adds logic to detect unclosed code blocks and exclude them from validation. ✅ Positive Aspects
🐛 Critical Bug FoundIssue: The logic in Location: Problem:
Recommended fix: Use an odd/even count approach - if there are an odd number of triple backticks in the content, the last one starts an unclosed block. 📝 Minor Issues
🧪 Testing RecommendationsAdd test cases for:
VerdictNeeds revision - The critical bug in unclosed block detection must be fixed before merging. The current implementation may create false positives by treating closing backticks as unclosed block starts. 🤖 Review generated with Claude Code |
Improved the getCodeBlockRanges() function to use a more robust odd/even pairing approach instead of the previous implementation that had potential issues with overlapping ranges. Previous implementation issues: - Closing backticks could be incorrectly treated as unclosed blocks - Range check did not account for the 3-character length of triple backticks - Could create overlapping or duplicate ranges New implementation: - Collects all triple backtick positions in order - Pairs them sequentially: indices 0-1, 2-3, 4-5, etc. - If odd number of backticks exists, the last one starts an unclosed block - Cleaner logic with fewer edge cases All existing tests pass (372 tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Pull Request ReviewSummaryThis PR fixes an important issue where CODE_REF comments inside code blocks (including unclosed ones) were being incorrectly validated. The solution refactors the Code Quality & Best Practices ⭐Strengths:
Suggestions:
Potential Bugs 🐛Medium Priority:
Performance Concerns ✅Good:
No concerns identified. Security Concerns ✅No security issues identified. The changes are purely about parsing logic and don't introduce any new security vectors. Test Coverage ⭐Excellent test coverage with 4 new test cases covering:
Suggestions:
Documentation Updates 📚Required:
Example: /**
* Detect code block and inline code ranges in markdown content.
*
* Triple backtick code blocks are paired sequentially: even indices (0, 2, 4...)
* are treated as opening markers, odd indices (1, 3, 5...) as closing markers.
* If there's an odd number of backticks, the final one is treated as an unclosed
* block extending to the end of the file.
*
* @param content - The markdown content to analyze
* @returns Array of ranges indicating code block positions
*/Overall AssessmentRecommendation: Approve with minor suggestions ✅ This is a solid fix that addresses the reported issue effectively. The implementation is clean, well-tested, and follows project conventions. The suggestions above are mostly about handling edge cases and improving documentation rather than critical issues. Strengths:
Minor improvements:
Great work on this fix! The refactored approach is cleaner and more maintainable than the original regex-based solution. |
|
🎉 This PR is included in version 1.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 0.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixed an issue where CODE_REF comments inside unclosed markdown code blocks were not being excluded from validation. The getCodeBlockRanges() function now detects unclosed code blocks (starting
without closing) and treats them as code blocks from the start position to the end of the file.Changes:
This resolves the issue where documentation examples of CODE_REF syntax within code blocks were incorrectly validated.
🤖 Generated with Claude Code