Repository navigation
Conversation
Since 6.2.0, a comment on its own line before a leading-dot call in a
method chain is attached to the call operator. format_chain then prints
the operator trailing, which joins the comment to the previous line and
leaves the dot on a line of its own:
foo
.bar(:a, :b)# comment
.
baz
This is upstream syntax_tree issue 411.
The trailing operator is only necessary when the comment follows the
operator. The check now looks at the comment location, so a comment
that comes before a leading dot stays on its own line, as in 6.1.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #411.
Since 6.2.0, the formatter breaks a comment on its own line before a leading-dot call in a method chain. It joins the comment to the previous call and moves the dot to a line of its own:
The parser attaches that comment to the call operator. If the operator has any comment, a check that b345765 added to
format_chainprints the operator trailing. For a comment after the operator, a trailing operator is necessary, as in the existingfoo.\n # comment\n quxfixture. For a comment before a leading dot, the trailing operator breaks the output.This change applies the check only to an operator comment that starts after the operator ends. A comment before a leading dot then formats as it did in 6.1.1. The trailing-dot fixtures do not change.
The PR adds two fixtures to
test/fixtures/call.rb: one comment and two comments before a leading-dot call. Both fail without the change. The formatting and idempotency tests pass. I also formatted a codebase of about 12,000 Ruby files with 6.1.1 and with this change. The only differences were the intendeddo/endlambda change from 6.2.0.I saw #472, which was closed because of the move to the prism parser. This is a small, local change for the 6.x line, in case another 6.x release happens.