Add a directive to disable or modify formatting of full modules #197

Open
opened 2018-11-09 19:52:39 +01:00 by 5outh · 7 comments
5outh commented 2018-11-09 19:52:39 +01:00 (Migrated from github.com)

We currently have directives for disabling/modifying specific bindings (-- brittany-disable-next-binding / -- brittany-next-binding --columns=100, e.g.). Certain files either choke on brittany, or are written in a particular style and should be ignored by the process. In those cases, I'd love if there were a directive akin to:

-- brittany-disable

which ignores the entire module; and similarly -- brittany-modify or something that that effect for modifying brittany settings for all top-level bindings in a module.

This might seem weird since brittany works on a per-module basis, but this would be really nice when working with editor integrations and full-project formatting scripts, for example.

We currently have directives for disabling/modifying specific bindings (`-- brittany-disable-next-binding` / `-- brittany-next-binding --columns=100`, e.g.). Certain files either choke on brittany, or are written in a particular style and should be ignored by the process. In those cases, I'd love if there were a directive akin to: `-- brittany-disable` which ignores the entire module; and similarly `-- brittany-modify` or something that that effect for modifying brittany settings for all top-level bindings in a module. This might seem weird since `brittany` works on a per-module basis, but this would be really nice when working with editor integrations and full-project formatting scripts, for example.
lspitzner commented 2018-11-11 22:20:09 +01:00 (Migrated from github.com)

I think both functionalities are in a way supported already:

-- brittany --exactprint-only
stuff =  42
-- brittany --indent 4

stuff = do
    pure 42

otherstuff = do
    pure True

The former is based on the assumption that exactprint does its job correctly (the risk of that failing is really really low, in my experience). But both for making things more intuitive and prevent wasting cpu-cycles on calculating a complex hopefully-identity, we probably indeed want "brittany-disable-module" that produces input directly (and does nothing on --write-mode=inplace).

I think both functionalities are in a way supported already: ~~~~.hs -- brittany --exactprint-only stuff = 42 ~~~~ ~~~~.hs -- brittany --indent 4 stuff = do pure 42 otherstuff = do pure True ~~~~ The former is based on the assumption that exactprint does its job correctly (the risk of that failing is really really low, in my experience). But both for making things more intuitive and prevent wasting cpu-cycles on calculating a complex hopefully-identity, we probably indeed want "brittany-disable-module" that produces input directly (and does nothing on `--write-mode=inplace`).
eborden commented 2018-11-12 15:59:34 +01:00 (Migrated from github.com)

@lspitzner is there an FAQ that could be updated to include this information?

@lspitzner is there an FAQ that could be updated to include this information?
tfausak commented 2019-06-18 04:18:29 +02:00 (Migrated from github.com)

It seems like maybe the original issue is solved? But the inline config definitely should be documented. It's in the change log for 0.11 and in #136, but that's it.

It seems like maybe the original issue is solved? But the inline config definitely should be documented. It's in the change log for 0.11 and in #136, but that's it.
nuttycom commented 2020-09-30 03:36:09 +02:00 (Migrated from github.com)

Can anyone quickly say what the configuration looks like for this? I've tried every variant of -- brittany disable-formatting I can think of, but none of them seem to cause the file where this comment appears to be ignored.

Can anyone quickly say what the configuration looks like for this? I've tried every variant of `-- brittany disable-formatting` I can think of, but none of them seem to cause the file where this comment appears to be ignored.
tfausak commented 2020-09-30 13:51:25 +02:00 (Migrated from github.com)

I think you can use -- brittany --exactprint-only, although it still seems to format the module header.

/tmp> cat gh197.hs 
-- brittany --exactprint-only
module Main ( main ) where

main
  =
    putStrLn
      ugly

ugly
  = 'u'
    : 'g'
      : 'l'
        : 'y'
          : []

/tmp> brittany gh197.hs
-- brittany --exactprint-only
module Main
  ( main
  )
where

main
  =
    putStrLn
      ugly

ugly
  = 'u'
    : 'g'
      : 'l'
        : 'y'
          : []
I think you can use `-- brittany --exactprint-only`, although it still seems to format the module header. ``` sh /tmp> cat gh197.hs -- brittany --exactprint-only module Main ( main ) where main = putStrLn ugly ugly = 'u' : 'g' : 'l' : 'y' : [] /tmp> brittany gh197.hs -- brittany --exactprint-only module Main ( main ) where main = putStrLn ugly ugly = 'u' : 'g' : 'l' : 'y' : [] ```
nuttycom commented 2020-10-05 21:56:15 +02:00 (Migrated from github.com)

My hope was actually to have a way to avoid https://github.com/lspitzner/brittany/issues/242 so this isn't quite enough; I'd just like the whole file to be completely ignored. I guess the only way to do this is just to make sure that brittany never looks at the file in the first place?

My hope was actually to have a way to avoid https://github.com/lspitzner/brittany/issues/242 so this isn't quite enough; I'd just like the whole file to be completely ignored. I guess the only way to do this is just to make sure that brittany never looks at the file in the first place?
tfausak commented 2020-10-05 22:32:37 +02:00 (Migrated from github.com)

As far as I know, yeah that's the only way.

As far as I know, yeah that's the only way.
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#197
There is no content yet.