@@ -359,7 +359,8 @@ class Alias < Node
359
359
# Formats an argument to the alias keyword. For symbol literals it uses the
360
360
# value of the symbol directly to look like bare words.
361
361
class AliasArgumentFormatter
362
- # [Backref | DynaSymbol | GVar | SymbolLiteral] the argument being passed to alias
362
+ # [Backref | DynaSymbol | GVar | SymbolLiteral] the argument being passed
363
+ # to alias
363
364
attr_reader :argument
364
365
365
366
def initialize ( argument )
@@ -2271,7 +2272,8 @@ def format(q)
2271
2272
# of just Statements nodes.
2272
2273
parent = parents [ 3 ] if parent . is_a? ( Block ) && parent . keywords?
2273
2274
2274
- if parent . is_a? ( MethodAddBlock ) && parent . call . is_a? ( Call ) && parent . call . message . value == "sig"
2275
+ if parent . is_a? ( MethodAddBlock ) && parent . call . is_a? ( Call ) &&
2276
+ parent . call . message . value == "sig"
2275
2277
threshold = 2
2276
2278
end
2277
2279
end
@@ -2300,7 +2302,7 @@ def format_chain(q, children)
2300
2302
# formatter so it's as if we had descending normally into them. This is
2301
2303
# necessary so they can check their parents as normal.
2302
2304
q . stack . concat ( children )
2303
- q . format ( children . last . receiver )
2305
+ q . format ( children . last . receiver ) if children . last . receiver
2304
2306
2305
2307
q . group do
2306
2308
if attach_directly? ( children . last )
@@ -2343,7 +2345,8 @@ def format_chain(q, children)
2343
2345
# If the parent call node has a comment on the message then we need
2344
2346
# to print the operator trailing in order to keep it working.
2345
2347
last_child = children . last
2346
- if last_child . is_a? ( Call ) && last_child . message . comments . any?
2348
+ if last_child . is_a? ( Call ) && last_child . message . comments . any? &&
2349
+ last_child . operator
2347
2350
q . format ( CallOperatorFormatter . new ( last_child . operator ) )
2348
2351
skip_operator = true
2349
2352
else
@@ -2405,7 +2408,7 @@ def format_child(
2405
2408
case child
2406
2409
when Call
2407
2410
q . group do
2408
- unless skip_operator
2411
+ if ! skip_operator && child . operator
2409
2412
q . format ( CallOperatorFormatter . new ( child . operator ) )
2410
2413
end
2411
2414
q . format ( child . message ) if child . message != :call
@@ -2495,7 +2498,8 @@ def format(q)
2495
2498
# If we're at the top of a call chain, then we're going to do some
2496
2499
# specialized printing in case we can print it nicely. We _only_ do this
2497
2500
# at the top of the chain to avoid weird recursion issues.
2498
- if CallChainFormatter . chained? ( receiver ) && !CallChainFormatter . chained? ( q . parent )
2501
+ if CallChainFormatter . chained? ( receiver ) &&
2502
+ !CallChainFormatter . chained? ( q . parent )
2499
2503
q . group do
2500
2504
q
2501
2505
. if_break { CallChainFormatter . new ( self ) . format ( q ) }
@@ -2507,11 +2511,13 @@ def format(q)
2507
2511
else
2508
2512
q . format ( message )
2509
2513
2510
- if arguments . is_a? ( ArgParen ) && arguments . arguments . nil? && !message . is_a? ( Const )
2511
- # If you're using an explicit set of parentheses on something that looks
2512
- # like a constant, then we need to match that in order to maintain valid
2513
- # Ruby. For example, you could do something like Foo(), on which we
2514
- # would need to keep the parentheses to make it look like a method call.
2514
+ if arguments . is_a? ( ArgParen ) && arguments . arguments . nil? &&
2515
+ !message . is_a? ( Const )
2516
+ # If you're using an explicit set of parentheses on something that
2517
+ # looks like a constant, then we need to match that in order to
2518
+ # maintain valid Ruby. For example, you could do something like Foo(),
2519
+ # on which we would need to keep the parentheses to make it look like
2520
+ # a method call.
2515
2521
else
2516
2522
q . format ( arguments )
2517
2523
end
@@ -3726,7 +3732,13 @@ def child_nodes
3726
3732
alias deconstruct child_nodes
3727
3733
3728
3734
def deconstruct_keys ( _keys )
3729
- { left : left , operator : operator , right : right , location : location , comments : comments }
3735
+ {
3736
+ left : left ,
3737
+ operator : operator ,
3738
+ right : right ,
3739
+ location : location ,
3740
+ comments : comments
3741
+ }
3730
3742
end
3731
3743
3732
3744
def format ( q )
@@ -5133,7 +5145,11 @@ def format(q)
5133
5145
if ContainsAssignment . call ( statement ) || q . parent . is_a? ( In )
5134
5146
q . group { format_flat ( q ) }
5135
5147
else
5136
- q . group { q . if_break { format_break ( q , force : false ) } . if_flat { format_flat ( q ) } }
5148
+ q . group do
5149
+ q
5150
+ . if_break { format_break ( q , force : false ) }
5151
+ . if_flat { format_flat ( q ) }
5152
+ end
5137
5153
end
5138
5154
else
5139
5155
# If we can transform this node into a ternary, then we're going to
@@ -9063,7 +9079,8 @@ def format(q)
9063
9079
#
9064
9080
# foo = bar while foo
9065
9081
#
9066
- if node . modifier? && ( statement = node . statements . body . first ) && ( statement . is_a? ( Begin ) || ContainsAssignment . call ( statement ) )
9082
+ if node . modifier? && ( statement = node . statements . body . first ) &&
9083
+ ( statement . is_a? ( Begin ) || ContainsAssignment . call ( statement ) )
9067
9084
q . format ( statement )
9068
9085
q . text ( " #{ keyword } " )
9069
9086
q . format ( node . predicate )
@@ -9466,9 +9483,7 @@ def format(q)
9466
9483
# last argument to the predicate is and endless range, then you are
9467
9484
# forced to use the "then" keyword to make it parse properly.
9468
9485
last = arguments . parts . last
9469
- if last . is_a? ( RangeLiteral ) && !last . right
9470
- q . text ( " then" )
9471
- end
9486
+ q . text ( " then" ) if last . is_a? ( RangeLiteral ) && !last . right
9472
9487
end
9473
9488
end
9474
9489
0 commit comments