From 0323229feadcd78d334ba4767df7200b8dedaddf Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Thu, 1 Jul 2021 20:08:47 +0200 Subject: [PATCH] Control semicolon in pattern list via setting. Fixes #1793. (#1801) --- src/Fantomas.Tests/RecordTests.fs | 88 +++++++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 28 +++++----- 2 files changed, 104 insertions(+), 12 deletions(-) diff --git a/src/Fantomas.Tests/RecordTests.fs b/src/Fantomas.Tests/RecordTests.fs index eca22b9f5b..8e323953ed 100644 --- a/src/Fantomas.Tests/RecordTests.fs +++ b/src/Fantomas.Tests/RecordTests.fs @@ -1444,3 +1444,91 @@ let x = { actual = 6 y = x } let y = { actual = 6; y = x } """ + +[] +let ``multiline records in pattern list should not have semicolon by default, 1793`` () = + formatSourceString + false + """ +match entities with +| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3" + Type = Elephant } ] -> () +| _ -> () +""" + config + |> prepend newline + |> should + equal + """ +match entities with +| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3" + Type = Elephant } ] -> () +| _ -> () +""" + +[] +let ``multiline records in pattern list should have semicolon`` () = + formatSourceString + false + """ +match entities with +| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3" + Type = Elephant } ] -> () +| _ -> () +""" + { config with + SemicolonAtEndOfLine = true } + |> prepend newline + |> should + equal + """ +match entities with +| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"; + Type = Elephant }; + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"; + Type = Elephant }; + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"; + Type = Elephant } ] -> () +| _ -> () +""" + +[] +let ``multiline records in pattern array should not have semicolon by default`` () = + formatSourceString + false + """ +match entities with +| [| { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3" + Type = Elephant } |] -> () +| _ -> () +""" + config + |> prepend newline + |> should + equal + """ +match entities with +| [| { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2" + Type = Elephant } + { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3" + Type = Elephant } |] -> () +| _ -> () +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index b2fc3a668c..f72620091d 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -4863,20 +4863,24 @@ and genPat astContext pat = expressionFitsOnRestOfLine short long | PatSeq (PatList, ps) -> - ifElse - ps.IsEmpty - (sepOpenLFixed +> sepCloseLFixed) - (sepOpenL - +> atCurrentColumn (colAutoNlnSkip0 sepSemi ps (genPat astContext)) - +> sepCloseL) + let genPats = + let short = + colAutoNlnSkip0 sepSemi ps (genPat astContext) + + let long = col sepSemiNln ps (genPat astContext) + expressionFitsOnRestOfLine short long + + ifElse ps.IsEmpty (sepOpenLFixed +> sepCloseLFixed) (sepOpenL +> atCurrentColumn genPats +> sepCloseL) | PatSeq (PatArray, ps) -> - ifElse - ps.IsEmpty - (sepOpenAFixed +> sepCloseAFixed) - (sepOpenA - +> atCurrentColumn (colAutoNlnSkip0 sepSemi ps (genPat astContext)) - +> sepCloseA) + let genPats = + let short = + colAutoNlnSkip0 sepSemi ps (genPat astContext) + + let long = col sepSemiNln ps (genPat astContext) + expressionFitsOnRestOfLine short long + + ifElse ps.IsEmpty (sepOpenAFixed +> sepCloseAFixed) (sepOpenA +> atCurrentColumn genPats +> sepCloseA) | PatRecord xs -> let smallRecordExpr =