fsprojects / fantomas

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

Fluent API with comments breaks code #331

Closed isaacabraham closed 5 years ago

isaacabraham commented 6 years ago

This code (taken from the Program.fs file in the Server project of https://github.com/Zaid-Ajaj/tabula-rasa)

Log.Logger <- 
  LoggerConfiguration() 
    // Suave.SerilogExtensions has native destructuring mechanism
    // this helps Serilog deserialize the fsharp types like unions/records
    .Destructure.FSharpTypes()
    // use package Serilog.Sinks.Console  
    // https://github.com/serilog/serilog-sinks-console
    .WriteTo.Console() 
    // add more sinks etc.
    .CreateLogger()

gets rewritten as:

Log.Logger <- LoggerConfiguration().// Suave.SerilogExtensions has native destructuring mechanism
                                    // this helps Serilog deserialize the fsharp types like unions/records
                                    Destructure.FSharpTypes().// use package Serilog.Sinks.Console  
                                                              // https://github.com/serilog/serilog-sinks-console
                                                              WriteTo.Console().// add more sinks etc.
                                                                                CreateLogger()

which is actually invalid F# and does not build.

Using standard fantomas settings with 120 char line length.

In fact, fluent APIs in general don't get very well formatted e.g.:

Log.Logger <-
    LoggerConfiguration()
        .Destructure.FSharpTypes()
        .WriteTo.Console()
        .CreateLogger()

becomes

Log.Logger <- LoggerConfiguration().Destructure.FSharpTypes().WriteTo.Console().CreateLogger()

Although this is more aesthetic.

nojaf commented 5 years ago

Fixed in 2.9.1, see online.