fsprojects / fantomas

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

Idempotency problem when formatting NUnit Assert.That #1740

Open mschlaipfer opened 3 years ago

mschlaipfer commented 3 years ago

Issue created from fantomas-online

Original code

Assert.That(
    Assert.Throws<System.Exception>(fun () -> FooFooFooFooFooFoo.BarBar.dodododo filesfiles [] outoutout |> ignore)
        .Message,
    Is.EqualTo(message)
)

Formatted code

Assert.That(
    Assert.Throws<System.Exception>
        (fun () ->
            FooFooFooFooFooFoo.BarBar.dodododo filesfiles [] outoutout
            |> ignore)
        .Message,
    Is.EqualTo(message)
)

Reformatted code

Assert.That(
    Assert.Throws<System.Exception>
        (fun () ->
            FooFooFooFooFooFoo.BarBar.dodododo filesfiles [] outoutout
            |> ignore)
            .Message,
    Is.EqualTo(message)
)

Problem description

Fantomas was not able to produce the same code after reformatting the result.

Extra information

Options

Fantomas Master at 05/21/2021 11:35:53 - acd47bd9c4fe77e7604cc94f74ab5200e99a600f

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?

nojaf commented 3 years ago

Hello Matthias, thank you for reporting this bug. I believe the AST of the code changed after formatting due to the extra newline after (fun () ->. In short, I believe Fantomas is adding a new line where it cannot do this to stay valid.

I believe the result should more be something like

Assert.That(
    Assert.Throws<System.Exception>(fun () ->
        FooFooFooFooFooFoo.BarBar.dodododo 
            filesfiles 
            [] 
            outoutout
        |> ignore)
        .Message,
    Is.EqualTo(message)
)

Would you be interested in submitting a PR for this?

mschlaipfer commented 3 years ago

Hi, thanks for the confirmation. I don't really have cycles right now, unfortunately.