diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f7dd2ef3..f957a1d03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 6.3.5 - 2024-05-30 + +### Fixed +* Idempotency problem when _.Property shorthand. [#3050](https://github.com/fsprojects/fantomas/issues/3050) + ## 6.3.4 - 2024-04-16 ### Fixed diff --git a/src/Fantomas.Core.Tests/DotLambdaTests.fs b/src/Fantomas.Core.Tests/DotLambdaTests.fs index 376a4b92a..45285c3e3 100644 --- a/src/Fantomas.Core.Tests/DotLambdaTests.fs +++ b/src/Fantomas.Core.Tests/DotLambdaTests.fs @@ -59,3 +59,75 @@ let c = _.foo().Length """ let c = _.foo().Length """ + +[] +let ``idempotency problem when _.Property shorthand, 3050`` () = + formatSourceString + """ +"ABC" |> _.ToLower() +""" + { config with + SpaceBeforeUppercaseInvocation = true } + |> prepend newline + |> should + equal + """ +"ABC" |> _.ToLower() +""" + +[] +let ``idempotency problem when _.property shorthand lowercase, 3050`` () = + formatSourceString + """ +"ABC" |> _.toLower() +""" + { config with + SpaceBeforeLowercaseInvocation = true } + |> prepend newline + |> should + equal + """ +"ABC" |> _.toLower() +""" + +[] +let ``idempotency problem when _.property shorthand quoted, 3050`` () = + formatSourceString + """ +"ABC" |> _.``to Lower``() +""" + { config with + SpaceBeforeLowercaseInvocation = true } + |> prepend newline + |> should + equal + """ +"ABC" |> _.``to Lower``() +""" + +[] +let ``idempotency problem when _.Property shorthand with app arg, 3050`` () = + formatSourceString + """ +let Meh () = 1 + +type Bar() = + member this.Foo(v:int):int = v + 1 + +let b = Bar() +b |> _.Foo(Meh ()) +""" + { config with + SpaceBeforeUppercaseInvocation = true } + |> prepend newline + |> should + equal + """ +let Meh () = 1 + +type Bar() = + member this.Foo(v: int) : int = v + 1 + +let b = Bar () +b |> _.Foo(Meh ()) +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 2491ef4f1..658f5fcdd 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -1553,9 +1553,14 @@ let genExpr (e: Expr) = | Expr.IndexFromEnd node -> !- "^" +> genExpr node.Expr |> genNode node | Expr.Typar node -> genSingleTextNode node | Expr.DotLambda node -> + let genDotLambdaExpr expr = + match expr with + | Expr.AppSingleParenArg p -> genExpr p.FunctionExpr +> genExpr p.ArgExpr // be always atomic, see 3050 + | _ -> genExpr expr + genSingleTextNode node.Underscore +> genSingleTextNode node.Dot - +> genExpr node.Expr + +> genDotLambdaExpr node.Expr |> genNode node | Expr.BeginEnd node -> let short =