What's new in Elixir - Dec/17

But that’s precisely where the inconsistency is. If we are not at the point to discuss those, then we are certainly not at the point to discuss trailing commas in the formatter. Trailing commas would be straight-forward if it was not for this particular issue.

1 Like

Will it be possible to use the formatted to fail a build?

I’m looking for something like mix formatted that would return a failure if running mix format would change any files.

2 Likes

Straight from the docs:

--check-formatted - check that the file is already formatted. This is useful in pre-commit hooks and CI scripts if you want to reject contributions with unformatted code. However, keep in mind, that the formatting output may differ between Elixir versions as improvements and fixes are applied to the formatter.

and

If any of the --check-* flags are given and a check fails, the formatted contents won’t be written to disk nor printed to stdout.

6 Likes

Here is a github issue where @pragdave points out a few pros for having trailing commas in (keyword) lists and (I suppose) other data structures too.
I also find it quite annoying to have a diff with several lines changed when I only added one line within a map for example or that I have to manually correct commas when I reorder a list and it would be great if I could just use a trailing comma without the formatter stripping it away.

I read through some posts here on the forum and a few related discussions on github and it seems that the plan is to first make it work and then add the flexibility (for cases such as trailing commas) later on. Would that be a correct interpretation :slight_smile: ?

Thank you very much in advance!

Yup!

There has also been a discussion about trailing commas here in the forum. If someone find it, please link it here, for those who are curious. :slight_smile:

Probably it is this post…

https://elixirforum.com/t/come-on-elixir-if-php-can-do-it-anybody-can-trailing-comma-now-allowed-in-function-method-calls/9856

2 Likes

Thank you for your quick reply! This clears things up for me.

Here is a topic I came across (besides this very topic) on the forum about it. It contains a few indirect and a direct remark about trailing commas. Is this by any chance the one you meant?

https://elixirforum.com/t/running-the-new-elixir-formatter/9344

1 Like

Both are excellent links, thanks. The one shared by @kokolegorille explains how trailing commas are tricky for functions calls in Elixir. The one by @rmoorman is the general formatter rationale/feedback thread.

1 Like