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

Add WriteLineBecauseOfTrivia for trivia newlines. #1720

Merged
merged 2 commits into from
May 11, 2021
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
85 changes: 85 additions & 0 deletions src/Fantomas.Tests/ColMultilineItemTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,88 @@ let ``first lamba`` () =
let uppercased = toUpperCase name
Assert.Equal("JOEY", uppercased)
"""

[<Test>]
let ``leading multiline block comment followed by newline should not make item multiline, 1718`` () =
formatSourceString
false
"""
(*
My personal favorite: Discriminated Unions!
This is a feature related to sum types in category theory and incredibly useful for code correctness.
ref: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/discriminated-unions
*)

type Days = Days of int // you can alias types in F# to get a DDD kind of vibe.
type StoryPoints = StoryPoints of int
type Money = Money of double
"""
config
|> prepend newline
|> should
equal
"""
(*
My personal favorite: Discriminated Unions!
This is a feature related to sum types in category theory and incredibly useful for code correctness.
ref: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/discriminated-unions
*)

type Days = Days of int // you can alias types in F# to get a DDD kind of vibe.
type StoryPoints = StoryPoints of int
type Money = Money of double
"""

[<Test>]
let ``leading comment followed by newlines should not make item multiline`` () =
formatSourceString
false
"""
//



let a = 0
let b = p
"""
config
|> prepend newline
|> should
equal
"""
//



let a = 0
let b = p
"""

[<Test>]
let ``define surrounded by newlines should not make item multiline`` () =
formatSourceString
false
"""
let a = p

#if MEH
()
#endif

let i = 00
let y = p
"""
config
|> prepend newline
|> should
equal
"""
let a = p

#if MEH
()
#endif

let i = 0
let y = p
"""
2 changes: 1 addition & 1 deletion src/Fantomas/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ let internal printTriviaContent (c: TriviaContent) (ctx: Context) =
-- s
+> sepSpace
+> ifElse after sepNlnForTrivia sepNone
| Newline -> (ifElse addNewline (sepNln +> sepNln) sepNln)
| Newline -> (ifElse addNewline (sepNlnForTrivia +> sepNlnForTrivia) sepNlnForTrivia)
| Keyword _
| Number _
| StringContent _
Expand Down