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

Inline anonymous record type declarations do not respect MultilineBlockBracketsOnSameColumn setting #2412

Closed
3 tasks
isaacabraham opened this issue Aug 6, 2022 · 2 comments

Comments

@isaacabraham
Copy link

Issue created from fantomas-online

Code

type Foo =
    {
        Bar : {| X : string; Y : int; A : string; B : string |}
        Baz : int
        Blip : string
    }

Result

type Foo =
    {
        Bar: {| X: string
                Y: int
                A: string
                B: string |}
        Baz: int
        Blip: string
    }

Problem description

I would expect the above code to be formatted as follows:

type Foo =
    {
        Bar:
            {|
                X: string
                Y: int
                A: string
                B: string
            |}
        Baz: int
        Blip: string
    }

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 master branch at 2022-08-06T07:12:17Z - c1d5250

    { config with
                MultilineBlockBracketsOnSameColumn = true }

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

@nojaf
Copy link
Contributor

nojaf commented Aug 8, 2022

Hello, I believe this is a duplicate of #1167.
SynType.AnonRecd would need an alternative path based on the setting.

Around

| TAnonRecord (isStruct, fields) ->
let smallExpression =
ifElse isStruct !- "struct " sepNone
+> sepOpenAnonRecd
+> col sepSemi fields (genAnonRecordFieldType astContext)
+> sepCloseAnonRecd
let longExpression =
ifElse isStruct !- "struct " sepNone
+> sepOpenAnonRecd
+> atCurrentColumn (col sepNln fields (genAnonRecordFieldType astContext))
+> sepCloseAnonRecd
fun (ctx: Context) ->
let size = getRecordSize ctx fields
isSmallExpression size smallExpression longExpression ctx

longExpression should be something similar to

let longExpression =
ifAlignBrackets
(genMultilineAnonRecordAlignBrackets isStruct fields copyInfo astContext)
(genMultilineAnonRecord isStruct fields copyInfo astContext)

Note that you cannot just re-use the function because the AST is different.
You would need to create genMultilineAnonRecordType and genMultilineAnonRecordTypeAlignBrackets accordingly. Unit tests can be placed in MultilineBlockBracketsOnSameColumnRecordTests.fs.

Are you interested in submitting a PR for this?

@isaacabraham
Copy link
Author

Sorry, yes. Closing as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants