Skip to content

Commit

Permalink
Always force hash directives on a new line. (#600)
Browse files Browse the repository at this point in the history
Fixes #576
  • Loading branch information
nojaf authored Dec 19, 2019
1 parent 544d89b commit 09c7f23
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,4 +1006,46 @@ let foo =
|> List.rev
#endif
|> List.sort
"""

[<Test>]
let ``async block inside directive, 576`` () =
formatSourceString false """#if TEST
let f () =
async {
let x = 2
return x
}
#endif
""" config
|> prepend newline
|> should equal """
#if TEST
let f() =
async {
let x = 2
return x
}
#endif
"""

[<Test>]
let ``async block inside directive, TEST`` () =
formatSourceStringWithDefines ["TEST"] """#if TEST
let f () =
async {
let x = 2
return x
}
#endif
""" config
|> prepend newline
|> should equal """
#if TEST
let f() =
async {
let x = 2
return x
}
#endif
"""
3 changes: 2 additions & 1 deletion src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type Element =
module RecordSignature
/// Represents simple XML elements.
type Element =
{ /// The attribute collection.
{
/// The attribute collection.
Attributes: IDictionary<Name, string>;
/// The children collection.
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ let internal printTriviaContent (c: TriviaContent) (ctx: Context) =
// It is hard to always get this right in CodePrinter, so we detect it based on the current code.
let addNewline =
currentLastLine
|> Option.map(fun line -> line.Trim().Length > 1)
|> Option.map(fun line -> line.Trim().Length > 0)
|> Option.defaultValue false

let addSpace =
Expand Down

0 comments on commit 09c7f23

Please sign in to comment.