Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "Format multi-line braces blocks using do/end"
This reverts commit f833a82.
  • Loading branch information
asterite committed Jun 24, 2017
1 parent 72fe026 commit dc9e5cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
5 changes: 1 addition & 4 deletions spec/compiler/formatter/formatter_spec.cr
Expand Up @@ -205,7 +205,7 @@ describe Crystal::Formatter do
assert_format "foo do # hello\nend", "foo do # hello\nend"
assert_format "foo{}", "foo { }"
assert_format "foo{|x| x}", "foo { |x| x }"
assert_format "foo{|x|\n x}", "foo do |x|\n x\nend"
assert_format "foo{|x|\n x}", "foo { |x|\n x\n}"
assert_format "foo &.bar", "foo &.bar"
assert_format "foo &.bar( 1 , 2 )", "foo &.bar(1, 2)"
assert_format "foo.bar &.baz( 1 , 2 )", "foo.bar &.baz(1, 2)"
Expand Down Expand Up @@ -953,9 +953,6 @@ describe Crystal::Formatter do
assert_format "foo { | a, ( b , c, ), | a + b + c }", "foo { |a, (b, c)| a + b + c }"
assert_format "foo { | a, ( _ , c ) | a + c }", "foo { |a, (_, c)| a + c }"

assert_format "foo do |a| 2 end", "foo do |a|\n 2\nend"
assert_format "foo { |a|\n 2\n}", "foo do |a|\n 2\nend"

assert_format "def foo\n {{@type}}\nend"

assert_format "[\n 1, # foo\n 3,\n]"
Expand Down
16 changes: 7 additions & 9 deletions src/compiler/crystal/tools/formatter.cr
Expand Up @@ -1273,13 +1273,13 @@ module Crystal
end
end

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

if @token.type == :";"
if node.is_a?(Nop)
skip_semicolon_or_space_or_newline
check_end unless force_end
check_end
write "; end"
next_token
return false
Expand All @@ -1289,12 +1289,12 @@ module Crystal
end

format_nested node, column, write_end_line: write_end_line
format_end(column, force_end: force_end)
format_end(column)
end

def format_end(column, force_end = false)
def format_end(column)
skip_space_or_newline(column + 2, last: true)
check_end unless force_end
check_end
write_indent(column)
write "end"
next_token
Expand Down Expand Up @@ -2540,13 +2540,11 @@ module Crystal
next_token_skip_space_or_newline
end

needs_do_block = node.location.try(&.line_number) != node.end_location.try(&.line_number)

if @token.keyword?(:do) || (@token.type == :"{" && needs_do_block)
if @token.keyword?(:do)
write " do"
next_token_skip_space
body = format_block_args node.args, node
format_nested_with_end body, force_end: needs_do_block
format_nested_with_end body
elsif @token.type == :"{"
write "," if needs_comma
write " {"
Expand Down

0 comments on commit dc9e5cc

Please sign in to comment.