fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
758 stars 189 forks source link

[Feature request] Make newline experience consistent across match branches #3083

Closed Lanayx closed 1 month ago

Lanayx commented 2 months ago

I propose we add configuration (or make default) for having consistent indentation of match cases. So: 1) If all branches can placed in the same line, do that 2) If any branch must be moved to new line (due to length or multiline), move all branches to the new line

Pros and Cons

The advantages of making this adjustment to Fantomas are - more consistent code look and feel.

The disadvantages of making this adjustment to Fantomas are - reformatting existing code base (could be fixed by disabling feature by default)

Examples

From Oxpecker Existing formatting:

match result with
| Ok _ -> return! ctx.Write <| Created()
| Error error ->
    env.Logger.LogError(error)
    return! ctx.Write <| BadRequest {| Error = error |}

Proposed formatting:

match result with
| Ok _ -> 
    return! ctx.Write <| Created()
| Error error ->
    env.Logger.LogError(error)
    return! ctx.Write <| BadRequest {| Error = error |}

Extra information

Estimated cost (XS, S, M, L, XL, XXL): M

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:

nojaf commented 1 month ago

This falls under what-are-we-not-looking-for.

You are in luck, however, that this was discussed at some point in the style guide: https://github.com/fsharp/fslang-design/issues/650.

I would accept a PR for this.