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

Inconsistent styling when using Stroustrup, MaxRecordWidth and MultilineBlockBracketsOnSameColumn with or without member attach to record creation #2652

Closed
3 tasks
MangelMaxime opened this issue Dec 8, 2022 · 6 comments · Fixed by #2773
Assignees

Comments

@MangelMaxime
Copy link

Issue created from fantomas-online

Code

type NameStepFormValues = {
    FirstName: string
    LastName: string
}

type NameStepResult =
    {
        FirstName: FirstName.T
        LastName: LastName.T
    }

    member this.ToFormValues() : NameStepFormValues = {
        FirstName = FirstName.toString this.FirstName
        LastName = LastName.toString this.LastName
    }

Result

type NameStepFormValues = {
    FirstName: string
    LastName: string
}

type NameStepResult =
    {
        FirstName: FirstName.T
        LastName: LastName.T
    }

    member this.ToFormValues() : NameStepFormValues = {
        FirstName = FirstName.toString this.FirstName
        LastName = LastName.toString this.LastName
    }

Problem description

Please describe here the Fantomas problem you encountered.
Check out our Contribution Guidelines.

If user enable Stroustrup I think it should be applied everywhere and in the case of the member it should written with the additional with keyword to make the code valid.

type NameStepResult = {
        FirstName: FirstName.T
        LastName: LastName.T
    } with

    member this.ToFormValues() : NameStepFormValues = {
        FirstName = FirstName.toString this.FirstName
        LastName = LastName.toString this.LastName
    }

This is just to show the code, the placement of the with need to be reflected upon

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 main branch at 2022-12-03T22:59:05Z - 47c6ac6

    { config with
                MaxRecordWidth = 0
                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?

@dawedawe
Copy link
Member

dawedawe commented Dec 8, 2022

Hey Maxime, thanks for raising this issue.
CC'ing @josh-degraw in case he can help.

@josh-degraw
Copy link
Contributor

So initially this was an intentional exception due to AST limitations at the time, and we haven't yet reached a consensus on the best way to approach this style. I actually mentioned in the style guide discussion that I was personally in favor of using the Stroustrup style here with the with keyword, but since there are a few ways it could be formatted we might need to figure out exactly how we're going to format it.

@nojaf
Copy link
Contributor

nojaf commented Dec 9, 2022

Hello Maxime, the style guide does not recommend having the with keyword in the first place, which is why when a record type has members, it resolves to the Allman style to avoid having offset errors. This reasoning could be considered consistent and I could close this issue here and now.

Stroustrup is not part of the style guide so any new issue could always be closed on sight. I encourage you to engage in fsharp/fslang-design#706 to change this.

Overall I would be ok with having the with keyword but your proposal is ambiguous and should not be discussed here.

@corsinpfister
Copy link

Just wanted to mention that Stroustrup is now part of the style guide (see Multiline bracket formatting styles). Moreover, an exception to the rule discouraging the with keyword has been added for the Stroustrup style, see the section Formatting record declarations

// ✔️ OK
type PostalAddress = {
    Address: string
    City: string
    Zip: string
} with
    member x.ZipAndCity = $"{x.Zip} {x.City}"

@josh-degraw
Copy link
Contributor

josh-degraw commented Feb 15, 2023

@corsinpfister Thank you for the reminder, I actually added those updates to the style guide myself, in part due to this issue, but I had actually forgotten to add the changes to bring the style in line in fantomas itself here. We'll try and get this included in the next major release 👍🏻

@nojaf
Copy link
Contributor

nojaf commented Apr 13, 2023

Available in v6.

@nojaf nojaf closed this as completed Apr 13, 2023
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.

5 participants