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

Trailing commas for multiline def / macro / fun parameter lists #13169

Closed
HertzDevil opened this issue Mar 9, 2023 · 0 comments · Fixed by #14075
Closed

Trailing commas for multiline def / macro / fun parameter lists #13169

HertzDevil opened this issue Mar 9, 2023 · 0 comments · Fixed by #14075

Comments

@HertzDevil
Copy link
Contributor

HertzDevil commented Mar 9, 2023

The formatter appends a comma to the last elements of multiline container literals:

[
  x,
  y, # this comma
]
{
  x,
  y,
}
{
  1 => x,
  2 => y,
}
{
  x: x,
  y: y,
}

to multiline type names (sometimes):

Tuple(Int32, String)

NamedTuple(
  x: Int32,
  y: String,
)

preserves it in multiline calls:

foo(
  1,
  2
)

foo(
  1,
  2,
)

but removes them from def parameter lists and similar nodes:

def foo(
  x,
  y
)
end

macro foo(
  x,
  y
)
end

fun foo(
  x : Int32,
  y : Int32
)
end

I think we should add the commas here too, unless the last parameter is a & or a .... This is to minimize diff noise when the parameters are moved around, added, or deleted. (By definition a block or a C vararg list must be the last parameter, so they aren't subject to this and can continue to have their trailing commas removed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant