Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

### Changed

- A comment on its own line before a leading-dot call in a method chain stays on its own line. It is no longer joined to the previous call with the dot moved to a separate line.

## [6.3.0] - 2025-07-16

### Added
Expand Down
14 changes: 11 additions & 3 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2860,13 +2860,21 @@ def format_chain(q, children)
skip_attached: empty_except_last && children.empty?
)

# If the parent call node has a comment on the message then we need
# to print the operator trailing in order to keep it working.
# If the parent call node has a comment on the message, or a comment
# that follows the operator, then we need to print the operator
# trailing in order to keep it working. A comment that comes before
# a leading operator stays on its own line above the call.
last_child = children.last
if last_child.is_a?(CallNode) && last_child.message != :call &&
(
(last_child.message.comments.any? && last_child.operator) ||
(last_child.operator && last_child.operator.comments.any?)
(
last_child.operator &&
last_child.operator.comments.any? do |comment|
comment.location.start_char >=
last_child.operator.location.end_char
end
)
)
q.format(CallOperatorFormatter.new(last_child.operator))
skip_operator = true
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@
qux
.quux
%
foo
.bar(:a, :b)
# comment
.baz
.qux
%
foo
.bar
# first comment
# second comment
.baz(:a)
.qux
%
{ a: 1, b: 2 }.fooooooooooooooooo.barrrrrrrrrrrrrrrrrrr.bazzzzzzzzzzzz.quxxxxxxxxxxxx
-
{ a: 1, b: 2 }.fooooooooooooooooo
Expand Down