Skip to content

fix: register syntax option implicit locals as lowercase#166

Merged
jbearak merged 3 commits into
mainfrom
fix/syntax-false-positives
May 5, 2026
Merged

fix: register syntax option implicit locals as lowercase#166
jbearak merged 3 commits into
mainfrom
fix/syntax-false-positives

Conversation

@jbearak
Copy link
Copy Markdown
Owner

@jbearak jbearak commented May 4, 2026

Summary

  • Stata's syntax command uses uppercase letters in option names to declare a minimum abbreviation (Cache(string) accepts cache(...), Cac(...), ..., C(...)), but the implicit local Stata creates at runtime is always lowercased. The analyzer was registering the local under the original casing, so references like `cache' inside the program body were flagged as undefined.
  • Fix is local to register_implicit_locals: lowercase opt.name when registering and looking up the implicit-local symbol. OptionSpec.name itself is left intact so hover and signature display continue to show the user's original casing (which conveys the abbreviation hint).
  • Reported against format_birth_data.do, which declares syntax, Cache(string) Prefix(string) Outpath(string) [Suffix(string)] and then references `cache', `prefix', `outpath', `suffix' in the program body.

Test plan

  • Added tests/unit/analyzer/syntax-option-capitalization.test.ts covering mixed-case (Cache), already-lowercase, and fully-uppercase (OUT) options.
  • Updated tests/property/syntax-command-analyzer.prop.test.ts — the existing property assertion encoded the old buggy round-trip; it now asserts the correct Stata semantics (lowercase runtime name).
  • bun run test — 5530 pass / 0 fail.
  • bun run typecheck — clean.

Summary by CodeRabbit

  • Bug Fixes
    • Syntax command options now generate implicit local macros with lowercase names, ensuring consistent behavior regardless of how the option name is capitalized in the command definition.

Stata's `syntax` command uses uppercase letters in option names to
declare a minimum abbreviation (e.g. `Cache(string)` accepts `cache(...)`,
`Cac(...)`, ..., `C(...)`), but the implicit local it creates at runtime
is always the lowercase form. The analyzer was registering the local
under the original casing, so references like `` `cache' `` inside the
program body were flagged as undefined for any program declaring
`Cache(...)` in its syntax line.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@jbearak has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 37 minutes and 31 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 55dfb0a9-de1f-4c8a-8058-3de1b5a8c139

📥 Commits

Reviewing files that changed from the base of the PR and between 2eb3328 and 72eb4c1.

📒 Files selected for processing (1)
  • tests/unit/analyzer/syntax-option-capitalization.test.ts
📝 Walkthrough

Walkthrough

Syntax option names registered as implicit local macros are now lowercased during registration. Documentation is updated to clarify case-sensitive matching elsewhere. Tests validate that mixed-case and uppercase syntax options create lowercase implicit locals and preserve case-sensitivity in macro references.

Changes

Syntax Option Implicit Local Registration

Layer / File(s) Summary
Documentation
src/analyzer/index.ts (lines 739–744)
Comments for extract_syntax_option_names clarify that option names preserve literal casing and downstream case-sensitive matching is handled separately.
Core Implementation
src/analyzer/index.ts (lines 977–1007)
register_implicit_locals lowercases option names via opt.name.toLowerCase() when creating and storing implicit local macro symbols, replacing prior verbatim name registration.
Existing Test Updates
tests/property/syntax-command-analyzer.prop.test.ts (lines 95–117)
Property test now deduplicates option names by lowercase form and asserts localMacros entries exist with scope === 'local'; verifies count matches the deduplicated set to prevent silent collisions.
New Test Suite
tests/unit/analyzer/syntax-option-capitalization.test.ts (lines 1–85)
Comprehensive unit tests validate that uppercase (e.g., Cache, OUT) and mixed-case syntax option names define lowercase implicit locals (e.g., `cache', `out'), and that case-mismatched references (e.g., `Cache' when only `cache' exists) produce undefined-macro diagnostics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Options dance in lowercase grace,
No matter what their birth-case place—
Cache becomes cache, bold and bright,
Tests ensure the casing's right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: registering syntax option implicit locals as lowercase to match Stata runtime behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/syntax-false-positives

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- syntax-option-capitalization.test.ts: assert that a wrong-case
  reference (`Cache') still produces an undefined-macro diagnostic.
  Locks in the semantics in both directions and prevents accidentally
  registering both casings.
- syntax-command-analyzer.prop.test.ts: deduplicate generated option
  names by their lowercase form before asserting, and confirm every
  distinct lowercase name maps to exactly one entry. Previously the
  generator could produce inputs that collapse to one runtime local
  (e.g. `Foo`, `foo`), and the assertion looked stronger than it was.
- analyzer/index.ts: document why extract_syntax_option_names preserves
  original casing — full case-insensitive matching of macro-creating
  options also requires lowercasing call-site option matching, which
  is broader than the implicit-local fix.
@jbearak
Copy link
Copy Markdown
Owner Author

jbearak commented May 5, 2026

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jbearak
Copy link
Copy Markdown
Owner Author

jbearak commented May 5, 2026

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/unit/analyzer/syntax-option-capitalization.test.ts (1)

16-43: ⚡ Quick win

Align scoped variable names with the repo’s my_ naming convention.

Please rename scoped variables like analyzer, lexer, and parser to the project’s prefixed form for consistency in this new test file.

As per coding guidelines, "**/*.ts: ... Use my_ prefix for loop iterators and scoped variables (except single letters i, j, k)."

🤖 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 `@tests/unit/analyzer/syntax-option-capitalization.test.ts` around lines 16 -
43, Scoped variables in this test file (analyzer, lexer, parser) don't follow
the repo naming convention—rename analyzer to my_analyzer, lexer to my_lexer,
and parser to my_parser and update every reference (the beforeEach initializer
and usages inside analyze_document and undefined_macro_messages) so the test
uses my_analyzer, my_lexer, my_parser consistently; ensure function
analyze_document uses my_lex_result.tokenize(my_source) and parser.parse calls
are updated to use my_parser and pass my_lex_result.tokens, and that
analyzer.analyze is replaced with my_analyzer.analyze in the return path.
🤖 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.

Nitpick comments:
In `@tests/unit/analyzer/syntax-option-capitalization.test.ts`:
- Around line 16-43: Scoped variables in this test file (analyzer, lexer,
parser) don't follow the repo naming convention—rename analyzer to my_analyzer,
lexer to my_lexer, and parser to my_parser and update every reference (the
beforeEach initializer and usages inside analyze_document and
undefined_macro_messages) so the test uses my_analyzer, my_lexer, my_parser
consistently; ensure function analyze_document uses
my_lex_result.tokenize(my_source) and parser.parse calls are updated to use
my_parser and pass my_lex_result.tokens, and that analyzer.analyze is replaced
with my_analyzer.analyze in the return path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8c9eb630-e59d-47a9-89c8-752f6b235bd6

📥 Commits

Reviewing files that changed from the base of the PR and between b770bdc and 2eb3328.

📒 Files selected for processing (3)
  • src/analyzer/index.ts
  • tests/property/syntax-command-analyzer.prop.test.ts
  • tests/unit/analyzer/syntax-option-capitalization.test.ts

@jbearak
Copy link
Copy Markdown
Owner Author

jbearak commented May 5, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@jbearak jbearak merged commit fcd115b into main May 5, 2026
12 checks passed
@jbearak jbearak deleted the fix/syntax-false-positives branch May 5, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant