Preserve trailing vs. leading commas?

Recently we added dhall format support for preserving the ASCII vs. Unicode encoding from the original Dhall file and I was wondering if we should do something similar for preserving trailing vs. leading commas. That way people who prefer to use trailing commas can begin doing so and it wouldn’t break or reformat any existing code in the wild.

There would also be the option of explicitly specifying one or the other comma style via command-line options if you wanted to override the file’s original formatting (similar to how dhall format still accepts --ascii and --unicode for overriding the original formatting).

This is most recently prompted by https://github.com/dhall-lang/dhall-haskell/commit/5f7d46b17922651d0fce76ca0fa1f2c8fb30bf79#commitcomment-49077659 and similar feedback I’ve gotten from others along those lines.

That sounds like a reasonable addition to the formatting logic to me. But if we keep on adding more options like this we should really consider having a configuration file somewhere (project, xdg_config_home).

In terms of implementation, if there is some interest in this feature I could give it a shot. Having done the unicode/ascii automatic detection I can see something similar working for leading/trailing commas.

I do wonder if there wouldn’t be a lighter weight option (from the user’s perspective) for this instead of relying on a flag/configuration file. We could detect for every comma separated block (curly or square brackets) which one of trailing or leading is desired from the first comma and update the rest to match it. This way we can easily switch from one style to the other without having to leave the text editor (assuming format on save). This style of formatting choice is similar to what elm-format or ormolu provide for letting the user choose between single-line and mutli-line formatting.