Skip to content

Commit

Permalink
Check if we just wrote a DotLambda before deciding on space before pa…
Browse files Browse the repository at this point in the history
…rens, fix 3050 (#3051)

* fix an idempotency issue with dot lambdas, 3050

* add changelog entry

* fix warning from analysers

* fix by using Oak knowledge and altering the config for the dotlambda construction

* instead of using a potentially wrong config for argument nodes, check if the node.Expr is an AppSingleParenArg and just be always atomic in that case when writing the FunctionExpr

* release notes for 6.3.5
  • Loading branch information
dawedawe authored May 30, 2024
1 parent da71271 commit cb7a8e0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
72 changes: 72 additions & 0 deletions src/Fantomas.Core.Tests/DotLambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,75 @@ let c = _.foo().Length
"""
let c = _.foo().Length
"""

[<Test>]
let ``idempotency problem when _.Property shorthand, 3050`` () =
formatSourceString
"""
"ABC" |> _.ToLower()
"""
{ config with
SpaceBeforeUppercaseInvocation = true }
|> prepend newline
|> should
equal
"""
"ABC" |> _.ToLower()
"""

[<Test>]
let ``idempotency problem when _.property shorthand lowercase, 3050`` () =
formatSourceString
"""
"ABC" |> _.toLower()
"""
{ config with
SpaceBeforeLowercaseInvocation = true }
|> prepend newline
|> should
equal
"""
"ABC" |> _.toLower()
"""

[<Test>]
let ``idempotency problem when _.property shorthand quoted, 3050`` () =
formatSourceString
"""
"ABC" |> _.``to Lower``()
"""
{ config with
SpaceBeforeLowercaseInvocation = true }
|> prepend newline
|> should
equal
"""
"ABC" |> _.``to Lower``()
"""

[<Test>]
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 ())
"""
7 changes: 6 additions & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit cb7a8e0

Please sign in to comment.