Skip to content

Fix macro-creating option case matching#168

Merged
jbearak merged 2 commits into
mainfrom
issue167
May 5, 2026
Merged

Fix macro-creating option case matching#168
jbearak merged 2 commits into
mainfrom
issue167

Conversation

@jbearak
Copy link
Copy Markdown
Owner

@jbearak jbearak commented May 5, 2026

Summary

  • Normalize syntax option names and macro-creating option pattern matches to lowercase.
  • Match call-site user-program macro-creating options using lowercased option names.
  • Update unit/property tests for Stata's lowercased runtime option locals.

Validation

  • bun test tests/unit/analyzer.test.ts
  • bun test tests/property/program-pattern-detection-macro-creation.prop.test.ts tests/property/program-macro-creation-correctness.prop.test.ts
  • bun run test

Fixes #167

Conversation: https://app.warp.dev/conversation/0d604b25-de4f-4001-b616-d8cfa0adb550

Summary by CodeRabbit

  • Bug Fixes

    • Macro-creating option names declared via syntax are now treated case-insensitively and normalized to lowercase across local and global detection.
  • Tests

    • Updated property tests to expect lowercase option-name handling and deduplication.
    • Added a unit test confirming syntax-declared option names are normalized to lowercase.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d9c9583d-f770-47fe-81cf-0af811dfbfd4

📥 Commits

Reviewing files that changed from the base of the PR and between fd249b1 and ef5e49c.

📒 Files selected for processing (2)
  • src/analyzer/index.ts
  • tests/property/program-macro-creation-correctness.prop.test.ts

📝 Walkthrough

Walkthrough

Option-name handling for syntax-declared locals is made case-insensitive: option names are lowercased during extraction, pattern matching, and call-site validation in the analyzer; tests were updated to expect deduplicated lowercase runtime option names.

Changes

Option Name Normalization to Lowercase

Layer / File(s) Summary
Data Shape / Extraction
src/analyzer/index.ts (extract_syntax_option_names, lines ~736–748)
extract_syntax_option_names now returns syntax option names lowercased (uses opt.name.toLowerCase()).
Pattern Matching
src/analyzer/index.ts (extract_macro_creating_option_patterns, lines ~741–793)
Backticked identifiers extracted from c_local \...''andglobal `...''are lowercased before membership checks/recording againstsyntax_option_names`.
Call-site Validation / Allowlist
src/analyzer/index.ts (extract_macro_creating_options, lines ~2093–2129)
Allowlisted local/global option-name sets (built-ins and program options) are lowercased and option.name.toLowerCase() is used for membership checks.
Unit Test
tests/unit/analyzer.test.ts (lines ~142–161)
Adds a test asserting syntax, Cache(string) + c_local \cache'registers['cache']inmacro_creating_local_options, registers a local macro, and produces no UNDEFINED_MACRO` diagnostic.
Property Tests
tests/property/program-macro-creation-correctness.prop.test.ts, tests/property/program-pattern-detection-macro-creation.prop.test.ts
All assertions updated to normalize/dedupe expected option names to lowercase and adjust case-sensitivity/uniqueness properties accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • jbearak/sight#166: Lowercases syntax option implicit locals at registration; this PR completes lowercase normalization for pattern matching and call-site checks.

Poem

🐰
I nibble at capitals, one by one,
Cache becomes cache — the lowering's done,
Patterns match kindly, no more mismatch cheer,
Locals appear, defined and clear,
A tidy hop—code springs in ear.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 describes the main change: fixing case-insensitive matching for macro-creating options.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #167: lowercasing syntax option names, lowercasing inner names in pattern matching, lowercasing option names in call-site checks, and updating tests.
Out of Scope Changes check ✅ Passed All changes are scoped to the macro-creating option case-matching fix across analyzer implementation and related unit/property tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue167

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.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/analyzer/index.ts (1)

2089-2099: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Normalize builtin matched option names before set membership checks.

option_name is lowercased at lookup, but builtin-matched names are inserted into local_option_names / global_option_names using raw casing. This can skip macro creation when option casing differs.

💡 Suggested fix
         if (builtin_cmd) {
             for (const option of node.options) {
                 for (const opt of builtin_cmd.local_options) {
                     if (matches_option(option.name, opt)) {
-                        local_option_names.add(option.name);
+                        local_option_names.add(option.name.toLowerCase());
                     }
                 }
                 for (const opt of builtin_cmd.global_options) {
                     if (matches_option(option.name, opt)) {
-                        global_option_names.add(option.name);
+                        global_option_names.add(option.name.toLowerCase());
                     }
                 }
             }
         } else if (program_options) {
             for (const option_name of program_options.local_options) {
-                local_option_names.add(option_name);
+                local_option_names.add(option_name.toLowerCase());
             }
             for (const option_name of program_options.global_options) {
-                global_option_names.add(option_name);
+                global_option_names.add(option_name.toLowerCase());
             }
         }

