Skip to content

Commit dc9e5cc

Browse files
committedJun 24, 2017
Revert "Format multi-line braces blocks using do/end"
This reverts commit f833a82.
1 parent 72fe026 commit dc9e5cc

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed
 

‎spec/compiler/formatter/formatter_spec.cr

+1-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe Crystal::Formatter do
205205
assert_format "foo do # hello\nend", "foo do # hello\nend"
206206
assert_format "foo{}", "foo { }"
207207
assert_format "foo{|x| x}", "foo { |x| x }"
208-
assert_format "foo{|x|\n x}", "foo do |x|\n x\nend"
208+
assert_format "foo{|x|\n x}", "foo { |x|\n x\n}"
209209
assert_format "foo &.bar", "foo &.bar"
210210
assert_format "foo &.bar( 1 , 2 )", "foo &.bar(1, 2)"
211211
assert_format "foo.bar &.baz( 1 , 2 )", "foo.bar &.baz(1, 2)"
@@ -953,9 +953,6 @@ describe Crystal::Formatter do
953953
assert_format "foo { | a, ( b , c, ), | a + b + c }", "foo { |a, (b, c)| a + b + c }"
954954
assert_format "foo { | a, ( _ , c ) | a + c }", "foo { |a, (_, c)| a + c }"
955955

956-
assert_format "foo do |a| 2 end", "foo do |a|\n 2\nend"
957-
assert_format "foo { |a|\n 2\n}", "foo do |a|\n 2\nend"
958-
959956
assert_format "def foo\n {{@type}}\nend"
960957

961958
assert_format "[\n 1, # foo\n 3,\n]"

‎src/compiler/crystal/tools/formatter.cr

+7-9
Original file line numberDiff line numberDiff line change
@@ -1273,13 +1273,13 @@ module Crystal
12731273
end
12741274
end
12751275

1276-
def format_nested_with_end(node, column = @indent, write_end_line = true, force_end = false)
1276+
def format_nested_with_end(node, column = @indent, write_end_line = true)
12771277
skip_space(column + 2)
12781278

12791279
if @token.type == :";"
12801280
if node.is_a?(Nop)
12811281
skip_semicolon_or_space_or_newline
1282-
check_end unless force_end
1282+
check_end
12831283
write "; end"
12841284
next_token
12851285
return false
@@ -1289,12 +1289,12 @@ module Crystal
12891289
end
12901290

12911291
format_nested node, column, write_end_line: write_end_line
1292-
format_end(column, force_end: force_end)
1292+
format_end(column)
12931293
end
12941294

1295-
def format_end(column, force_end = false)
1295+
def format_end(column)
12961296
skip_space_or_newline(column + 2, last: true)
1297-
check_end unless force_end
1297+
check_end
12981298
write_indent(column)
12991299
write "end"
13001300
next_token
@@ -2540,13 +2540,11 @@ module Crystal
25402540
next_token_skip_space_or_newline
25412541
end
25422542

2543-
needs_do_block = node.location.try(&.line_number) != node.end_location.try(&.line_number)
2544-
2545-
if @token.keyword?(:do) || (@token.type == :"{" && needs_do_block)
2543+
if @token.keyword?(:do)
25462544
write " do"
25472545
next_token_skip_space
25482546
body = format_block_args node.args, node
2549-
format_nested_with_end body, force_end: needs_do_block
2547+
format_nested_with_end body
25502548
elsif @token.type == :"{"
25512549
write "," if needs_comma
25522550
write " {"

0 commit comments

Comments
 (0)
Please sign in to comment.