Comments (4)
Related: #1787
I resorted to the suggestion to use a comment to force a newline, not exactly pretty =/
from fantomas.
So short answer here is that at this point, this is actually a feature, not a bug: there's a specific handling for if the infix operators are the same. If guess this is mainly there to treat pipe-like operations the same but it doesn't account for situations like this where there are several similar but different operations like these.
If this behavior is unwanted the best way to work around it for now is probably by utilizing fsharp_max_infix_operator_expression
.
If that is not sufficient for your use case, please feel free to open another issue if you'd like to suggest a new feature to handle this differently.
from fantomas.
Reducing fsharp_max_infix_operator_expression
causes too many other unwanted changes in my code. Also, it doesn't catch the case where the operator arguments are sufficiently short.
I think this can be solved by #988 (comment):
I think this may be solved by Fantomas knowing about operator precedence.
Quasi algorithm:
- If line is too long, find lowest precedence operator and break on that (break on all operators with the same precedence)
- If some of the broken lines are still too long, find the next lowest precedence operator(s) in those lines and break on those, but indent as demonstrated in this issue
Do this recursively, of course.
In summary, I think this can be solved by Fantomas considering operator precedence. Instead of breaking chains on identical operators as you describe, break on operators of equal precedence. The operator precedence rules for F# are AFAIK well-defined (also for custom operators) and could be hardcoded in Fantomas.
from fantomas.
I've been running into this same issue. Just to add some additional examples:
When using |>>
as a generic map operator and mixing it with |>
, this code:
let test (x: int) =
x
|> computationOne
|> computationTwo
|>> Option.map ((+) 3)
|>> Option.toValidOr "Problem"
becomes
let test (x: int) =
x |> computationOne |> computationTwo
|>> Option.map ((+) 3)
|>> Option.toValidOr "Problem"
Which, in my opinion, is much less readable.
Similarly, applicative-style expressions are affected, with:
let result =
create
<!> validate 1
<*> validate 2
<*> validate 3
<*> validate 4
<*> validate 5
<*> validate 6
which is fine as-is, becoming
let result =
create <!> validate 1
<*> validate 2
<*> validate 3
<*> validate 4
<*> validate 5
<*> validate 6
Setting fsharp_max_infix_operator_expression
to a lower number isn't really an option for me because it affects non-pipeline-like expressions. I, too, will likely resort to using an //
to force a line break, but it's less than ideal and adds noise.
from fantomas.
Related Issues (20)
- Unable to format F# 8 extended interpolated strings with curly braces HOT 3
- Move editor config to library rather than tool HOT 6
- "Incomplete declaration of a static construct" which the F# compiler accepts HOT 2
- Multiline secondary constructor HOT 4
- Equals sign should only be on same line if last tuple is multiline HOT 2
- Return type should go on next line
- Invalid F# code after formatting HOT 1
- Formatting removes necessary additional closing brackets for multiline interpolated strings HOT 1
- Fantomas reports an error when formatting interpolated string with tripple quotes HOT 7
- Idempotency problem when _.Property shorthand
- Regression: Stroustrup bracket style in anonymous record type parameter is not respected
- HashDirective before closing `]`
- Long parameter attribute gives weird line break before type annotation
- Fantomas corrupts an explicit constructor with `then` clause HOT 2
- FormatASTAsync loses single quotes for characters HOT 4
- Regression: An empty line or comment at the end of a list breaks Stroustrup formatting HOT 2
- `SpaceBeforeUppercaseInvocation` corrupts underscore lambda invocation HOT 1
- Non needed parentheses are added around lambda call from tuple/members HOT 3
- [Feature request] Make newline experience consistent across match branches HOT 1
- Make Fantomas AOT compatible HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fantomas.