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

Update constructor formatting to match MS Style guide #1359

Closed
3 tasks
cmeeren opened this issue Jan 11, 2021 · 3 comments · Fixed by #1366
Closed
3 tasks

Update constructor formatting to match MS Style guide #1359

cmeeren opened this issue Jan 11, 2021 · 3 comments · Fixed by #1366

Comments

@cmeeren
Copy link
Contributor

cmeeren commented Jan 11, 2021

Issue created from fantomas-online

Code

This is how it's formatted with AlternativeLongMemberDefinitions = true:

type SomeVeryLongTypeNameWithConstructor
    (
        aVeryLongType: AVeryLongTypeThatYouNeedToUse,
        aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse,
        aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse
    )
    =
    class
    end

Result

This is how it's formatted with AlternativeLongMemberDefinitions = false (the current default):

type SomeVeryLongTypeNameWithConstructor(aVeryLongType: AVeryLongTypeThatYouNeedToUse,
                                         aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse,
                                         aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) =
    class
    end

Problem description

This is a violation of the "avoid name-sensitive alignment" clause of the F# code formatting guidelines.

Se also the F# code formatting guidelines, section Place parameters on a new line for long definitions. It demonstrates how this concrete case should be formatted:

type TC
    (
        aVeryLongCtorParam: AVeryLongTypeThatYouNeedToUse,
        aSecondVeryLongCtorParam: AVeryLongTypeThatYouNeedToUse,
        aThirdVeryLongCtorParam: AVeryLongTypeThatYouNeedToUse
    ) =
    // ... the body of the class follows

Based on this, I suggest that AlternativeLongMemberDefinitions should be true by default.

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

Default Fantomas configuration

@nojaf
Copy link
Contributor

nojaf commented Jan 11, 2021

The setting should not be changed or impacted in any way here.
The default style for constructors should be updated to match the MS style guide.
The rule of thumb is that is that the default Fantomas settings should adhere to the MS guide.

AlternativeLongMemberDefinitions tailors specifically to the GR guide.
The only remaining difference between the guides (at the time of writing) is the location of the = sign.
MS puts it after the ), while GR places it on a new line.

The existing way Fantomas formats it does not adhere to either style and that is the bug to me.

@cmeeren
Copy link
Contributor Author

cmeeren commented Jan 11, 2021

The setting should not be changed or impacted in any way here.
The default style for constructors should be updated to match the MS style guide.

Makes sense 👍

MS puts it after the ), while GR places it on a new line.

Actually, the official guide is inconsistent about this particular point (at least in the case of there being a return type annotation): dotnet/docs#22296

The existing way Fantomas formats it does not adhere to either style and that is the bug to me.

I agree.

@nojaf
Copy link
Contributor

nojaf commented Jan 11, 2021

Thanks for starting the conversation at dotnet/docs.

@nojaf nojaf changed the title Make AlternativeLongMemberDefinitions true by default Update constructor formatting to match MS Style guide Jan 15, 2021
nojaf added a commit to nojaf/fantomas that referenced this issue Jan 15, 2021
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.

2 participants