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

Commit d9810d5

Browse files
committed
Ensure the Return breaks with brackets and not parentheses.
1 parent 29d675f commit d9810d5

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
3737
- Allow for the possibility that `CommandCall` nodes might not have arguments.
3838
- Explicitly handle `?"` so that it formats properly.
3939
- Check that a block is within the predicate in a more relaxed way.
40+
- Ensure the `Return` breaks with brackets and not parentheses.
4041

4142
### Removed
4243

lib/syntax_tree.rb

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,20 +2930,35 @@ def format(q)
29302930
q.text(keyword)
29312931

29322932
if arguments.parts.any?
2933-
if arguments.parts.length == 1 && arguments.parts.first.is_a?(Paren)
2934-
q.format(arguments)
2935-
else
2936-
q.if_break { q.text("(") }
2937-
q.indent do
2938-
q.breakable(" ")
2933+
if arguments.parts.length == 1
2934+
part = arguments.parts.first
2935+
2936+
if part.is_a?(Paren)
2937+
q.format(arguments)
2938+
elsif part.is_a?(ArrayLiteral)
2939+
q.text(" ")
29392940
q.format(arguments)
2941+
else
2942+
format_arguments(q, "(", ")")
29402943
end
2941-
q.breakable("")
2942-
q.if_break { q.text(")") }
2944+
else
2945+
format_arguments(q, " [", "]")
29432946
end
29442947
end
29452948
end
29462949
end
2950+
2951+
private
2952+
2953+
def format_arguments(q, opening, closing)
2954+
q.if_break { q.text(opening) }
2955+
q.indent do
2956+
q.breakable(" ")
2957+
q.format(node.arguments)
2958+
end
2959+
q.breakable("")
2960+
q.if_break { q.text(closing) }
2961+
end
29472962
end
29482963

29492964
# Break represents using the +break+ keyword.

0 commit comments

Comments
 (0)