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

Fix formatter for white space in a.[b] syntax #14346

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
6 changes: 6 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,12 @@ describe Crystal::Formatter do
assert_format "foo[] =1", "foo[] = 1"
assert_format "foo[ 1 , 2 ] =3", "foo[1, 2] = 3"

assert_format "foo.[]"
assert_format "foo.[ 1 , 2 ]", "foo.[1, 2]"
assert_format "foo.[ 1, 2 ]?", "foo.[1, 2]?"
assert_format "foo.[] =1", "foo.[] = 1"
assert_format "foo.[ 1 , 2 ] =3", "foo.[1, 2] = 3"

assert_format "1 || 2", "1 || 2"
assert_format "a || b", "a || b"
assert_format "1 && 2", "1 && 2"
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,7 @@ module Crystal
write "["
next_token_skip_space_or_newline
format_call_args(node, false, base_indent)
skip_space_or_newline
write_token :OP_RSQUARE
write_token :OP_QUESTION if node.name == "[]?"
return false
Expand All @@ -2703,6 +2704,7 @@ module Crystal
args = node.args
last_arg = args.pop
format_call_args(node, true, base_indent)
skip_space_or_newline
write_token :OP_RSQUARE
skip_space_or_newline
write " ="
Expand Down
Loading