stylish-haskell icon indicating copy to clipboard operation
stylish-haskell copied to clipboard

newtypes are formatted on two lines with break_single_constructors: false

Open imuli opened this issue 3 years ago • 6 comments

As newtypes always have a single constructor, you would think that they would obey break_single_constructors. However, with that set to false,

newtype Foo = Foo Int

becomes

newtype Foo
   = Foo Int

while data with a single constructor stay on one line.

data Foo = Foo Int

imuli avatar Nov 27 '20 00:11 imuli

Okay, having now found the place in the source that explicitly checks this and the test case that claims the current behavior is correct, it seems like @jaspervdj wants this behavior. I still find it unintuitive - if it's not too much configuration bloat could we add a break_newtypes flag?

imuli avatar Nov 27 '20 00:11 imuli

I think this accident @imuli . newtype and data have to be consistent. let's fix that.

EncodePanda avatar Apr 09 '21 08:04 EncodePanda

Hello, any progress on that? Maybe I can help somehow?

stevladimir avatar May 30 '22 10:05 stevladimir

Yeah this is accidental. I would welcome a PR that fixes this :-)

jaspervdj avatar May 30 '22 10:05 jaspervdj

IMO this should be the default behavior, but it is somewhat breaking change (people might get big diffs) if we just directly alter the current behavior. If this is acceptable I would go this way as I see no strong reasons to distinguish newtype and data in this respect.

Otherwise, @imuli has a fix which should be backwards compatible in cost of introducing a new option.

Which one would you prefer?

stevladimir avatar May 30 '22 11:05 stevladimir

I think the primary issue with my fix as it stands is that it doesn't provide any tests?

I also would have no complaints about somone removing the option in favor of break_single_constructors.

imuli avatar May 30 '22 11:05 imuli