Configuration for minimal diffs (VCS friendly) #316
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#316
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 think many big projects try to minimize the amount of conflicts they have when merging, rebasing, etc etc, so the main goal is to create as little diff as possible.
One very important aspect of this is: never align identifiers based on other identifiers (except where it is necessary, e.g. for
let
)... because the layout changes too easily on code changes increasing the diff. Also see e.g. https://github.com/input-output-hk/adrestia/wiki/Coding-Standards#avoid-variable-length-indentationThere might be other things to do or avoid. Does anyone have ideas for an ultimate config for this?
I typically use this as a starting point:
I tried it and it leads to weird formatting wrt
let
andin
. And there's also a bug in the list formatting.Config
Before
After
There's a lot to unpack there. Can you identify separate issues specifically?
1
why not
More concise, wastes less space: again, aligning is a non-goal for this configuration.
2
This is the worst imo, it should be:
3
Same here
Should be
4
Aligning lists should be configurable, so that:
becomes
I don't think having one element per line really helps readability here. It's excessive.
5
The second item of the list is indented further, this looks like a bug.
Another instance of excessive newlining:
Before
After:
This is unreadable.
Thanks for taking the time to split all these out! Some of these look like bugs. Others of them look like things that could be controlled via configuration.
I personally prefer the way Brittany formats expressions like this currently. Once you bump over the line length each operator goes on its own line. It looks like you'd prefer a "paragraph fill" mode that puts as many parts of the expression on one line before breaking. Is that correct?
In this case I think Brittany is doing the right thing. If the layout is not supposed to depend on the length of any identifiers, adding a newline after
let
and indenting is the only thing it can reasonably do. Otherwise the layout will depend on the length oflet
. (In other words, everything would have to be indented four spaces rather than what the indentation is set at.)I agree with you on this one. I've never understood why Brittany puts a newline immediately after
in
. Sounds like a bug!This is similar to the last one. Seems like Brittany should try to put some tokens on the same line as
else
even when the whole expression is over the line length. It's unclear to me if the entire conditional expression should be collapsed as well.There is already an issue for this one: #302.
Agreed! Looks like another bug. Could be related to
do
notation somehow? See #296.Unfortunately getting this one right requires knowing the precedence of the operators. See #79 for details.
There are a couple other "omnibus" issues that are similar to this one: #33 and #278.
The problem is... it's a waste of vertical space and quickly becomes excessive, turning a line that exceeds the desired length by 2 chars into 10 line breaks. So yes, readability isn't always about increasing verbosity. It's also about making scrolling over code easier and spotting things. The more line breaks, the harder scrolling through code becomes, because everything is so noisy.
I believe if the indenting is at least 4 spaces, then brittany can infer that it doesn't need a newline after
=
.I think this is very easy. The problem is that we're still trying to do layouting while we should just do indenting and careful newlining. If we only do the latter, this won't really be a problem. That's the entire point of this ticket and VCS friendly formatting: minimal changes, no layouting.
It sounds like you may want a different tool entirely. Have you tried Ormolu? https://github.com/tweag/ormolu
Yes and it's neither configurable, nor pleasant.