Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 211 #257

Merged
merged 7 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .paket/paket.exe
Binary file not shown.
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Cmd/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("Fantomas")>]
[<assembly: AssemblyProductAttribute("Fantomas")>]
[<assembly: AssemblyDescriptionAttribute("Source code formatter for F#")>]
[<assembly: AssemblyVersionAttribute("2.7.1")>]
[<assembly: AssemblyFileVersionAttribute("2.7.1")>]
[<assembly: AssemblyVersionAttribute("2.7.2")>]
[<assembly: AssemblyFileVersionAttribute("2.7.2")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "Fantomas"
let [<Literal>] AssemblyProduct = "Fantomas"
let [<Literal>] AssemblyDescription = "Source code formatter for F#"
let [<Literal>] AssemblyVersion = "2.7.1"
let [<Literal>] AssemblyFileVersion = "2.7.1"
let [<Literal>] AssemblyVersion = "2.7.2"
let [<Literal>] AssemblyFileVersion = "2.7.2"
2 changes: 1 addition & 1 deletion src/Fantomas.Cmd/Fantomas.Cmd.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;net45</TargetFrameworks>
<Version>2.7.1</Version>
<Version>2.7.2</Version>
<AssemblyName>dotnet-fantomas</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net45</TargetFrameworks>
<Version>2.7.1</Version>
<Version>2.7.2</Version>
<NoWarn>FS0988</NoWarn>
</PropertyGroup>
<ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion src/Fantomas.Tests/PipingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ let runAll() =
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
"""
"""

[<Test>]
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 ])
"""
8 changes: 4 additions & 4 deletions src/Fantomas/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ open System.Runtime.CompilerServices
[<assembly: AssemblyTitleAttribute("FantomasLib")>]
[<assembly: AssemblyProductAttribute("Fantomas")>]
[<assembly: AssemblyDescriptionAttribute("Source code formatter for F#")>]
[<assembly: AssemblyVersionAttribute("2.7.1")>]
[<assembly: AssemblyFileVersionAttribute("2.7.1")>]
[<assembly: AssemblyVersionAttribute("2.7.2")>]
[<assembly: AssemblyFileVersionAttribute("2.7.2")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] InternalsVisibleTo = "Fantomas.Tests"
let [<Literal>] AssemblyTitle = "FantomasLib"
let [<Literal>] AssemblyProduct = "Fantomas"
let [<Literal>] AssemblyDescription = "Source code formatter for F#"
let [<Literal>] AssemblyVersion = "2.7.1"
let [<Literal>] AssemblyFileVersion = "2.7.1"
let [<Literal>] AssemblyVersion = "2.7.2"
let [<Literal>] AssemblyFileVersion = "2.7.2"
5 changes: 3 additions & 2 deletions src/Fantomas/CodeFormatter.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;;
Expand Down
18 changes: 12 additions & 6 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal but parentheses are not needed in when clauses.

(!- 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
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/Fantomas.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>2.7.1</Version>
<Version>2.7.2</Version>
</PropertyGroup>
<ItemGroup>
<None Include="paket.references" />
Expand Down
6 changes: 4 additions & 2 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions src/Fantomas/SourceTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down Expand Up @@ -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
Expand Down