From 515500869fd1b39be20d756e46775cb9881c8d99 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Sat, 16 May 2020 15:18:23 +0200 Subject: [PATCH] Add brace before indentation. Fixes #835 (#836) --- .../ComputationExpressionTests.fs | 48 +++++++++++++++++++ .../FormatConfigJsonConfigurationFileTests.fs | 3 +- src/Fantomas/CodePrinter.fs | 8 ++-- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/Fantomas.Tests/ComputationExpressionTests.fs b/src/Fantomas.Tests/ComputationExpressionTests.fs index 0cfc13126b..864b19404e 100644 --- a/src/Fantomas.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Tests/ComputationExpressionTests.fs @@ -280,6 +280,54 @@ let tests = testList "tests" [ test "test" { Expect.equal true true "unexpected" } ] """ +[] +let ``multiline computation expression with SynExpr.App identifier, 835`` () = + formatSourceString false """let meh = + create [] { + // foo + // bar + return 42 + }""" config + |> prepend newline + |> should equal """ +let meh = + create [] { + // foo + // bar + return 42 + } +""" + +[] +let ``multiline computation expression with SynExpr.App identifier and multiple expressions`` () = + formatSourceString false """ +let private validateLocation = + createValidatorFor () { + validate (fun l -> l.Id) [ isNotEmptyGuid ] + validate (fun l -> l.Name) + [ isNotEmpty + hasMinLengthOf 3 ] + validate (fun l -> fst l.Location) [ isValidLatitude ] + validate (fun l -> snd l.Location) [ isValidLongitude ] + validate (fun l -> l.Price) [ isGreaterThan 0. ] + validate (fun l -> l.Date) [ isNotMinDate ] + validate (fun l -> l.Creator) [ isNotEmpty ] + } +""" config + |> prepend newline + |> should equal """ +let private validateLocation = + createValidatorFor () { + validate (fun l -> l.Id) [ isNotEmptyGuid ] + validate (fun l -> l.Name) [ isNotEmpty; hasMinLengthOf 3 ] + validate (fun l -> fst l.Location) [ isValidLatitude ] + validate (fun l -> snd l.Location) [ isValidLongitude ] + validate (fun l -> l.Price) [ isGreaterThan 0. ] + validate (fun l -> l.Date) [ isNotMinDate ] + validate (fun l -> l.Creator) [ isNotEmpty ] + } +""" + [] let ``new line after multiline let bang, 819`` () = formatSourceString false """ diff --git a/src/Fantomas.Tests/FormatConfigJsonConfigurationFileTests.fs b/src/Fantomas.Tests/FormatConfigJsonConfigurationFileTests.fs index aa4c22000e..2fdd0edd69 100644 --- a/src/Fantomas.Tests/FormatConfigJsonConfigurationFileTests.fs +++ b/src/Fantomas.Tests/FormatConfigJsonConfigurationFileTests.fs @@ -1,6 +1,5 @@ module Fantomas.Tests.FormatConfigJsonConfigurationFileTests -open System open Fantomas open Fantomas.FormatConfig open NUnit.Framework @@ -8,7 +7,7 @@ open System.IO open Fantomas.Tests.TestHelper [] -let private ConfigFileName ="fantomas-config.json" +let private ConfigFileName = "fantomas-config.json" let private mkConfig subFolder config = let json = Config.configToJson config diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index c74a02495a..b7ae344ec7 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1204,11 +1204,9 @@ and genExpr astContext synExpr = atCurrentColumn (genExpr astContext e +> colPre sepSpace sepSpace es (fun e -> - indent - +> appNlnFun e - (indentIfNeeded - +> onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace) - +> genExpr astContext e) + onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace) + +> indent + +> appNlnFun e (indentIfNeeded +> genExpr astContext e) +> unindent)) | TypeApp(e, ts) -> genExpr astContext e -- "<" +> col sepComma ts (genType astContext false) -- ">"