Skip to content

[Feature request] fsharp_max_if_then_short_width #2299

Open
@dsyme

Description

@dsyme

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 and fsharp_max_if_then_else_short_width. We kind of want short-if-then-else to only apply to functional code, not imperative code. Setting large fsharp_max_if_then_else_short_width gives things like

    if something then variable <- expr

The 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 line if 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:

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions