@@ -1539,7 +1539,7 @@ def ===(other)
1539
1539
private
1540
1540
1541
1541
def format_contents ( q )
1542
- q . parent . format_key ( q , key )
1542
+ ( q . parent || HashKeyFormatter :: Identity . new ) . format_key ( q , key )
1543
1543
return unless value
1544
1544
1545
1545
if key . comments . empty? && AssignFormatting . skip_indent? ( value )
@@ -1756,6 +1756,20 @@ def format_key(q, key)
1756
1756
end
1757
1757
end
1758
1758
1759
+ # When formatting a single assoc node without the context of the parent
1760
+ # hash, this formatter is used. It uses whatever is present in the node,
1761
+ # because there is nothing to be consistent with.
1762
+ class Identity
1763
+ def format_key ( q , key )
1764
+ if key . is_a? ( Label )
1765
+ q . format ( key )
1766
+ else
1767
+ q . format ( key )
1768
+ q . text ( " =>" )
1769
+ end
1770
+ end
1771
+ end
1772
+
1759
1773
def self . for ( container )
1760
1774
labels =
1761
1775
container . assocs . all? do |assoc |
@@ -4328,7 +4342,7 @@ def format(q)
4328
4342
# are no parentheses around the arguments to that command, so we need to
4329
4343
# break the block.
4330
4344
case q . parent
4331
- when Command , CommandCall
4345
+ when nil , Command , CommandCall
4332
4346
q . break_parent
4333
4347
format_break ( q , break_opening , break_closing )
4334
4348
return
@@ -4382,7 +4396,7 @@ def unchangeable_bounds?(q)
4382
4396
# If we're a sibling of a control-flow keyword, then we're going to have to
4383
4397
# use the do..end bounds.
4384
4398
def forced_do_end_bounds? ( q )
4385
- case q . parent . call
4399
+ case q . parent & .call
4386
4400
when Break , Next , ReturnNode , Super
4387
4401
true
4388
4402
else
0 commit comments