From 26db836bee9ad126ffe4b986e9f487297a8a302e Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 16 Jul 2019 20:43:27 +0200 Subject: [PATCH] Add parenthesis around lamba in tuple, fixes #450 --- src/Fantomas.Tests/Fantomas.Tests.fsproj | 3 ++- src/Fantomas.Tests/TupleTests.fs | 17 +++++++++++++++++ src/Fantomas/CodePrinter.fs | 6 +++++- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/Fantomas.Tests/TupleTests.fs diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index 07d5ef0dc2..945cdd45e1 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -1,4 +1,4 @@ - + 3.0.0-beta-001 @@ -51,6 +51,7 @@ + diff --git a/src/Fantomas.Tests/TupleTests.fs b/src/Fantomas.Tests/TupleTests.fs new file mode 100644 index 0000000000..376c74e16b --- /dev/null +++ b/src/Fantomas.Tests/TupleTests.fs @@ -0,0 +1,17 @@ +module Fantomas.Tests.TupleTests + +open NUnit.Framework +open FsUnit + +open Fantomas.Tests.TestHelper + +[] +let ``tuple with lamba should add parenthesis`` () = + formatSourceString false """ +let private carouselSample = + FunctionComponent.Of(fun _ -> + fragment [] [] + ,"CarouselSample") +""" config + |> should equal """let private carouselSample = FunctionComponent.Of((fun _ -> fragment [] []), "CarouselSample") +""" \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 9f0c6276be..4ea8f1699b 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -644,7 +644,11 @@ and genAnonRecordFieldName astContext (AnonRecordFieldName(s, e)) = and genTuple astContext es = atCurrentColumn (coli sepComma es (fun i -> if i = 0 then genExpr astContext else noIndentBreakNln astContext - |> addParenWhen (function |ElIf _ -> true |_ -> false) // "if .. then .. else" have precedence over "," + |> addParenWhen (fun e -> + match e with + |ElIf _ + | SynExpr.Lambda _ -> true + |_ -> false) // "if .. then .. else" have precedence over "," )) and genExpr astContext synExpr =