Skip to content

Commit

Permalink
Don't indent static member too far if record has access modifier. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Dec 18, 2020
1 parent ac4e2d6 commit f383752
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
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

0 comments on commit f383752

Please sign in to comment.