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

Incorrect Stroustrup indentation with let binding for anonymous record with expression #2508

Closed
3 tasks done
josh-degraw opened this issue Sep 16, 2022 · 2 comments · Fixed by #2515
Closed
3 tasks done
Labels
bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet! stroustrup

Comments

@josh-degraw
Copy link
Contributor

Sorry to be one of the new voices of issues post v5 🙃

Issue created from fantomas-online

Code

let fooDto =
    {| otherDto with
        TextFilters =
            criteria.Meta.TextFilter
            |> Option.map (fun f -> f.Filters)
            |> Option.map (List.map (sprintf "~%s~"))
            |> Option.toObj
    |}

Result

let fooDto = {| otherDto with
    TextFilters =
        criteria.Meta.TextFilter
        |> Option.map (fun f -> f.Filters)
        |> Option.map (List.map (sprintf "~%s~"))
        |> Option.toObj
|}

Problem description

See above examples for the issue.

Also, if I add a comment or newline to try and preserve formatting, it results in this:

let fooDto =
// Comment
{| otherDto with
    TextFilters =
        criteria.Meta.TextFilter
        |> Option.map (fun f -> f.Filters)
        |> Option.map (List.map (sprintf "~%s~"))
        |> Option.toObj
|}

I think the root cause of this might be related to that of #2501.

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-09-16T18:11:37Z - 5182588

    { config with
                MultilineBlockBracketsOnSameColumn = true
                ExperimentalStroustrupStyle = 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 Sep 17, 2022

Sorry to be one of the new voices of issues post v5 🙃

No worries, someone had to do it 😅.

This one is rather easy to fix I think.
If you look at

let (|StroustrupStyleExpr|_|) (isStroustrupStyleEnabled: bool) (e: SynExpr) =
if not isStroustrupStyleEnabled then
None
else
match e with
// { foo with Bar = bar }
| SynExpr.Record(copyInfo = Some _) -> None
| SynExpr.Record _
| SynExpr.AnonRecd _
// task { ... }
| SynExpr.App (ExprAtomicFlag.NonAtomic, false, SynExpr.Ident _, SynExpr.ComputationExpr _, _)
| ArrayOrList _ -> Some e
| _ -> None

We ignore normal update records as a stroustrup expression: | SynExpr.Record(copyInfo = Some _) -> None.
We should be able to ignore these as well for SynExpr.AnonRecd(copyInfo = Some _). (ref)

Are you up for it?

@nojaf nojaf added bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet! labels Sep 17, 2022
@josh-degraw
Copy link
Contributor Author

Are you up for it?
Yeah I'll try and tackle it this weekend if I can!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet! stroustrup
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants