Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format: fix formatting StringLiteral in interpolation #6568

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ 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 %("foo\#{"bar"} Baz \#{"qux"} ")
assert_format %("1\#{"4\#{"\#{"2"}"}3"}3\#{__DIR__}4\#{5}6")
assert_format %("1\#{"\#{"2"}"}3\#{"4"}5")

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