Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 06ca006

Browse files
committed
Properly handle trailing operators in call chains with attached comments.
1 parent 93bf48f commit 06ca006

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
5050
- Allow flip-flop operators to be formatted correctly within `IfMod` and `UnlessMod` nodes.
5151
- Allow `IfMod` and `UnlessMod` to know about heredocs moving their bounds.
5252
- Properly handle breaking parameters when there are no parentheses.
53+
- Properly handle trailing operators in call chains with attached comments.
5354

5455
### Removed
5556

lib/syntax_tree.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,12 +3093,19 @@ def child_nodes
30933093
end
30943094

30953095
def format(q)
3096+
call_operator = CallOperatorFormatter.new(operator)
3097+
30963098
q.group do
30973099
q.format(receiver)
3100+
3101+
# If there are trailing comments on the call operator, then we need to
3102+
# use the trailing form as opposed to the leading form.
3103+
q.format(call_operator) if call_operator.comments.any?
3104+
30983105
q.group do
30993106
q.indent do
3100-
q.breakable(force: true) if receiver.comments.any?
3101-
q.format(CallOperatorFormatter.new(operator))
3107+
q.breakable(force: true) if receiver.comments.any? || call_operator.comments.any?
3108+
q.format(call_operator) if call_operator.comments.empty?
31023109
q.format(message) if message != :call
31033110
q.format(arguments) if arguments
31043111
end

0 commit comments

Comments
 (0)