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

Fix Stroustrup record member declaration indent issue #2788

Merged
merged 2 commits into from
Mar 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,63 @@ type MangaDexAtHomeResponse = {
|}
}
"""

[<Test>]
let ``record interface declarations can break with Stroustrup enabled, 2787 `` () =
formatSourceString
false
"""
type IEvent = interface end

type SomeEvent =
{ Id: string
Name: string }
interface IEvent

type UpdatedName = { PreviousName: string }
"""
{ config with
NewlineBetweenTypeDefinitionAndMembers = false }
|> prepend newline
|> should
equal
"""
type IEvent =
interface
end

type SomeEvent = {
Id: string
Name: string
} with
interface IEvent

type UpdatedName = { PreviousName: string }
"""

[<Test>]
let ``record member declarations can break with Stroustrup enabled, 2787 `` () =
formatSourceString
false
"""
type SomeEvent =
{ Id: string
Name: string }
member x.BreakWithOtherStuffAs well = ()

type UpdatedName = { PreviousName: string }
"""
{ config with
NewlineBetweenTypeDefinitionAndMembers = false }
|> prepend newline
|> should
equal
"""
type SomeEvent = {
Id: string
Name: string
} with
member x.BreakWithOtherStuffAs well = ()

type UpdatedName = { PreviousName: string }
"""
7 changes: 2 additions & 5 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3234,9 +3234,7 @@ let genTypeDefn (td: TypeDefn) =
+> genSingleTextNode node.ClosingBrace

let genMembers =
onlyIf hasMembers sepNln
+> sepNlnBetweenTypeAndMembers typeDefnNode
+> genMemberDefnList members
onlyIf hasMembers (sepNln +> sepNlnBetweenTypeAndMembers typeDefnNode +> genMemberDefnList members)

let anyFieldHasXmlDoc =
List.exists (fun (fieldNode: FieldNode) -> fieldNode.XmlDoc.IsSome) node.Fields
Expand All @@ -3255,8 +3253,7 @@ let genTypeDefn (td: TypeDefn) =

genAccessOpt node.Accessibility
+> genRecordFields
+> onlyIf hasMembers (sepSpace +> withKw +> indent)
+> genMembers
+> onlyIf hasMembers (sepSpace +> withKw +> indent +> genMembers +> unindent)

let cramped =
sepNlnUnlessLastEventIsNewline
Expand Down