From 9b90b56a42d8f13b57538afe58ad7538e4eac40a Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Sat, 18 Feb 2023 11:32:20 -0500 Subject: [PATCH] Fixes command breaking with lambda in tuple, #2771 --- CHANGELOG.md | 5 +++++ src/Fantomas.Core.Tests/TupleTests.fs | 23 +++++++++++++++++++++++ src/Fantomas.Core/CodePrinter.fs | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cae9e095fe..d539dc161b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [5.2.2] - 2023-02-18 + +### Fixed +* Fixes comma breaking with lambda in tuple. [#2771](https://github.com/fsprojects/fantomas/issues/2771) + ## [5.2.1] - 2023-02-04 ### Fixed diff --git a/src/Fantomas.Core.Tests/TupleTests.fs b/src/Fantomas.Core.Tests/TupleTests.fs index 14f589215f..bd1901c0a4 100644 --- a/src/Fantomas.Core.Tests/TupleTests.fs +++ b/src/Fantomas.Core.Tests/TupleTests.fs @@ -397,3 +397,26 @@ let f x = () """ + +[] +let ``comma should not break with lambda as tuple, 2771`` () = + formatSourceString + false + """ +let shiftTimes localDate (start: Utc, duration) = + ZonedDate.create TimeZone.current localDate + |> Time.ZonedDate.startOf + |> fun dayStart -> start + dayStart.Duration - refDay.StartTime.Duration + , duration +""" + config + |> prepend newline + |> should + equal + """ +let shiftTimes localDate (start: Utc, duration) = + ZonedDate.create TimeZone.current localDate + |> Time.ZonedDate.startOf + |> fun dayStart -> start + dayStart.Duration - refDay.StartTime.Duration + , duration +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 566b9f6d08..06a407048f 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -1754,6 +1754,10 @@ let genTupleMultiline (node: ExprTupleNode) = match node.RightHandSide with | Expr.Lambda _ -> true | _ -> false + | Expr.SameInfixApps node -> + match List.last node.SubsequentExpressions with + | _, Expr.Lambda _ -> true + | _ -> false | _ -> false | _ -> false)