Skip to content

Commit

Permalink
Format: fix indentation in collection with comment after beginning de…
Browse files Browse the repository at this point in the history
…limiter (crystal-lang#5893)
  • Loading branch information
makenowjust authored and RX14 committed Apr 2, 2018
1 parent 49d722c commit e17823f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ describe Crystal::Formatter do
assert_format " [ 1, \n 2 , \n 3 ] ", "[1,\n 2,\n 3]"
assert_format "Set { 1 , 2 }", "Set{1, 2}"
assert_format "[\n1,\n\n2]", "[\n 1,\n\n 2,\n]"
assert_format "[ # foo\n 1,\n]"
assert_format "Set{ # foo\n 1,\n}"

assert_format "{1, 2, 3}"
assert_format "{ {1, 2, 3} }"
assert_format "{ {1 => 2} }"
assert_format "{ {1, 2, 3} => 4 }"
assert_format "{ {foo: 2} }"
assert_format "{ # foo\n 1,\n}"

assert_format "{ } of A => B", "{} of A => B"
assert_format "{ 1 => 2 }", "{1 => 2}"
Expand All @@ -91,6 +94,7 @@ describe Crystal::Formatter do
assert_format "{ \"foo\" => 1 }", "{\"foo\" => 1}"
assert_format "{ 1 => 2 ,\n\n 3 => 4 }", "{1 => 2,\n\n 3 => 4}"
assert_format "foo({\nbar: 1,\n})", "foo({\n bar: 1,\n})"
assert_format "{ # foo\n 1 => 2,\n}"

assert_format "Foo"
assert_format "Foo:: Bar", "Foo::Bar"
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ module Crystal
found_comment = false
found_first_newline = false

skip_space
if @token.type == :NEWLINE
found_comment = skip_space
if found_comment || @token.type == :NEWLINE
# add one level of indentation for contents if a newline is present
offset = @indent + 2

Expand Down

0 comments on commit e17823f

Please sign in to comment.