Skip to content

Commit

Permalink
Unindent after record and before members. Fixes #1824. (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jul 18, 2021
1 parent 5b9abb0 commit 6869e2e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1135,3 +1135,35 @@ module WatcherTests =
()
"""

[<Test>]
let ``a record type with accessibility modifier and members, 1824`` () =
formatSourceString
true
"""
namespace Thing
type Foo =
private
{
Bar : int
Qux : string
}
static member Baz : int
"""
config
|> prepend newline
|> should
equal
"""
namespace Thing
type Foo =
private
{
Bar : int
Qux : string
}
static member Baz : int
"""
33 changes: 31 additions & 2 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,8 +1513,8 @@ and [<CustomEquality>] Bang =
{
LongNameBarBarBarBarBarBarBar: int
}
///
override GetHashCode : unit -> int
///
override GetHashCode : unit -> int
"""

[<Test>]
Expand Down Expand Up @@ -1572,3 +1572,32 @@ type Bar =
* item : int list ->
LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong
"""

[<Test>]
let ``a record type with accessibility modifier and members`` () =
formatSourceString
true
"""
namespace Thing
type Foo =
private
{
Bar : int
Qux : string
}
static member Baz : int
"""
config
|> prepend newline
|> should
equal
"""
namespace Thing
type Foo =
private
{ Bar: int
Qux: string }
static member Baz : int
"""
4 changes: 2 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3928,9 +3928,9 @@ and genSigSimpleRecord tdr ms ao' fs astContext =
+> col sepSemiNln fs (genField astContext "")
)
+> sepCloseS
+> optSingle (fun _ -> unindent) ao'
+> sepNlnBetweenSigTypeAndMembers tdr ms
+> colPre sepNln sepNln ms (genMemberSig astContext)
+> optSingle (fun _ -> unindent) ao'

and genSigSimpleRecordAlignBrackets tdr ms ao' fs astContext =
// the typeName is already printed
Expand All @@ -3946,9 +3946,9 @@ and genSigSimpleRecordAlignBrackets tdr ms ao' fs astContext =
+> unindent
+> sepNln
+> sepCloseSFixed
+> optSingle (fun _ -> unindent) ao'
+> sepNlnBetweenSigTypeAndMembers tdr ms
+> colPre sepNln sepNln ms (genMemberSig astContext)
+> onlyIf (Option.isSome ao') unindent

and genMemberSig astContext node =
let range, mainNodeName =
Expand Down

0 comments on commit 6869e2e

Please sign in to comment.