Ignore some patterns #208

Open
opened 2018-12-22 12:25:10 +01:00 by asheshambasta · 15 comments
asheshambasta commented 2018-12-22 12:25:10 +01:00 (Migrated from github.com)

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.
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 ```haskell 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: ```haskell 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. ```
tfausak commented 2018-12-22 14:28:58 +01:00 (Migrated from github.com)

You can disable Brittany on a per-binding basis with this comment:

-- brittany-disable-next-binding

4cb3b96f07/ChangeLog.md (01100----may-2018)

You can disable Brittany on a per-binding basis with this comment: ``` hs -- brittany-disable-next-binding ``` https://github.com/lspitzner/brittany/blob/4cb3b96f073fb391d765a38bb757c369f050e079/ChangeLog.md#01100----may-2018
asheshambasta commented 2018-12-24 15:16:55 +01:00 (Migrated from github.com)

@tfausak Thanks! That works.
Is there a way for me to disable some "patterns" universally, though?

@tfausak Thanks! That works. Is there a way for me to disable some "patterns" universally, though?
tfausak commented 2019-06-18 03:55:07 +02:00 (Migrated from github.com)

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?

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?
asheshambasta commented 2019-06-18 11:51:05 +02:00 (Migrated from github.com)

@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.

@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.
tfausak commented 2019-06-18 14:03:46 +02:00 (Migrated from github.com)

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."

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."
lspitzner commented 2019-06-18 15:48:08 +02:00 (Migrated from github.com)

@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.

@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.
asheshambasta commented 2019-06-18 16:05:46 +02:00 (Migrated from github.com)

@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.

@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.
tfausak commented 2019-06-18 16:15:28 +02:00 (Migrated from github.com)

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.

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.
lspitzner commented 2019-06-18 16:19:37 +02:00 (Migrated from github.com)

We definitely need some xpath-equivalent on the haskell syntax tree. :D

We definitely need some xpath-equivalent on the haskell syntax tree. :D
asheshambasta commented 2019-06-18 16:29:31 +02:00 (Migrated from github.com)

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 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.
eborden commented 2019-06-19 06:03:32 +02:00 (Migrated from github.com)

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.

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.
asheshambasta commented 2019-06-19 14:07:14 +02:00 (Migrated from github.com)

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.

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.
tfausak commented 2019-06-19 14:56:40 +02:00 (Migrated from github.com)

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).

I think the comment would need to go after the `where`. For example: ``` hs {-# 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).
asheshambasta commented 2019-06-19 14:59:38 +02:00 (Migrated from github.com)

@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.

@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.
lspitzner commented 2019-06-23 17:04:22 +02:00 (Migrated from github.com)

(I'll read this is as another vote for working on #109, too.)

(I'll read this is as another vote for working on #109, too.)
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#208
There is no content yet.