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

Aesthetics of long members in a type declaration #1362

Closed
3 tasks
Smaug123 opened this issue Jan 12, 2021 · 4 comments · Fixed by #1368
Closed
3 tasks

Aesthetics of long members in a type declaration #1362

Smaug123 opened this issue Jan 12, 2021 · 4 comments · Fixed by #1368

Comments

@Smaug123
Copy link
Contributor

Issue created from fantomas-online

Code

type IFoo =
    abstract Blah : foo : string -> bar : string -> baz : string -> int

Result

type IFoo =
    abstract Blah: foo:string
     -> bar:string -> baz:string -> int

Problem description

I set the line length very short so as to trigger this.

This is purely stylistic, but I would prefer to follow a different rule: if a member declaration has to be split over multiple lines, then all the arguments should be split onto their own line.

type IFoo =
    abstract Blah :
        foo : string ->
        bar : string ->
        baz : string ->
        int

I recognise that this change should be accompanied by a change to the G-Research style guidelines, which are currently silent on the matter. If you think this is a reasonable choice, I'll raise an appropriate PR to https://github.com/G-Research/fsharp-formatting-conventions/ .

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 01/09/2021 08:58:25 - ca42f0d

    { config with
                MaxLineLength = 60 }

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

@Smaug123
Copy link
Contributor Author

Relatedly, by the way, it would be nice to be clear what happens in the following case:

type IFoo =
    abstract Bar :
        [<Path "bar">] bar : string
        * [<Path "baz">] baz : string
        -> Task<Foo>

This arises from using RestEase, for example. I don't have a strong preference for how this is formatted, except that currently Fantomas indents a very long way. It puts the * symbols underneath the [ of the preceding [<Path>], which I'd say is correct (though my preference is not strong) - but it puts that [ on the same line as abstract Bar, with the result that it's sadly very far over to the right:

type IFoo =
    abstract Bar : [<Path "bar">] bar : string
                   * [<Path "baz"] baz : string
                   -> Task<Foo>

@nojaf
Copy link
Contributor

nojaf commented Jan 15, 2021

Hello Patrick, this seems doable I think.
In the second example, I would expect that the arrow is after the tuple.

type IFoo =
    abstract Blah : 
        foo : string -> 
        bar : string -> 
        baz : string -> 
        int

type IFoo =
    abstract Bar : 
        [<Path "bar">] bar : string 
        * [<Path "baz">] baz : string -> 
        Task<Foo>

I've also raised this in the MS style guide: dotnet/docs#22368

@Smaug123
Copy link
Contributor Author

Smaug123 commented Jan 15, 2021

That seems reasonable; I think we don't have strong preferences about where the arrows go, as long as they're not all forced to be indented a very long way. Could you let us know what the easiest answer is from Fantomas's point of view, because I don't want to write down some hard requirement which we don't actually care very much about? I'll raise a corresponding GResearch/fsharp-formatting-conventions PR.

@nojaf
Copy link
Contributor

nojaf commented Jan 15, 2021

Could you let us know what the easiest answer is from Fantomas's point of view

Yep, I'll let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants