Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional parentheses are introduced when match is piped #1698

Closed
3 tasks
nojaf opened this issue May 5, 2021 · 0 comments · Fixed by #1699
Closed
3 tasks

Additional parentheses are introduced when match is piped #1698

nojaf opened this issue May 5, 2021 · 0 comments · Fixed by #1699

Comments

@nojaf
Copy link
Contributor

nojaf commented May 5, 2021

Issue created from fantomas-online

Code

  let select px =
    match px with
    | Shared.Foo _ -> "foo"
    | Shared.LongerFoobarFoo -> "lf"
    | Shared.Barry -> "barry"
    |> List.singleton
    |> instr "ziggy"

Result

let select px =
  (match px with
   | Shared.Foo _ -> "foo"
   | Shared.LongerFoobarFoo -> "lf"
   | Shared.Barry -> "barry")
  |> List.singleton
  |> instr "ziggy"

Problem description

In this scenario the parenthesis are not necessary.
They would be in case the last clause was multiline.

Like

let select px =
  match px with
  | Shared.Foo _ -> "foo"
  | Shared.LongerFoobarFoo -> "lf"
  | Shared.Barry -> 
    // foo
    "barry"
  |> List.singleton
  |> instr "ziggy"
  
 // would lead to
 
 let select px =
  match px with
  | Shared.Foo _ -> "foo"
  | Shared.LongerFoobarFoo -> "lf"
  | Shared.Barry ->
    // foo
    "barry" |> List.singleton |> instr "ziggy"

Not sure, what the best way would be to deal with this.
This is hard to detect from the SynExpr.App point of view.

So that is why the parenthesis are added in the first place.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas Master at 05/01/2021 14:37:19 - d8e76d4

    { config with
                IndentSize = 2 }

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

nojaf added a commit that referenced this issue May 8, 2021
* Don't add parenthesis if last clause is single line. Fixes #1698

* Verify last clause was multiline via writer events.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant