ormolu
ormolu copied to clipboard
StandaloneDeriving: preserve choice of blank lines
StandaloneDeriving requires separate lines for each derived instance:
data Foo
deriving stock instance Generic Foo
deriving anyclass instance FromJSON Foo
deriving anyclass instance ToJSON Foo
deriving anyclass instance FromDhall Foo
deriving anyclass instance ToDhall Foo
Right now, ormolu will insert blank lines inbetween the deriving statements, which is unnecessary IMHO and also prevents grouping of related derivings.
data Foo
deriving stock instance Generic Foo
deriving anyclass instance FromJSON Foo
deriving anyclass instance ToJSON Foo
deriving anyclass instance FromDhall Foo
deriving anyclass instance ToDhall Foo
What about preserving the choice of blank lines, similar to #554? Happy to put a PR together in this case.
I'm not sure. If the declarations are multi-line it becomes desirable to separate them for readability. If so, should preservation of blank lines be conditional?
Yes, blank lines are sometimes useful for separation. To clarify, I would like both of my code examples above to be unchanged when formatted, as well as
data Foo
deriving stock instance Generic Foo
deriving anyclass instance FromJSON Foo
deriving anyclass instance ToJSON Foo
deriving anyclass instance FromDhall Foo
deriving anyclass instance ToDhall Foo
Sorry, I meant, should it be conditional on multi-line vs single line layout of the deriving declarations?
Ah, so you mean that if we had
deriving stock instance Generic Foo
deriving via
CustomJSON
'[ OmitNothingFields,
FieldLabelModifier (StripPrefix "foo", CamelToSnake)
]
Foo
instance
FromJSON Foo
then the question is whether ormolu should add a blank line inbetween as the second deriving declaration is multiline?
I have no strong opinion here, but I don't think it is strictly necessary to preserve readability.
Variant of #635.