Repository navigation
Conversation
Sija
force-pushed
the
formatter-fix-heredoc-comma-placement
branch
from
November 3, 2026 19:38
f0354a9 to
aa08114
Compare
The formatter wrote a heredoc's body as soon as the newline following it
was read, so code that reads ahead before deciding on a comma would put
the comma after the heredoc's terminator, producing invalid code.
Write the body when that newline is written or moved past instead, which
lets the comma go on the line that starts the heredoc. This also makes
the `has_heredoc_in_line` workaround for literals unnecessary.
Fixes the following:
- call and index arguments, including when followed by a block
- `foo <<-H,` followed by `&.bar` on a later line
- `[` or `{` literals with a comment after the comma, which got a double
comma (`<<-H,, # c`)
Also indent `&.bar` and `&block` when they start a new line after a
comment or a comma, instead of writing a single space or none. This
changes the output for existing code such as `foo 1, # c` followed by
`&.bar` or `&block`.
Assisted-by: Claude:claude-opus-5-5
Sija
force-pushed
the
formatter-fix-heredoc-comma-placement
branch
from
November 4, 2026 13:59
aa08114 to
ea4a904
Compare
Fixes the following: - a blank line written before `)` when the last parameter of a `def` or `macro` has a heredoc as its default value - a blank line added above a comment that follows a heredoc's terminator inside call parentheses - `)` written at column 0 in nested code after a trailing comma, when a heredoc or comment had already ended the line, which was only corrected by formatting again - a comment before `)` losing its indentation in `yield(...)` and other calls going through `format_parenthesized_args` This makes all of these idempotent. The `)` fix also changes the output for nested code without heredocs, such as `foo(1, # c` followed by `)`. Assisted-by: Claude:claude-opus-5-5
Keep both behaviours in `Formatter#format_block`: the lookahead for a comment before `&.foo` skips any spaces and newlines, but stops at a newline with a pending heredoc. Assisted-by: Claude:claude-opus-5-5
Fixes the following: - a named argument written at column 0 after a heredoc followed by a comma and a comment - `}` of a block written with a single space instead of the indentation when a heredoc or comment had already ended the line - `&block` and `&.bar` written at column 0 after a comment following `(`, when there are no other arguments - the first argument of `yield(...)` and annotations written at column 0 after a comment following `(` - additional comment lines before `)` or `}` losing their indentation Assisted-by: Claude:claude-opus-5-5
…redoc `finish_args` and the code writing `)` before a block relied on whether a comment was found anywhere in the arguments, rather than on whether the line had already ended. Use `@wrote_newline` instead, which fixes the following: - `)` and `]` written at column 0 in nested code after a heredoc or comment - spaces written before `)` when an earlier argument was followed by a comment, such as `foo(1, # c` followed by `2)` - `)` before a block not following the indentation of a multiline call chain Also let `format_block` write the comma before `&.foo` inside an index call. It was written after a preceding heredoc or comment, producing invalid code. Assisted-by: Claude:claude-opus-5-5
This branch has not been deployed
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.
The formatter wrote a heredoc's body as soon as the newline following it was read, so code that reads ahead before deciding on a comma would put the comma after the heredoc's terminator, producing invalid code.
Write the body when that newline is written or moved past instead, which lets the comma go on the line that starts the heredoc. This also makes the
has_heredoc_in_lineworkaround for literals unnecessary.Fixes the following:
foo <<-H,followed by&.baron a later linefoo[1, # cfollowed by&.bar], which got the comma after the comment[or{literals with a comment after the comma, which got a double comma (<<-H,, # c)Also fix the indentation of arguments,
&.bar,&block, closing delimiters and comments before them, when a heredoc or comment has already ended the line. This changes the output for existing code without heredocs, too:)before a block now follows the indentation of a multiline call chain:Resolves #10278