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

Anonymous types in a DU inserts newlines #2621

Closed
1 of 3 tasks
ly29 opened this issue Nov 10, 2022 · 5 comments · Fixed by #2622
Closed
1 of 3 tasks

Anonymous types in a DU inserts newlines #2621

ly29 opened this issue Nov 10, 2022 · 5 comments · Fixed by #2622

Comments

@ly29
Copy link
Contributor

ly29 commented Nov 10, 2022

Issue created from fantomas-online

Code

type A =
    | A of int
    | B of {| B: int ; C : string; Karlar: byte ; Kalle: byte|}
    | C of string

Result

type A =
    | A of int
    | B of


            {| B: int
               C: string
               Karlar: byte
               Kalle: byte |}
    | C of string

Problem description

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

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-11-10T07:58:47Z - 573d273

Default Fantomas configuration

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

@ly29 ly29 changed the title <Insert meaningful title> Anonymous types in a DU inserts newlines Nov 10, 2022
@nojaf
Copy link
Contributor

nojaf commented Nov 10, 2022

Hello, thank you for reporting this issue.

I believe the problem is introduced around:

+> (opt sepColon so genIdent +> autoIndentAndNlnIfExpressionExceedsPageWidth t
|> optSingle (genTriviaFor SynField_IdentifierAndType) innerRange)

autoIndentAndNlnIfExpressionExceedsPageWidth t should only be considered when there is an named identifier present.

Changing this behaviour to:

    +> (match so with
        | None -> t
        | Some name -> genIdent name +> sepColon +> autoIndentAndNlnIfExpressionExceedsPageWidth t
        |> optSingle (genTriviaFor SynField_IdentifierAndType) innerRange)

probably does the trick.
Are you interested in submitting a PR for this?

@ly29
Copy link
Contributor Author

ly29 commented Nov 10, 2022

Probably tomorrow I can have a go

@ly29
Copy link
Contributor Author

ly29 commented Nov 10, 2022

Also thank you for your quick feedback!

@ly29
Copy link
Contributor Author

ly29 commented Nov 11, 2022

Yeah that does the trick, I will try submitting the PR tomorrow.

any guidance for where place the test and should there be more than one test for this fix?

@nojaf
Copy link
Contributor

nojaf commented Nov 11, 2022

I think adding a single test to src/Fantomas.Core.Tests/UnionTests.fs would suffice in this case.
Please take all our guidelines into account.
Many thanks!

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