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

Class type with long variable names results in invalid formatted F# code #841

Closed
Bobface opened this issue May 19, 2020 · 5 comments · Fixed by #843
Closed

Class type with long variable names results in invalid formatted F# code #841

Bobface opened this issue May 19, 2020 · 5 comments · Fixed by #843

Comments

@Bobface
Copy link
Contributor

Bobface commented May 19, 2020

Issue created from fantomas-online

The formatted result for the code below is invalid F# code: The variables in the result are missing a comma , at the end of their corresponding lines.

@nojaf I would like to work on a PR which implements the commas at the end of the lines. Let me know if you agree with this fix.

Edit: It seems like there is already a test in TypeDeclarationTests which checks for this behaviour:

[<Test>]
let ``long constructors should have parameters on separate lines`` () =
    formatSourceString false """type C (aVeryLongType : AVeryLongTypeThatYouNeedToUse, aSecondVeryLongType : AVeryLongTypeThatYouNeedToUse, aThirdVeryLongType : AVeryLongTypeThatYouNeedToUse) =
    member this.X = 42
"""  ({ config with SpaceBeforeClassConstructor = true })
    |> prepend newline
    |> should equal """
type C (
    aVeryLongType: AVeryLongTypeThatYouNeedToUse
    aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse
    aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse)
    =
    member this.X = 42
"""

However it also checks for the wrong result.

Code

type SomeType(looooooooooooooooooooooooong1: string, looooooooooooooooooooooooong2: string, looooooooooooooooooooooooong3: string -> string) =
    member this.SomeMethod () =
        "..."

Error

Fantomas was able to format the code but the result appears to be invalid F# code.
Please open an issue.

Formatted result:

type SomeType(
    looooooooooooooooooooooooong1: string
    looooooooooooooooooooooooong2: string
    looooooooooooooooooooooooong3: string -> string)
    =
    member this.SomeMethod() = "..."

Options

Fantomas Next - 4.0.0-alpha-001-1/1/1990

Name Value
IndentSpaceNum 4
PageWidth 120
SemicolonAtEndOfLine false
SpaceBeforeParameter true
SpaceBeforeLowercaseInvocation true
SpaceBeforeUppercaseInvocation false
SpaceBeforeClassConstructor false
SpaceBeforeMember false
SpaceBeforeColon false
SpaceAfterComma true
SpaceBeforeSemicolon false
SpaceAfterSemicolon true
IndentOnTryWith false
SpaceAroundDelimiter true
MaxIfThenElseShortWidth 40
MaxInfixOperatorExpression 50
MaxRecordWidth 40
MaxArrayOrListWidth 40
MaxLetBindingWidth 40
MultilineBlockBracketsOnSameColumn false
NewlineBetweenTypeDefinitionAndMembers false
KeepIfThenInSameLine false
StrictMode false
@knocte
Copy link
Contributor

knocte commented May 19, 2020

I think this is a regression introduced by this commit: ef2e6f3

@knocte
Copy link
Contributor

knocte commented May 19, 2020

The culprit of the regression is that the unit test is actually wrong, it's missing commas. This is something I noticed myself in G-Research coding guidelines and I fixed with a PR here:

G-Research/fsharp-formatting-conventions#1

@nojaf
Copy link
Contributor

nojaf commented May 19, 2020

Hey @Bobface and @knocte, good catch. I just copied that example from the G-Research style guide and missed the comma's.

We need them in this case, so @Bobface it would be great if you could work on a fix.
I'm guessing the fix will be changing sepNln here.
Not sure though, can't look into great detail now.

@Bobface
Copy link
Contributor Author

Bobface commented May 19, 2020

@nojaf Yep that one worked for the member tuples but not for the constructor tuples. Am currently looking into where the constructors tuples are implemented.

@nojaf
Copy link
Contributor

nojaf commented May 19, 2020

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.

3 participants