diff --git a/.paket/paket.exe b/.paket/paket.exe index bb20c62401..d6de423dfa 100644 Binary files a/.paket/paket.exe and b/.paket/paket.exe differ diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 01c772bd16..5c3d4e1dc4 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,8 @@ +#### 2.7.2 - xx-05-2018 +* Wrong indentation of `else` after comment [#241](https://github.com/dungpa/fantomas/issues/241) +* Change Content to None [#238](https://github.com/dungpa/fantomas/issues/238) +* Formatting of code with a pipe and a lambda expression [#211](https://github.com/dungpa/fantomas/issues/211) + #### 2.7.1 - 03-05-2018 * Hotfix for runtime problem when using dotnet cli tool diff --git a/src/Fantomas.Cmd/AssemblyInfo.fs b/src/Fantomas.Cmd/AssemblyInfo.fs index 05bab5848d..2916688149 100644 --- a/src/Fantomas.Cmd/AssemblyInfo.fs +++ b/src/Fantomas.Cmd/AssemblyInfo.fs @@ -5,13 +5,13 @@ open System.Reflection [] [] [] -[] -[] +[] +[] do () module internal AssemblyVersionInformation = let [] AssemblyTitle = "Fantomas" let [] AssemblyProduct = "Fantomas" let [] AssemblyDescription = "Source code formatter for F#" - let [] AssemblyVersion = "2.7.1" - let [] AssemblyFileVersion = "2.7.1" + let [] AssemblyVersion = "2.7.2" + let [] AssemblyFileVersion = "2.7.2" diff --git a/src/Fantomas.Cmd/Fantomas.Cmd.fsproj b/src/Fantomas.Cmd/Fantomas.Cmd.fsproj index e38e9331c9..453d49caf0 100644 --- a/src/Fantomas.Cmd/Fantomas.Cmd.fsproj +++ b/src/Fantomas.Cmd/Fantomas.Cmd.fsproj @@ -3,7 +3,7 @@ Exe netcoreapp2.0;net45 - 2.7.1 + 2.7.2 dotnet-fantomas diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index 2a07f9b736..ac456296b0 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -2,7 +2,7 @@ netcoreapp2.0;net45 - 2.7.1 + 2.7.2 FS0988 diff --git a/src/Fantomas.Tests/PipingTests.fs b/src/Fantomas.Tests/PipingTests.fs index a0d22e0e7c..8835e8125b 100644 --- a/src/Fantomas.Tests/PipingTests.fs +++ b/src/Fantomas.Tests/PipingTests.fs @@ -62,4 +62,19 @@ let runAll() = |> Async.Parallel |> Async.RunSynchronously |> ignore -""" \ No newline at end of file +""" + +[] +let ``pipe and multiline should put pipe on newline`` () = + formatSourceString false """ +let prefetchImages = + [ playerOImage; playerXImage ] + |> List.map (fun img -> link [ Rel "prefetch"; Href img ])""" config + |> prepend newline + |> should equal """ +let prefetchImages = + [ playerOImage; playerXImage ] + |> List.map (fun img -> + link [ Rel "prefetch" + Href img ]) +""" diff --git a/src/Fantomas/AssemblyInfo.fs b/src/Fantomas/AssemblyInfo.fs index 05a95cbe9b..6b1b8daa7d 100644 --- a/src/Fantomas/AssemblyInfo.fs +++ b/src/Fantomas/AssemblyInfo.fs @@ -7,8 +7,8 @@ open System.Runtime.CompilerServices [] [] [] -[] -[] +[] +[] do () module internal AssemblyVersionInformation = @@ -16,5 +16,5 @@ module internal AssemblyVersionInformation = let [] AssemblyTitle = "FantomasLib" let [] AssemblyProduct = "Fantomas" let [] AssemblyDescription = "Source code formatter for F#" - let [] AssemblyVersion = "2.7.1" - let [] AssemblyFileVersion = "2.7.1" + let [] AssemblyVersion = "2.7.2" + let [] AssemblyFileVersion = "2.7.2" diff --git a/src/Fantomas/CodeFormatter.fsx b/src/Fantomas/CodeFormatter.fsx index 2ed4f6d478..ba4ead1508 100644 --- a/src/Fantomas/CodeFormatter.fsx +++ b/src/Fantomas/CodeFormatter.fsx @@ -30,8 +30,9 @@ fsi.AddPrinter (fun (p : pos) -> p.ToString()) fsi.AddPrinter (fun (r : range) -> r.ToString()) let input = """ -module Tmp -let f (arg : 'T) = (^T : (member Value : string) arg) +let prefetchImages = + [ playerOImage; playerXImage ] + |> List.map (fun img -> link [ Rel "prefetch"; Href img ]) """ formatSrc input;; diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 2dbbe51ca7..df4f63e0ce 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -658,14 +658,20 @@ and genLetOrUseList astContext = function | _ -> sepNone /// When 'hasNewLine' is set, the operator is forced to be in a new line -and genInfixApps astContext hasNewLine = function +and genInfixApps astContext hasNewLine synExprs = + match synExprs with + | (s, e)::es when(hasNewLine) -> + (sepNln -- s +> sepSpace +> genExpr astContext e) + +> genInfixApps astContext (hasNewLine || checkNewLine e es) es + | (s, e)::es when(NoSpaceInfixOps.Contains s) -> + (!- s +> autoNln (genExpr astContext e)) + +> genInfixApps astContext (hasNewLine || checkNewLine e es) es + | (s, e)::es when (NoBreakInfixOps.Contains s) -> + (sepSpace -- s +> sepSpace +> genExpr astContext e) + +> genInfixApps astContext (hasNewLine || checkNewLine e es) es | (s, e)::es -> - (ifElse hasNewLine (sepNln -- s +> sepSpace +> genExpr astContext e) - (ifElse (NoSpaceInfixOps.Contains s) (!- s +> autoNln (genExpr astContext e)) - (ifElse (NoBreakInfixOps.Contains s) (sepSpace -- s +> sepSpace +> genExpr astContext e) - (sepSpace +> autoNln (!- s +> sepSpace +> genExpr astContext e))))) + (sepSpace +> autoNln (!- s +> sepSpace +> genExpr astContext e)) +> genInfixApps astContext (hasNewLine || checkNewLine e es) es - | [] -> sepNone /// Use in indexed set and get only diff --git a/src/Fantomas/Fantomas.fsproj b/src/Fantomas/Fantomas.fsproj index 0a32316390..5fcc7752ed 100644 --- a/src/Fantomas/Fantomas.fsproj +++ b/src/Fantomas/Fantomas.fsproj @@ -2,7 +2,7 @@ netstandard2.0;net45 - 2.7.1 + 2.7.2 diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index e09654146b..993fa75ce8 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -666,7 +666,8 @@ let (|PrefixApp|_|) = function Some((|OpName|) s, e2) | _ -> None -let private (|InfixApp|_|) = function +let private (|InfixApp|_|) synExpr = + match synExpr with | SynExpr.App(_, true, Var "::", Tuple [e1; e2], _) -> Some("::", e1, e2) // Range operators need special treatments, so we exclude them here @@ -681,7 +682,8 @@ let (|TernaryApp|_|) = function /// We should return the whole triple for convenient check let (|InfixApps|_|) e = - let rec loop = function + let rec loop synExpr = + match synExpr with | InfixApp(s, e, e2) -> let (e1, es) = loop e (e1, (s, e2)::es) diff --git a/src/Fantomas/SourceTransformer.fs b/src/Fantomas/SourceTransformer.fs index d316976980..e58000ee46 100644 --- a/src/Fantomas/SourceTransformer.fs +++ b/src/Fantomas/SourceTransformer.fs @@ -15,7 +15,8 @@ module List = /// Check whether an expression should be broken into multiple lines. /// Notice that order of patterns matters due to non-disjoint property. -let rec multiline = function +let rec multiline synExpr = + match synExpr with | ConstExpr _ | NullExpr | OptVar _ @@ -87,9 +88,17 @@ let rec multiline = function // Default mode is single-line | _ -> false -let checkNewLine e es = - match es with - | (s, _) :: _ :: _ -> NewLineInfixOps.Contains s +let checkNewLine e es = + match (e, es) with + | _, [s, infixExpr] when NewLineInfixOps.Contains s -> + (* + If s is a single infix (f.e. |> ) + Only multiline if the whole expression is multiline + or the next expression is multiline + See test ``pipe and multiline should put pipe on newline`` + *) + multiline e || multiline infixExpr + | _, (s, _) :: _ :: _ -> NewLineInfixOps.Contains s | _ -> multiline e /// Check if the expression already has surrounding parentheses