Skip to content

Keep file names out of variable references, warn on a forvalues range after version N:, and resolve graph working directories and do-file arguments like Stata - #413

Merged
jbearak merged 3 commits into
mainfrom
t3/fix-reference-graph-bugs
Nov 19, 2026

Conversation

@jbearak

@jbearak jbearak commented Nov 19, 2026

Copy link
Copy Markdown
Owner

An audit of v0.15.1..main before the stable release turned up four bugs in recent changes:

  1. Find References counted a file extension as a variable use (regression from Find references to a variable inside factor-variable terms such as i.foo and _b[2.foo] #410). With generate dta = 1 and save old.dta, references to dta included the dta in old.dta. The cause was the operator check, which read old as the operators o, l, d. Now a .name does not count when it is part of a file name: a word after using, or a word before the first comma of save, use, do, run, copy and similar commands. Path-like words (dir/old.dta, ../x/old.dta) are covered too. A parenthesized operator argument counts only after an operator, so ib(first).foo and L(1/3).foo match and r(N).foo does not. The operator-word pattern is also stricter: one optional factor operator, then time-series operators. Everything Find references to a variable inside factor-variable terms such as i.foo and _b[2.foo] #410 matched (i., c., ib3., ibn., L2., LD., factor interactions, _b[]/_se[]) still matches.
  2. version 16: forvalues i = 3/1 { got no empty-range warning (from Warn about a forvalues range that runs no times, such as 3/1, and suggest the countdown #407). Command-position detection did not skip a version #: prefix. It does now, including when combined with capture/quietly/noisily and their colon forms.
  3. sight graph --json lost a parent's working directory for a grandchild (from Add sight parse --json and sight graph --json, so other tools can read Sight's view of Stata code #347). Graph used only explicit backward directives to find an inherited working directory. It now does what sight check does: it registers every file's calls in a dependency graph, then resolves each file's working directory with auto-discovered parents. In the repro, work/jobs/child.do's do grand.do now resolves to work/grand.do, and the only entry point is main.do. Graph follows check where check stops, too: inheritance is directive-based and one auto-discovered level deep. A four-level chain and a parent's in-script cd (not sight: cd) still leave a grandchild unresolved in both, by design (see docs/cross-file.md).
  4. sight graph dropped do-file arguments that start with if (from Add sight parse --json and sight graph --json, so other tools can read Sight's view of Stata code #347). Arguments came from the parser's varlist, so anything it put in a qualifier, weight, using, =exp or options was lost. Arguments are now every word after the file name, in source order, as Stata passes them to args. Words are split at spaces, and touching tokens form one word. do child.do if price > 100 gives ["if","price",">","100"]. The arguments doc in docs/cli.md is updated. Before, tokens glued to a macro were split (`a'b gave two items). Now they are one word, which is what Stata passes.

Proof: each item has a regression test that fails on main and passes here. The repros change from:

  • item 1: references ["2:10","3:10"] → ["2:10"];
  • item 2: a warning only at 4:15 → warnings at 1:27 and 4:15;
  • item 3: target: null, resolution: "missing" → target: "work/grand.do", resolution: "exact";
  • item 4: [] → ["if","price",">","100"].

check:line-endings, typecheck, bun test ./tests (9867 pass, 0 fail) and lint each pass on their own. The cli-json golden fixtures are unchanged.

Created with Claude Opus 5.5 in Claude Code.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 86 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 2aa7f647-310f-441c-a074-5d4f60e31963
Commits

Reviewing files that changed from the base of the PR and between cf0a45d and b7dd03d.

Files selected for processing: 8

  • docs/cli.md
  • docs/find-references.md
  • src/cli/graph.ts
  • src/providers/command-position.ts
  • src/providers/references.ts
  • tests/unit/cli/parse-graph-json.test.ts
  • tests/unit/forvalues-range-diagnostics.test.ts
  • tests/unit/references-factor-variables.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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