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

Incosistent formatting of trailing commas Hash vs. NamedTuple #10916

Open
szabgab opened this issue Jul 9, 2021 · 0 comments
Open

Incosistent formatting of trailing commas Hash vs. NamedTuple #10916

szabgab opened this issue Jul 9, 2021 · 0 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Comments

@szabgab
Copy link

szabgab commented Jul 9, 2021

Original file:

alias Ax = NamedTuple(
  a: String
)
alias Bx = NamedTuple(
  b: String,
)
x = {
  "name" => "Crystal"
}
y = {
  "name" => "Crystal",
}

running format:

crystal tool format

alias Ax = NamedTuple(
  a: String)
alias Bx = NamedTuple(
  b: String,
)
x = {
  "name" => "Crystal",
}
y = {
  "name" => "Crystal",
}

In the Hash a trailing comma was added, in the NamedTuple the trailing newline was removed and no trailing comma was added.
IMHO the correct behavior would be that in NamedTuples too the formatter will add a trailing comma and a newline after it.

So this is the expected output:

alias Ax = NamedTuple(
  a: String,
)
alias Bx = NamedTuple(
  b: String,
)
x = {
  "name" => "Crystal",
}
y = {
  "name" => "Crystal",
}

Even if a trailing comma is not added, IMHO the trailing newline should not be removed.

Test case for spec/compiler/formatter/formatter_spec.cr if trailing comma is expected:

assert_format "NamedTuple(\n  a: Int32\n)", "NamedTuple(\n  a: Int32,\n)"

Test case if leaving the trailing newline is expected:

assert_format "NamedTuple(\n  a: Int32\n)"
@szabgab szabgab added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter
Projects
None yet
Development

No branches or pull requests

2 participants