Skip to content

Commit

Permalink
Format: fix formatting StringLiteral in StringInterpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Aug 19, 2018
1 parent 40206f6 commit adbf845
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ describe Crystal::Formatter do
assert_format %("\#{\n foo = 1\n}")
assert_format %("\#{\n foo = 1}"), %("\#{\n foo = 1\n}")
assert_format %("\#{ # foo\n foo = 1\n}")
assert_format %("\#{"foo"}")
assert_format %("\#{"\#{foo}"}")

assert_format "%w(one two three)", "%w(one two three)"
assert_format "%i(one two three)", "%i(one two three)"
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ module Crystal
# This is the case of #{__DIR__}
write "\#{"
next_token_skip_space_or_newline
write @token.type
next_token_skip_space_or_newline
indent(@column, node)
skip_space_or_newline
check :"}"
write "}"
next_string_token
Expand Down Expand Up @@ -564,10 +564,10 @@ module Crystal
if exp.is_a?(StringLiteral)
# It might be #{__DIR__}, for example
if @token.type == :INTERPOLATION_START
next_token_skip_space_or_newline
write "\#{"
write @token.type
next_token_skip_space_or_newline
indent(@column, exp)
skip_space_or_newline
check :"}"
write "}"
else
Expand Down

0 comments on commit adbf845

Please sign in to comment.