brittany
brittany copied to clipboard
Ignore some patterns
I was going through the documentation but couldn't find a way to add options to ignore certain kinds of patterns. In my use case, I have a type like
query'
:: Query
Schema
'[]
'[ "anId" ::: 'NotNull 'PGtext
, "anName" ::: 'Null 'PGtext
, "anDesc" ::: 'Null 'PGtext
, "anPairStatus" ::: 'NotNull (PG (Enumerated PairStatus))
, "anCreated" ::: 'NotNull 'PGtimetz
, "anUpdated" ::: 'Null 'PGtimetz
]
While I'd like Brittany to leave as-is. However, formatting this with Brittany causes it to become:
query'
:: Query
Schema
'[]
'["anId" ::: 'NotNull 'PGtext, "anName" ::: 'Null 'PGtext, "anDesc"
:::
'Null
'PGtext, "anPairStatus" ::: 'NotNull (PG (Enumerated PairStatus)), "anCreated"
:::
'NotNull
'PGtimetz, "anUpdated" ::: 'Null 'PGtimetz]
Which is rather unreadable.
Is there a way I could make Brittany ignore some cases? If so, can you please point me to the relevant documentation/resources where I can understand it?
brittany version 0.11.0.0
Copyright (C) 2016-2018 Lennart Spitzner
There is NO WARRANTY, to the extent permitted by law.
You can disable Brittany on a per-binding basis with this comment:
-- brittany-disable-next-binding
https://github.com/lspitzner/brittany/blob/4cb3b96f073fb391d765a38bb757c369f050e079/ChangeLog.md#01100----may-2018
@tfausak Thanks! That works. Is there a way for me to disable some "patterns" universally, though?
I'm not sure what you mean by "patterns". It seems to me that the root issue here is that Brittany has trouble formatting type-level lists. Is that accurate?
@tfausak that is correct. What I meant by patterns were some sort of regexes that could define an expression I'd like Brittany to ignore.
Ah, I see. You want to be able to tell Brittany something like "don't format type-level lists" or "don't format expressions that look like this regex."
@asheshambasta what other patterns would you want to have excluded? I am asking because type-signature overhaul is planned anyway, so if that is the central pain point, I'd rather focus on that than spending time on writing elaborate workarounds.
@tfausak Yes, something like that would be more than enough. @lspitzner Its a little hard for me to come up with an exhaustive list of patterns I'd like excluded. If we can expose some sort of a configuration parameter that lets you specify a list of regexes for brittany to ignore, that will be what I'm speaking of here.
I agree with @lspitzner: I'd rather have Brittany format things properly than come up with complicated workarounds. Also regular expressions aren't powerful enough to express Haskell code that you'd want to ignore. For example, what would you say for type level lists: /'\[.+\]/
? That's got all kinds of problems.
We definitely need some xpath-equivalent on the haskell syntax tree. :D
I see your points. And yes, for me exclusion of a pattern is only necessary where the formatting via Brittany doesn't make sense. Otherwise, I also agree: I'd be happier with Brittany formatting things properly rather than have it ignore some sections.
I would also not like to see complex flags making their way into the config. Frankly the config is already too complicated for my own taste. I'd rather see some configurations be shed than adding more. I'd hope that -- brittany-disable-next-binding
would be sufficient for handling areas where users do not agree with brittany
's formatting.
And this discussion reminds me:
selectByIds cids = toFullEvents (toList cids) =<< execSelect selEvents
-- brittany-disable-next-binding
where selEvents = proc () -> do
t@(cid', _, _, _) <- eventImgJoin -< ()
restrict -< cid' ^. unCId . to (in_ cids')
returnA -< t
cids' = constant . _unCId <$> cids
I'm using something similar to ask brittany to ignore array-syntactical blocks since it causes failure. From what I see (I've only briefly played with this), is Brittany also supposed to ignore the function in the where block? It doesn't seem to, at least at present.
I think the comment would need to go after the where
. For example:
{-# language Arrows #-}
selectByIds cids =
toFullEvents (toList cids) =<< execSelect selEvents
where
-- brittany-disable-next-binding
selEvents = proc () -> do
t@(cid', _, _, _) <- eventImgJoin -< ()
restrict -< cid' ^. unCId . to (in_ cids')
returnA -< t
cids' = constant . _unCId <$> cids
However that still fails because arrows aren't supported (#24).
@tfausak yes, this is one case that I find the most problematic. Adding the ignore clause on the top level function is the only thing that works. However, that means Brittany ignores the entire function, which means you need to manually format that function.
(I'll read this is as another vote for working on #109, too.)