fsprojects / fantomas

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

Multiline secondary constructor #3037

Closed MangelMaxime closed 5 months ago

MangelMaxime commented 5 months ago

Issue created from fantomas-online

Code

type IntersectionOptions
    private
    (
        primary: bool,
        ?root: Element,
        ?rootMargin: string,
        ?threshold: ResizeArray<float>,
        ?triggerOnce: bool
    )
    =

    new(?root: Element,
        ?rootMargin: string,
        ?threshold: ResizeArray<float>,
        ?triggerOnce: bool) =

        IntersectionOptions(true)

    static member Test
        (
            ?root: Element,
            ?rootMargin: string,
            ?threshold: ResizeArray<float>,
            ?triggerOnce: bool
        )
        =
        failwith "Not implemented"

Result

type IntersectionOptions
    private
    (
        primary: bool,
        ?root: Element,
        ?rootMargin: string,
        ?threshold: ResizeArray<float>,
        ?triggerOnce: bool
    ) =

    new(?root: Element,
        ?rootMargin: string,
        ?threshold: ResizeArray<float>,
        ?triggerOnce: bool) =

        IntersectionOptions(true)

    static member Test
        (
            ?root: Element,
            ?rootMargin: string,
            ?threshold: ResizeArray<float>,
            ?triggerOnce: bool
        ) =
        failwith "Not implemented"

Problem description

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

The secondary constructors should follows the same indentation styles as the primary constructor and the member declaration.

type IntersectionOptions
    // ...
    =

    new
        (
            ?root: Element,
            ?rootMargin: string,
            ?threshold: ResizeArray<float>,
            ?triggerOnce: bool
        ) =

        IntersectionOptions(true)

    // ...

Extra information

Options

Fantomas main branch at 2024-01-11T10:58:46Z - d8f44dbe6c47bfb6371aed1dce9ee5227bf773c8

    { config with
                MaxLineLength = 80
                MultilineBracketStyle = stroustrup }

Did you know that you can ignore files when formatting by using a .fantomasignore file? PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.

nojaf commented 5 months ago

The current situation is that the formatting for implicit constructors is not influenced by the MultilineBracketStyle setting. So it gap is more with secondary constructors in general.

I'm open to implementing this feature, but I would like it to be clearly explained in the style guide. While I believe there's no need for extensive discussion on this matter, updating the guide on dotnet/docs could be beneficial in preemptively addressing any potential concerns from the community.

Could you send over a PR for the style guide?

MangelMaxime commented 5 months ago

I'm open to implementing this feature, but I would like it to be clearly explained in the style guide. While I believe there's no need for extensive discussion on this matter, updating the guide on dotnet/docs could be beneficial in preemptively addressing any potential concerns from the community.

Indeed, I think this case is cover by this section to be more precise this paragraph:

CleanShot 2024-01-11 at 16 22 11@2x

I can send a PR to add an exemple for secondary constructors.

nojaf commented 5 months ago

I can send a PR to add an exemple for secondary constructors.

Thanks!

nojaf commented 5 months ago

Available in https://www.nuget.org/packages/fantomas/6.3.0-alpha-007