fantomas icon indicating copy to clipboard operation
fantomas copied to clipboard

Add line break before start of argument list

Open alanlomeli opened this issue 3 years ago • 4 comments

Issue created from fantomas-online

Code

type FieldNotFoundException<'T>(obj:'T, field:string, specLink:string) =
    inherit SwaggerSchemaParseException(
        sprintf "Object MUST contain field `%s` (See %s for more details).\nObject:%A"
            field specLink obj)

Result

type FieldNotFoundException<'T>(obj: 'T, field: string, specLink: string) =
    inherit SwaggerSchemaParseException(sprintf
                                            "Object MUST contain field `%s` (See %s for more details).\nObject:%A"
                                            field
                                            specLink
                                            obj)

Problem description

After F# 6 indentation relaxations, we can now improve indent consistency by adding a line break before the argument. Check out our Contribution Guidelines.

Extra information

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

Options

Fantomas master branch at 2022-07-04T06:38:00Z - 26d45cf5a75ae44efd2bc7b3d80c660c77024a51

    { config with
                SpaceBeforeParameter = false
                SpaceBeforeLowercaseInvocation = false
                MultilineBlockBracketsOnSameColumn = true
                ExperimentalStroustrupStyle = true }

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

alanlomeli avatar Jul 06 '22 00:07 alanlomeli

@yisusalanpng the problem also occurs using the default settings, so the settings you have listed don't have an influence on the problem. It is best to leave them out when reporting them. Thank you for the report.

nojaf avatar Jul 06 '22 08:07 nojaf

@yisusalanpng @sergey-tihon I've raise this with the style guide, https://github.com/fsharp/fslang-design/issues/693. Just to be on the safe side.

nojaf avatar Jul 08 '22 15:07 nojaf

@yisusalanpng I'm not really sure what I was going to write down as additional feedback. So I'll add some generic pointers:

Almost every function in CodePrinter takes the Context record as the last argument. In F# you can omit this parameter when defining a function as the partial application will kick in.

Take the genIdent (ident: Ident) = !-ident.idText function for example. In full this would be genIdent (ident: Ident) ctx = !-ident.idText ctx. The definition of (!-) is image

Notice the string -> Context -> Context type signature. This function returns a Context. And take a string and Context argument. If we only pass in a string (like !- "hey"), this will return a function that takes Context and returns a Context. Because the (+>) combines two functions, it is very similar to >>. We can usually drop the last Context and return Context -> Context.

For example

let f (ctx:Context) : Context = !- "f" ctx // Adds WriterEvent.Write "f" to the Context
let g (ctx:Context) : Context = !- "g" ctx // Adds WriterEvent.Write "f" to the Context

let combined (ctx:Context) = g (f ctx) // first call `f`, then `g`. 
// The result will be a new Context with two WriterEvents

can be written as

let f : Context -> Context = !- "f"
let g : Context -> Context = !- "g"
let combined : Context -> Context = f +> g

Notice that f, g and combined have not been executed. Only when invoking combined with a Context argument, will the function return a new Context with two events.

let ctxAfter = combined Context.Default
Assert.True (ctxAfter.WriterEvents.Length = 2)

Maybe at some point, we should add some new unit tests in https://github.com/fsprojects/fantomas/blob/7d8b638cf25172100d60caad8be839d70d63b40c/src/Fantomas.Core.Tests/ContextTests.fs to better illustrate some of the functions used in CodePrinter.

(PS: @dawedawe how clear is it to you what is happening in CodePrinter?)

nojaf avatar Jul 11 '22 16:07 nojaf

(PS: @dawedawe how clear is it to you what is happening in CodePrinter?)

To use words to answer, I'd say it's mostly clear. To use numbers, I'd say it's ~85% clear. Sometimes I'm struggling with the size of some functions/APs/expressions, which make it hard for me to have a mental model of what's going on. But that has already improved in the last couple of months. Partly due to refactoring, partly due to my growing experience and exposure to the code base.

dawedawe avatar Jul 11 '22 21:07 dawedawe

This is available in the 5.1 series.

nojaf avatar Dec 05 '22 23:12 nojaf