Skip to content

Commit f144756

Browse files
authored
Add additional newline when there is trivia after the opening parenthesis (#2848)
* Add additional newline when there is trivia after the opening parenthesis. * Add new version.
1 parent b46120d commit f144756

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [6.0.1] - 2023-04-19
4+
5+
### Fixed
6+
* Invalid code: moved line comment. [#2847](https://github.com/fsprojects/fantomas/issues/2847)
7+
38
## [6.0.0] - 2023-04-13
49

510
### Fixed

src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
<Compile Include="TryWithTests.fs" />
128128
<Compile Include="CursorTests.fs" />
129129
<Compile Include="MultipleDefineCombinationsTests.fs" />
130+
<Compile Include="ParenthesesTests.fs" />
130131
</ItemGroup>
131132
<ItemGroup>
132133
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Fantomas.Core.Tests.ParenthesesTests
2+
3+
open NUnit.Framework
4+
open FsUnit
5+
open Fantomas.Core.Tests.TestHelpers
6+
7+
[<Test>]
8+
let ``trivia after opening parenthesis, 2847`` () =
9+
formatSourceString
10+
false
11+
"""
12+
let canConvertMemorised =
13+
Memoized.memoize
14+
(fun objectType ->
15+
( // Include F# discriminated unions
16+
FSharpType.IsUnion objectType
17+
// and exclude the standard FSharp lists (which are implemented as discriminated unions)
18+
&& not (objectType.GetTypeInfo().IsGenericType && objectType.GetGenericTypeDefinition() = typedefof<_ list>)
19+
)
20+
// include tuples
21+
|| tupleAsHeterogeneousArray && FSharpType.IsTuple objectType
22+
)
23+
"""
24+
config
25+
|> prepend newline
26+
|> should
27+
equal
28+
"""
29+
let canConvertMemorised =
30+
Memoized.memoize (fun objectType ->
31+
( // Include F# discriminated unions
32+
FSharpType.IsUnion objectType
33+
// and exclude the standard FSharp lists (which are implemented as discriminated unions)
34+
&& not (
35+
objectType.GetTypeInfo().IsGenericType
36+
&& objectType.GetGenericTypeDefinition() = typedefof<_ list>
37+
))
38+
// include tuples
39+
|| tupleAsHeterogeneousArray && FSharpType.IsTuple objectType)
40+
"""

src/Fantomas.Core/CodePrinter.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ let genExpr (e: Expr) =
712712
+> genSingleTextNode node.ClosingParen
713713
| _ ->
714714
genSingleTextNode node.OpeningParen
715+
+> sepNlnWhenWriteBeforeNewlineNotEmpty
715716
+> genExpr node.Expr
716717
+> genSingleTextNode node.ClosingParen
717718
|> genNode node

0 commit comments

Comments
 (0)