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

Unexpected newline added before let bang #1932

Closed
3 tasks
nojaf opened this issue Oct 29, 2021 · 3 comments · Fixed by #2100
Closed
3 tasks

Unexpected newline added before let bang #1932

nojaf opened this issue Oct 29, 2021 · 3 comments · Fixed by #2100

Comments

@nojaf
Copy link
Contributor

nojaf commented Oct 29, 2021

Issue created from fantomas-online

Code

                promise {
                    setItems [||]
                    setSelectedItem None
                    setFetchingItems true
                    let! items = Api.fetchItems partNumber
                    setItems items
                    items |> Array.tryHead |> setSelectedItem
                    setFetchingItems false

                    Seq.tryHead items
                    |> Option.iter (Some >> setSelectedItem)
                }
                |> Promise.start

Result

promise {
    setItems [||]
    setSelectedItem None
    setFetchingItems true

    let! items = Api.fetchItems partNumber
    setItems items
    items |> Array.tryHead |> setSelectedItem
    setFetchingItems false

    Seq.tryHead items
    |> Option.iter (Some >> setSelectedItem)
}
|> Promise.start

Problem description

There should not be a newline added by let! items = .

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 4.6 branch at 10/27/2021 20:15:01 - 95833f5

Default Fantomas configuration

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

@knocte
Copy link
Contributor

knocte commented Feb 8, 2022

AFAIU this should be marked as bug(stylistic) instead of bug(soundness)?

@ribeirotomas1904
Copy link
Contributor

I will try to solve this one

@nojaf
Copy link
Contributor Author

nojaf commented Feb 13, 2022

Hello @ribeirotomas1904, thank you for your interest.

This one is a bit trickier to solve, I believe a first step might be to revisit:

let rec (|CompExprBody|_|) expr =
match expr with
| SynExpr.LetOrUse (_, _, _, CompExprBody _, _)
| SynExpr.LetOrUseBang _
| SynExpr.Sequential (_, _, _, SynExpr.YieldOrReturn _, _)
| SynExpr.Sequential (_, _, _, SynExpr.LetOrUse _, _)
| SynExpr.Sequential (_, _, _, SynExpr.LetOrUseBang _, _) -> Some(collectComputationExpressionStatements expr id)
| _ -> None

I believe this active pattern is a bit too strict and should be more something like:

let rec (|CompExprBody|_|) expr =
    match expr with
    | SynExpr.LetOrUse (_, _, _, CompExprBody _, _)
    | SynExpr.LetOrUseBang _
    | SynExpr.Sequential _ -> Some(collectComputationExpressionStatements expr id)
    | _ -> None

Because of this change, you might need to update

| Paren (lpr, e, rpr, _pr) ->
match e with
| LetOrUses _
| Sequential (_, LetOrUses _, _) ->
sepOpenTFor lpr
+> atCurrentColumn (genExpr astContext e)
+> sepCloseTFor rpr
| _ ->
sepOpenTFor lpr
+> genExpr astContext e
+> sepCloseTFor rpr

accordingly to:

        | Paren (lpr, e, rpr, _pr) ->
            match e with
            | LetOrUses _
            | Sequential _ ->
                sepOpenTFor lpr
                +> atCurrentColumn (genExpr astContext e)
                +> sepCloseTFor rpr
            | _ ->
                sepOpenTFor lpr
                +> genExpr astContext e
                +> sepCloseTFor rpr

I hope this helps.

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.

3 participants