tfausak / cabal-gild

:crown: Format Haskell package descriptions.
https://hackage.haskell.org/package/cabal-gild
MIT License
48 stars 5 forks source link

Let input influence output? #54

Closed tfausak closed 7 months ago

tfausak commented 7 months ago

This would kind of address #20 and #28.

Currently Gild has one special case for formatting: If a field's value can be rendered on one line and has no comments attached, it will be rendered on the same line as the field. In other words:

one-line: yes

two-lines:
  hello
  world

one-line-with-comment:
  -- comment
  hello

Multiple people have requested a way for some fields to sometimes have their single-line value put on its own line even though it would normally go on the same line as the field name. For example:

one-line:
  yes

I opted not to allow configuration for this and not to special case any field names for this.

I'm now wondering if there's a way out. In addition to the previous rules, what if Gild only formatted things on one line if the input was also on one line? To wit:

-- input
foo: bar
-- output
foo: bar
-- input
foo:
 bar
-- output
foo:
  bar

I typically prefer formatters that produce the same output for all inputs that map to the same AST. However this feels like relatively unsurprising behavior, and it would allow users to put single field values on their own lines if they wanted to.

I'm not sure how complicated this would be to support. Gild currently only uses positions to attach comments and re-flow free text (like in the description field).

nikita-volkov commented 7 months ago

Sounds great! I like it! A nifty compromise.

michaelpj commented 7 months ago

This is pretty much the ormolu approach: the user gets to choose (via the input) whether an element is formatted on one line or multiple lines, and then after that the tool decides how to format.

tfausak commented 7 months ago

Released in version 1.2.0.0.