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

Don't add extra newline between attribute and let binding #620

Merged
merged 2 commits into from
Jan 6, 2020
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
31 changes: 31 additions & 0 deletions src/Fantomas.Tests/AttributeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,35 @@ module C =
module C =
[<DllImport("")>]
extern IntPtr f()
"""

[<Test>]
let ``keep single newline between attribute and let binding, 611`` () =
formatSourceString false """
open System
open Library

[<EntryPoint>]

let main argv =
printfn "Nice command-line arguments! Here's what JSON.NET has to say about them:" argv
|> Array.map getJsonNetJson |> Array.iter (printfn "%s")
0 // return an integer exit code
""" ({ config with
SpaceAfterComma = false
SpaceAfterSemicolon = false
SpaceAroundDelimiter = false
SpaceBeforeArgument = false })
|> prepend newline
|> should equal """
open System
open Library

[<EntryPoint>]

let main argv =
printfn "Nice command-line arguments! Here's what JSON.NET has to say about them:" argv
|> Array.map getJsonNetJson
|> Array.iter(printfn "%s")
0 // return an integer exit code
"""
17 changes: 2 additions & 15 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ and genAttributes astContext (ats: SynAttributes) =
let dontAddNewline =
TriviaHelpers.``has content after that ends with``
(fun t -> t.Range = a.Range)
(function | Directive(_) -> true | _ -> false)
(function | Directive(_) | Newline -> true | _ -> false)
ctx.Trivia
let chain =
acc +>
Expand All @@ -421,20 +421,6 @@ and genAttributes astContext (ats: SynAttributes) =
chain ctx
) sepNone

// col sepNln ats
// (fun a -> col sepNln a.Attributes (genAttribute astContext)
// |> genTrivia a.Range)
// let genTriviaAttributeList (f: Context -> Context) =
// Seq.foldBack (fun (attr: SynAttributeList) (acc: Context -> Context) -> acc |> (genTrivia attr.Range)) ats f
//
// (ats
// |> List.collect (fun a -> a.Attributes)
// |> Seq.groupBy (fun at -> at.Range.StartLine)
// |> Seq.map snd
// |> Seq.toList
// |> fun ats' -> (colPost sepNln sepNln ats' (genAttributesCore astContext)))
// |> genTriviaAttributeList

and genPreXmlDoc (PreXmlDoc lines) ctx =
if ctx.Config.StrictMode then
colPost sepNln sepNln lines (sprintf "///%s" >> (!-)) ctx
Expand Down Expand Up @@ -529,6 +515,7 @@ and genLetBinding astContext pref b =
genPreXmlDoc px
+> ifElse astContext.IsFirstChild (genAttributes astContext ats -- pref)
(!- pref +> genOnelinerAttributes astContext ats)
+> dumpAndContinue
+> opt sepSpace ao genAccess
+> ifElse isMutable (!- "mutable ") sepNone +> ifElse isInline (!- "inline ") sepNone
+> genPat astContext p
Expand Down