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

Don't indent static member too far if record has access modifier #1301

Merged
merged 1 commit into from
Dec 18, 2020
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
81 changes: 81 additions & 0 deletions src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,3 +1344,84 @@ let internal sepSemi (ctx: Context) =
| true, true -> str " ; "
<| ctx
"""

[<Test>]
let ``record with an access modifier and a static member, 1300`` () =
formatSourceString
false
"""
type RequestParser<'ctx, 'a> =
internal
{ consumedFields: Set<ConsumedFieldName>
parse: 'ctx -> Request -> Async<Result<'a, Error list>>
prohibited: ProhibitedRequestGetter list }

static member internal Create
(
consumedFields, parse: 'ctx -> Request -> Async<Result<'a, Error list>>
) : RequestParser<'ctx, 'a> =
{ consumedFields = consumedFields
parse = parse
prohibited = [] }

"""
config
|> prepend newline
|> should
equal
"""
type RequestParser<'ctx, 'a> =
internal
{ consumedFields: Set<ConsumedFieldName>
parse: 'ctx -> Request -> Async<Result<'a, Error list>>
prohibited: ProhibitedRequestGetter list }

static member internal Create(consumedFields, parse: 'ctx -> Request -> Async<Result<'a, Error list>>)
: RequestParser<'ctx, 'a> =
{ consumedFields = consumedFields
parse = parse
prohibited = [] }
"""

[<Test>]
let ``record with an access modifier and a static member, MultilineBlockBracketsOnSameColumn`` () =
formatSourceString
false
"""
type RequestParser<'ctx, 'a> =
internal
{ consumedFields: Set<ConsumedFieldName>
parse: 'ctx -> Request -> Async<Result<'a, Error list>>
prohibited: ProhibitedRequestGetter list }

static member internal Create
(
consumedFields, parse: 'ctx -> Request -> Async<Result<'a, Error list>>
) : RequestParser<'ctx, 'a> =
{ consumedFields = consumedFields
parse = parse
prohibited = [] }

"""
{ config with
MultilineBlockBracketsOnSameColumn = true }
|> prepend newline
|> should
equal
"""
type RequestParser<'ctx, 'a> =
internal
{
consumedFields: Set<ConsumedFieldName>
parse: 'ctx -> Request -> Async<Result<'a, Error list>>
prohibited: ProhibitedRequestGetter list
}

static member internal Create(consumedFields, parse: 'ctx -> Request -> Async<Result<'a, Error list>>)
: RequestParser<'ctx, 'a> =
{
consumedFields = consumedFields
parse = parse
prohibited = []
}
"""
2 changes: 2 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3548,6 +3548,7 @@ and genMultilineSimpleRecordTypeDefn tdr ms ao' fs astContext =
)
+> sepCloseS
+> leaveNodeTokenByName tdr.Range RBRACE
+> optSingle (fun _ -> unindent) ao'
+> onlyIf (List.isNotEmpty ms) sepNln
+> sepNlnBetweenTypeAndMembers ms
+> genMemberDefnList
Expand All @@ -3570,6 +3571,7 @@ and genMultilineSimpleRecordTypeDefnAlignBrackets tdr ms ao' fs astContext =
+> unindent
+> sepNln
+> sepCloseSFixed
+> optSingle (fun _ -> unindent) ao'
+> onlyIf (List.isNotEmpty ms) sepNln
+> sepNlnBetweenTypeAndMembers ms
+> genMemberDefnList
Expand Down