Also applies to: 2119-2125

🤖 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/analyzer/index.ts` around lines 2089 - 2099, The code adds
builtin-matched option names into local_option_names/global_option_names using
raw casing which mismatches the lowercased lookup; update the insertion to
normalize the name the same way as lookup (e.g., use option.name.toLowerCase()
or the same normalization function used by matches_option) before calling
local_option_names.add(...) and global_option_names.add(...), and apply the same
change in the other occurrence around the 2119–2125 block so set membership and
macro creation use consistent casing.
tests/property/program-macro-creation-correctness.prop.test.ts (1)

79-95: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Lowercase the negative membership assertions to avoid vacuous passes.

Detected options are now normalized to lowercase, but several negative checks still use .includes(option_name). With mixed-case generators, regressions can slip through unnoticed.

💡 Suggested fix pattern
- expect(invalid_program!.macro_creating_local_options?.includes(option_name) || false).toBe(false);
+ expect(
+     invalid_program!.macro_creating_local_options?.includes(option_name.toLowerCase()) || false
+ ).toBe(false);

- expect(program!.macro_creating_local_options?.includes(option_name) || false).toBe(false);
+ expect(program!.macro_creating_local_options?.includes(option_name.toLowerCase()) || false).toBe(false);

- expect(program!.macro_creating_global_options?.includes(option_name) || false).toBe(false);
+ expect(program!.macro_creating_global_options?.includes(option_name.toLowerCase()) || false).toBe(false);

Also applies to: 146-150, 359-366, 431-433

🤖 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/property/program-macro-creation-correctness.prop.test.ts` around lines
79 - 95, The negative membership assertions use .includes(option_name) but
macro_creating_local_options are normalized to lowercase, causing vacuous passes
for mixed-case names; update all negative checks (e.g., in this test block and
other occurrences at the noted ranges) to compare using the lowercase form
(e.g., .includes(option_name.toLowerCase()) or normalize the RHS via .map/.some)
when checking macro_creating_local_options, so replace .includes(option_name)
with .includes(option_name.toLowerCase()) (reference symbols:
macro_creating_local_options, option_name, parse_and_analyze).
🤖 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.

Outside diff comments:
In `@src/analyzer/index.ts`:
- Around line 2089-2099: The code adds builtin-matched option names into
local_option_names/global_option_names using raw casing which mismatches the
lowercased lookup; update the insertion to normalize the name the same way as
lookup (e.g., use option.name.toLowerCase() or the same normalization function
used by matches_option) before calling local_option_names.add(...) and
global_option_names.add(...), and apply the same change in the other occurrence
around the 2119–2125 block so set membership and macro creation use consistent
casing.

In `@tests/property/program-macro-creation-correctness.prop.test.ts`:
- Around line 79-95: The negative membership assertions use
.includes(option_name) but macro_creating_local_options are normalized to
lowercase, causing vacuous passes for mixed-case names; update all negative
checks (e.g., in this test block and other occurrences at the noted ranges) to
compare using the lowercase form (e.g., .includes(option_name.toLowerCase()) or
normalize the RHS via .map/.some) when checking macro_creating_local_options, so
replace .includes(option_name) with .includes(option_name.toLowerCase())
(reference symbols: macro_creating_local_options, option_name,
parse_and_analyze).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5ce2eda-788e-4af6-9a30-b51cab5e88e4

📥 Commits

Reviewing files that changed from the base of the PR and between fcd115b and fd249b1.

📒 Files selected for processing (4)
  • src/analyzer/index.ts
  • tests/property/program-macro-creation-correctness.prop.test.ts
  • tests/property/program-pattern-detection-macro-creation.prop.test.ts
  • tests/unit/analyzer.test.ts

Insert option names into local_option_names/global_option_names using\nlowercase form to match the lowercased lookup, ensuring consistent set\nmembership for both builtin and user-defined program paths.\n\nAlso fix vacuous negative-membership assertions in property tests:\nmacro_creating_local_options/global_options are stored lowercase, so\n.includes(option_name) for mixed-case identifiers always passed\nregardless of correctness. Compare against option_name.toLowerCase().
@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 jbearak merged commit 43962a9 into main May 5, 2026
9 of 10 checks passed
@jbearak jbearak deleted the issue167 branch May 5, 2026 07:20
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.

Lowercase call-site option matching for macro-creating options

1 participant