Closed pkamenarsky closed 5 years ago
It is intentional: this was my request. My logic here is that if there are several methods, then they should be separated by newlines and it's odd to "glue" the first method with instance header by omitting a newline there. Feel free to argue otherwise, we might change it later.
@mrkkrp The explanation makes sense, except that if we were to apply it consistently, we would do the same after where
in a function definition. Most existing code doesn't do that - whether in a function or in instance declarations.
Maybe related: https://github.com/tweag/ormolu/issues/74.
A single instance ...
line looks like a deriving instance
or an empty instance at a quick glance to me.
A compromise would be to not collapse empty lines present in the original layout or conversely, introduce new ones where there were none before. This would allow the programmer to group semantic constructs as they see fit, which I'd argue is paramount for readability.
My plan currently is to return to more subtle stylistic questions after initial release and making sure we can format all existing code. So, this one (and others tagged "style") is lower-priority for now.
Agreed with the OP, seeing code like this is kinda weird:
-- | A category was found.
data CSRCategory
= CSRCategory
{ csrcInfo :: CCategoryInfo
, csrcDescription :: CMarkdown
}
deriving (Show, Generic)
instance A.ToJSON CSRCategory where
toJSON = A.genericToJSON jsonOptions
instance ToSchema CSRCategory where
declareNamedSchema = genericDeclareNamedSchema schemaOptions
Perhaps the leading newline should be inserted only sometimes:
What makes this odd, is that it makes long list of these hard to read, e.g.
data Foo a = Foo a
data Boo a = Boo a
instance Functor Foo where
fmap f foo = undefined
instance Applicative Foo where
pure x = undefined
f <*> foo = undefined
instance Functor Boo where
fmap f foo = undefined
instance Applicative Boo where
pure x = undefined
f <*> foo = undefined
Omitting the blank line in all cases after the instance head makes sense.
gets formatted to
Is this intentional? This is of course subjective, but the extra newline makes it look like
instance A.FromJSON Service where
is a separate thing fromparseJSON
, which it is not.