Skip to content

Track single-quoted strings and skip comments when detecting missing record commas#202

Merged
fdncred merged 1 commit into
nushell:mainfrom
momomuchu:fix/interpolation-spurious-comma-201
Jul 5, 2026
Merged

Track single-quoted strings and skip comments when detecting missing record commas#202
fdncred merged 1 commit into
nushell:mainfrom
momomuchu:fix/interpolation-spurious-comma-201

Conversation

@momomuchu

Copy link
Copy Markdown
Contributor

Description of changes

detect_missing_record_comma_positions tracked double-quote string state but not single-quoted strings, so a " inside a '...' literal (e.g. let x = '"') desynced the parser's quote tracking and caused a spurious comma to be inserted into a later $"..." interpolation.

This adds single-quote string tracking, and also skips # comment bodies during the same scan (reusing the existing comment extraction from comments.rs) so an apostrophe inside a comment like # don't can't be mistaken for the start of a single-quoted string and desync things the same way.

Relevant Issues

Fixes #201

…repair

detect_missing_record_comma_positions tracked single- and double-quote
string state but had no awareness of `#` line comments. An apostrophe
inside a comment (don't, it's, can't) toggled the single-quote tracking
just like a real string, desyncing quote parity for everything after it
until the next `'`. That could reintroduce the exact nushell#201 spurious-comma
bug even with balanced quotes in actual code, as long as a comment with
an odd number of apostrophes preceded a $"..." interpolation closely
enough to fall in the repair window.

Skip `#`-to-end-of-line comment spans before doing byte-level quote
tracking, reusing the existing string-aware comment extraction from
comments.rs so a `#` inside a string still isn't treated as a comment.

Fixes nushell#201
@fdncred fdncred merged commit de41085 into nushell:main Jul 5, 2026
5 checks passed
@fdncred

fdncred commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Thanks

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.

nufmt inserts spurious comma

2 participants