Ignore some patterns #208
Labels
No Label
blocked: dependency
blocked: info-needed
bug
duplicate
enhancement
fixed in HEAD
help wanted
hs:arrows
hs:brackets
hs:classes
hs:comments
hs:do-notation
hs:guards
hs:lists
hs:operators
hs:patterns
hs:records
hs:types
invalid
language extension support
layouting
needs confirmation
priority: high
priority: low
question
revisit before next release
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: hexagoxel/brittany#208
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
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
While I'd like Brittany to leave as-is. However, formatting this with Brittany causes it to become:
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?
You can disable Brittany on a per-binding basis with this comment:
4cb3b96f07/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 withbrittany
's formatting.And this discussion reminds me:
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: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.)