Seal heredoc renders so nothing packs onto their terminator - #17
Merged
Conversation
Unparser legitimately falls back to <<-HEREDOC emission when a dstr fails its quoted-string round-trip; the line-aligned emitter then treated that render like any other statement and `;`-packed displaced statements (and container closers) onto the terminator line, unterminating the heredoc and producing invalid Ruby (#16). StatementRenderer#line_terminal? probes whether a render's last line can be extended (re-parse verification, the same style as compress_to_single_line, behind a cheap `<<` gate), and Layout#place accepts the result as a `seal:` property: a pack onto a sealed line opens a fresh line instead — alignment degrades by one line, validity is preserved. Statements and container openers both seal; a false-positive seal costs alignment, never correctness. Closes #16 Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Aug 3, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<<-HEREDOCemission (a dstr failing its quoted round-trip — e.g. interpolation-heavy strings carrying newlines), the line-aligned emitter packed displaced statements and container closers onto the terminator line with;, unterminating the heredoc and swallowing the rest of the file.StatementRenderer#line_terminal?decides whether a render's last line can be extended, by re-parse verification (the same stylecompress_to_single_linealready uses) behind a cheap<<textual gate. The probe chomps first: heredoc renders end with a trailing newline, and the question is about the last line, where packing would land.Layout#placeaccepts the verdict as aseal:property, keeping the layering intact (Layout stays Ruby-free — "this last line is unextendable" is a caller-declared property). A pack onto a sealed line opens a fresh line instead: alignment degrades by one line, validity is preserved. The seal covers exactly one pack; padding to a line ahead is unaffected.Test plan
line_aligned_emitter_test.rb: the Line-aligned emission places statements after a heredoc terminator, producing invalid Ruby #16-shaped source (heredoc-fallback render displacing following statements) now compiles, terminator alone on its line — failed with the issue's exactSyntaxErrorbefore the fixLayoutseal semantics: sealed pack opens a fresh line, seal covers one pack, padding unaffectedStatementRenderer#line_terminal?: heredoc render flagged; plain renders, shovel<<, quoted"<<-EOS", and multi-line quoted strings passMade with Cursor