Repository navigation
fix: suppress false positive diagnostics for stored result references - #3
Conversation
Add detection logic to recognize Stata stored result references (r(), e(), c(), s()) within local macro reference tokens and suppress the invalid character diagnostic for these valid constructs. Changes: - Add is_stored_result_reference() helper method to Analyzer - Modify check_token_macro_references() to skip stored result patterns - Add property tests for stored result detection Stored result references like `r(values)' are valid Stata syntax for accessing return values, estimation results, system constants, and string scalars. The fix also handles nested macros and matrix subscripts. Closes: stored-result-reference-false-positive spec
📝 WalkthroughWalkthroughThis pull request introduces a fix for false positives where Stata stored result references (r(), e(), c(), s()) wrapped in backtick-apostrophe syntax are incorrectly flagged as invalid macro names. A new private helper method detects stored result patterns, and diagnostic logic is updated to skip invalid character checks for these valid references while preserving detection for actual invalid characters. Changes
Poem
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
🧰 Additional context used📓 Path-based instructions (5)src/{lexer,parser,analyzer}/**/*.ts📄 CodeRabbit inference engine (GEMINI.md)
Files:
src/**/*.ts📄 CodeRabbit inference engine (GEMINI.md)
Files:
src/analyzer/**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
tests/property/**/*.test.ts📄 CodeRabbit inference engine (GEMINI.md)
Files:
tests/property/**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (6)📚 Learning: 2026-01-02T19:17:42.555ZApplied to files:
📚 Learning: 2026-01-02T19:17:15.152ZApplied to files:
📚 Learning: 2026-01-02T19:17:42.555ZApplied to files:
📚 Learning: 2026-01-02T19:17:42.555ZApplied to files:
📚 Learning: 2026-01-02T19:17:15.152ZApplied to files:
📚 Learning: 2026-01-02T19:17:42.555ZApplied to files:
🧬 Code graph analysis (1)tests/property/stored-result-reference-detection.prop.test.ts (2)
🪛 LanguageTool.kiro/specs/stored-result-reference-false-positive/design.md[grammar] ~5-~5: Use a hyphen to join words. (QB_NEW_EN_HYPHEN) [style] ~134-~134: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym. (ENGLISH_WORD_REPEAT_BEGINNING_RULE) [style] ~136-~136: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym. (ENGLISH_WORD_REPEAT_BEGINNING_RULE) 🪛 markdownlint-cli2 (0.18.1).kiro/specs/stored-result-reference-false-positive/design.md11-11: Fenced code blocks should have a language specified (MD040, fenced-code-language) 96-96: Emphasis used instead of a heading (MD036, no-emphasis-as-heading) 102-102: Emphasis used instead of a heading (MD036, no-emphasis-as-heading) 108-108: Emphasis used instead of a heading (MD036, no-emphasis-as-heading) 114-114: Emphasis used instead of a heading (MD036, no-emphasis-as-heading) 🔇 Additional comments (7)
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.
Summary
This PR successfully implements a fix for false positive diagnostics when using Stata stored result references. The implementation correctly identifies stored result patterns (r(), e(), c(), s()) and suppresses invalid character diagnostics for these valid Stata constructs.
Key Changes
- ✅ Added
is_stored_result_reference()method to detect stored result patterns - ✅ Modified
check_token_macro_references()to skip stored result references - ✅ Comprehensive property-based tests covering all requirements
- ✅ Proper handling of nested macros and matrix subscripts
Issues Found
- 🔧 Minor Logic Issue: The regex pattern uses
.*which could match empty parentheses or malformed patterns. Should use.+to ensure non-empty content.
The fix is well-designed and thoroughly tested. The only concern is a minor regex pattern issue that should be addressed to prevent edge cases with malformed stored result references.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| private is_stored_result_reference(content: string): boolean { | ||
| return /^[recs]\(.*\)(\[.*\])?$/.test(content); |
There was a problem hiding this comment.
🛑 Logic Error: The regex pattern has a potential issue with empty parentheses handling. The current pattern /^[recs]\(.*\)(\[.*\])?$/ uses .* which matches zero or more characters, but this could incorrectly match malformed patterns like r() with empty parentheses or r( with missing closing parenthesis.
Consider making the pattern more restrictive to ensure there's actual content within the parentheses and proper balancing:
| private is_stored_result_reference(content: string): boolean { | |
| return /^[recs]\(.*\)(\[.*\])?$/.test(content); | |
| private is_stored_result_reference(content: string): boolean { | |
| return /^[recs]\(.+\)(\[.*\])?$/.test(content); | |
| } |
| .filter((my_name) => { | ||
| return !/^[recs]\(.*\)(\[.*\])?$/.test(my_name); | ||
| }); |
There was a problem hiding this comment.
The regex pattern in the test duplicates the same potential issue found in the main implementation. The pattern should use .+ instead of .* to ensure non-empty content within parentheses, maintaining consistency with the fix suggested for the main implementation.
| .filter((my_name) => { | |
| return !/^[recs]\(.*\)(\[.*\])?$/.test(my_name); | |
| }); | |
| .filter((my_name) => { | |
| return !/^[recs]\(.+\)(\[.*\])?$/.test(my_name); | |
| }); |
|
Thanks for the review! Regarding the regex pattern suggestion: The use of
Stata allows |
Address all review comments from CodeRabbit, Amazon Q Developer, and Claude: 1. Amazon Q Developer (lines 462-465): Fixed logic error in command node if qualifier context detection - Added range check to verify operator is actually within the if qualifier range - Previously returned 'qualifier' for ANY operator in a command with ifExpression 2. Claude issue #2: Added missing while condition check - Added condition check for while nodes to properly classify C-style operators in while conditions - Now returns 'control_flow' context when operator is in while condition 3. Claude issue #3: Fixed incorrect classification of operators in body commands - Added body range check before falling through to condition check - Prevents operators in plain body commands from being incorrectly classified as 'control_flow' - Applied fix to both if/else nodes and foreach/forvalues/while/frame nodes 4. Claude issue #1: Removed unnecessary 'as' type casts - Removed 'as' casts from command and program nodes - TypeScript automatically narrows types after type checks 5. CodeRabbit issues: Fixed markdown formatting - Added language specifiers to fenced code blocks in design.md (typescript, markdown, text) - Verified pipe characters already escaped in README.md - Verified test config already has cStyleLogicalInControlFlow setting All 85 operator sequence tests pass.
Add detection logic to recognize Stata stored result references (r(), e(), c(), s()) within local macro reference tokens and suppress the invalid character diagnostic for these valid constructs.
Changes:
Stored result references like `r(values)' are valid Stata syntax for accessing return values, estimation results, system constants, and string scalars. The fix also handles nested macros and matrix subscripts.
Closes: stored-result-reference-false-positive spec
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.