Description
I propose we add fsharp_max_if_then_short_width
. Style guide update TBD
Slack conversation with @nojaf:
@dsyme: I'm wondering if there should be two settings
fsharp_max_if_then_short_width
andfsharp_max_if_then_else_short_width
. We kind of want short-if-then-else to only apply to functional code, not imperative code. Setting largefsharp_max_if_then_else_short_width
gives things likeif something then variable <- exprThe style guide should really be explicit that such imperative code should be multi-line, and
if .. then ...
is always imperative. Equally people sometimes prefer one lineif condition then fail()
@nojaf: Should that always be on multiple lines if there is no else branch?
@dsyme: I think having
fsharp_max_if_then_short_width
with default 0 sounds right to me@nojaf: I'll take a look at that.
@nojaf: So, a couple of things come to mind here:
You could have a nested structure without else branch
if a then b elif c
The code printing the if/then/else is a bit complex and there are some obscured parts that take F# 5 offset rules into account. It might be good to revisit maybe a bit more than just the split of the setting.
Can we detect imperative code from an AST point of view and should we act upon that?
Pros and Cons
The advantages of making this adjustment to Fantomas are more explicit formatting of some imperative code
The disadvantages of making this adjustment to Fantomas are not all cases of imperative code are covered
Examples
Please provide multiple examples (before and after scenarios) and explain what rules did apply to achieve the outcome.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
- I have read the Contribution Guidelines.
- I have searched both open and closed suggestions on this site and believe this is not a duplicate
Please tick all that apply:
- This is not a breaking change to Fantomas
- I or my company would be willing to help implement and/or test this
- This suggestion is part of the Microsoft style guide (please add a link to section if so)
- This suggestion is part of the G-Research style guide (please add a link to section if so)