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

Commit 8c5a72a

Browse files
committed
Allow for the possibility that CommandCall nodes might not have arguments.
1 parent 7312e80 commit 8c5a72a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
3434
- Replicate content for `__END__` keyword exactly.
3535
- Keep block `If`, `Unless`, `While`, and `Until` forms if there is an assignment in the predicate.
3636
- Force using braces if the block is within the predicate of a conditional or loop.
37+
- Allow for the possibility that `CommandCall` nodes might not have arguments.
3738

3839
### Removed
3940

lib/syntax_tree.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,7 +3581,7 @@ class CommandCall
35813581
# [Const | Ident | Op] the message being send
35823582
attr_reader :message
35833583

3584-
# [Args] the arguments going along with the message
3584+
# [nil | Args] the arguments going along with the message
35853585
attr_reader :arguments
35863586

35873587
# [Location] the location of this node
@@ -3617,15 +3617,17 @@ def format(q)
36173617
q.format(receiver)
36183618
q.format(CallOperatorFormatter.new(operator))
36193619
q.format(message)
3620-
q.text(" ")
36213620
end
36223621

3623-
width = doc_width(doc)
3622+
if arguments
3623+
width = doc_width(doc) + 1
3624+
q.text(" ")
36243625

3625-
if width > (q.maxwidth / 2)
3626-
q.format(arguments)
3627-
else
3628-
q.nest(width) { q.format(arguments) }
3626+
if width > (q.maxwidth / 2)
3627+
q.format(arguments)
3628+
else
3629+
q.nest(width) { q.format(arguments) }
3630+
end
36293631
end
36303632
end
36313633
end
@@ -3643,8 +3645,10 @@ def pretty_print(q)
36433645
q.breakable
36443646
q.pp(message)
36453647

3646-
q.breakable
3647-
q.pp(arguments)
3648+
if arguments
3649+
q.breakable
3650+
q.pp(arguments)
3651+
end
36483652

36493653
q.pp(Comment::List.new(comments))
36503654
end
@@ -3695,7 +3699,7 @@ def doc_width(parent)
36953699
# untyped receiver,
36963700
# (:"::" | Op | Period) operator,
36973701
# (Const | Ident | Op) message,
3698-
# Args arguments
3702+
# (nil | Args) arguments
36993703
# ) -> CommandCall
37003704
def on_command_call(receiver, operator, message, arguments)
37013705
ending = arguments || message

0 commit comments

Comments
 (0)