Trailing commas + mix format

For people that love trailing commas, I released v2.0 of the freedom formatter. It is now a plugin for the builtin formatter (requires Elixir 1.13.2+).

Note that elixir-ls’s next release will support formatting plugins.

Thanks to José Valim for making formatter plugins possible :heart:, and Pete Gamache for the initial version of the freedom_formatter.

11 Likes

What do you think about adding tabular code formatting?

And what do you think about making the formatter bringing all clauses to a single line when possible, eg here when the inspect is removed:

case number do
  1 ->
    :one

  2 ->
    :two

  3 ->
    :three

  number ->
    IO.inspect(number)
    :very_big
end
3 Likes

Thanks for your question and interest :slight_smile:

I welcome PRs for new features. At first sight, both of these seem acceptable. Care must be taken into when they would trigger or not and have good test coverage.

I personally do not intend to actually write the implementation for any new option. Trailing commas is what I am interested in. It is in my mind a different beast than the rest because it is not about readability or esthetics, it is about ease of editing and about minimizing diffs. I doubt I will propose to my colleagues to use other formatting options.

If someone else writes them, I will gladly review them and maintain them though.

1 Like

For anyone interested, there’s a thread about trailing commas here:

:smiley:

1 Like

I stumbled on this thread after getting yet another compilation error from shuffling around the values in a long list (obviously, I moved the last one somewhere else in the list).

I think trailing commas are ugly, but they are simply more functional: Cleaner diffs, and makes it easier to shuffle values around.

Thanks for making this project! One less annoyance to babysit. :slight_smile:

4 Likes