File tree Expand file tree Collapse file tree 3 files changed +41
-35
lines changed Expand file tree Collapse file tree 3 files changed +41
-35
lines changed Original file line number Diff line number Diff line change 35
35
}
36
36
37
37
__END__
38
- assoc.rb:1
38
+ assign.rb:6
39
+ assoc.rb:4
39
40
assoc.rb:8
40
41
bare_assoc_hash.rb:4
42
+ bare_assoc_hash.rb:5
41
43
brace_block.rb:1
42
44
break.rb:9
43
45
call.rb:7
@@ -52,7 +54,6 @@ command_call.rb:3
52
54
command_call.rb:4
53
55
command_call.rb:7
54
56
command_call.rb:9
55
- command_call.rb:10
56
57
command_call.rb:11
57
58
def.rb:6
58
59
def_endless.rb:9
@@ -66,7 +67,7 @@ elsif.rb:3
66
67
embdoc.rb:0
67
68
embdoc.rb:1
68
69
end_content.rb:0
69
- heredoc .rb:17
70
+ hash .rb:6
70
71
heredoc.rb:18
71
72
if.rb:3
72
73
if.rb:7
Original file line number Diff line number Diff line change @@ -427,39 +427,12 @@ def format_prefix(operator_loc, value)
427
427
428
428
# foo = bar
429
429
def format_write ( operator_loc , value )
430
- indent_value = true
431
- current = value
432
-
433
- # Here, determine whether or not we should attempt to indent the value of
434
- # the write. For certain nodes we can to avoid this because it will look
435
- # strange.
436
- until current . nil?
437
- case current . type
438
- when :array_node
439
- indent_value = current . opening_loc . nil?
440
- break
441
- when :hash_node , :lambda_node
442
- indent_value = false
443
- break
444
- when :string_node , :x_string_node , :interpolated_string_node , :interpolated_x_string_node
445
- indent_value = current . opening_loc ? !current . opening . start_with? ( "<<" ) : true
446
- break
447
- when :call_node
448
- current = current . receiver
449
- when :interpolated_symbol_node
450
- indent_value = current . opening_loc ? !current . opening . start_with? ( "%s" ) : true
451
- break
452
- else
453
- break
454
- end
455
- end
456
-
457
430
group do
458
431
yield
459
432
text ( " " )
460
433
loc ( operator_loc )
461
434
462
- if indent_value
435
+ if value . indent_write?
463
436
indent do
464
437
breakable_space
465
438
format ( value )
Original file line number Diff line number Diff line change @@ -42,6 +42,23 @@ def contains_write?
42
42
43
43
false
44
44
end
45
+
46
+ def indent_write?
47
+ case type
48
+ when :array_node
49
+ opening_loc . nil?
50
+ when :hash_node , :lambda_node
51
+ false
52
+ when :string_node , :x_string_node , :interpolated_string_node , :interpolated_x_string_node
53
+ opening_loc ? !opening . start_with? ( "<<" ) : true
54
+ when :call_node
55
+ receiver ? receiver . indent_write? : true
56
+ when :interpolated_symbol_node
57
+ opening_loc ? !opening . start_with? ( "%s" ) : true
58
+ else
59
+ true
60
+ end
61
+ end
45
62
end
46
63
47
64
class AliasGlobalVariableNode
@@ -242,14 +259,29 @@ def format(q)
242
259
if operator_loc
243
260
q . format ( key )
244
261
q . text ( " #{ operator } " )
245
- q . breakable_space
246
- q . format ( value )
262
+
263
+ if value . indent_write?
264
+ q . indent do
265
+ q . breakable_space
266
+ q . format ( value )
267
+ end
268
+ else
269
+ q . text ( " " )
270
+ q . format ( value )
271
+ end
247
272
else
248
273
q . format ( key )
249
274
250
275
if value && !value . is_a? ( ImplicitNode )
251
- q . text ( " " )
252
- q . format ( value )
276
+ if value . indent_write?
277
+ q . indent do
278
+ q . breakable_space
279
+ q . format ( value )
280
+ end
281
+ else
282
+ q . text ( " " )
283
+ q . format ( value )
284
+ end
253
285
end
254
286
end
255
287
end
You can’t perform that action at this time.
0 commit comments