tweag / topiary

https://topiary.tweag.io/
MIT License
582 stars 29 forks source link

Should we enforce consistency of a final semicolon in parentheses or `begin`/`end`? #619

Open Niols opened 1 year ago

Niols commented 1 year ago

As of 3964d3c, Topiary formats both:

(
  foo;
  bar
)

and

(
  foo;
  bar;
)

as they are. (And same with begin/end.)

For the single-line style, Topiary formats:

(foo; bar)

and

(foo; bar; )

as they are. (While we're at it, note the space after the last semi-colon.)

This makes me wonder whether we shouldn't enforce consistency of those styles, the same way we do it with records and lists, for instance. The style would therefore be:

(foo; bar)

for single-line, and:

(
  foo;
  bar;
)

for multi-line.

I am however a bit afraid that this might make aerated single-element parentheses very ugly, namely:

(
  foo
)

would always have to be:

(
  foo;
)

and I think this would interact potentially very poorly with multi-line functions or matches as parameters, for instance. Any ideas? @aspiwack and @nbacquey in particular?

Niols commented 1 year ago

Actually, I don't think we enforce this style in records and lists. I had in mind that we did, but maybe it is just hard to do?

nbacquey commented 1 year ago

This problem has a large amount of complexity when you factor in comments and attributes. I'd recommend not to try addressing this properly before #430 is done.

Niols commented 1 year ago

Actually, I'm wondering if the rule shouldn't be that when tuples/lists/arrays have only one element, then there is no last separator, even in multi-line mode; when there are more than one elements in single-line mode, still no last separator; and when there are more than one elements in multi-line mode, then there should be a last separator.

This rule is not very nice with respect to Git diffs, and systematically adding a last separator in multi-line mode might make more sense for that. However, I think it might be pretty shocking for people to have a list of one element with a separator. It is also maybe fine to have singletons handled in a different way because it is usually not random that something is a singleton.