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 record definition using Stroustrup style #2484

Merged
merged 8 commits into from
Sep 8, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Fixed
* Record definition with accessibility modifier error using stroustrup style [#2481](https://github.com/fsprojects/fantomas/issues/2481)

## [5.0.0-beta-009] - 2022-09-02

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,67 @@ type V =
}
member this.Coordinate = (this.X, this.Y, this.Z)
"""

[<Test>]
let ``record definition with private accessibility modifier, 2481`` () =
formatSourceString
false
"""
type Person = private {
FirstName: string
LastName: string
}
"""
config
|> prepend newline
|> should
equal
"""
type Person = private {
FirstName: string
LastName: string
}
"""

[<Test>]
let ``record definition with internal accessibility modifier, 2481`` () =
formatSourceString
false
"""
type Person = internal {
FirstName: string
LastName: string
}
"""
config
|> prepend newline
|> should
equal
"""
type Person = internal {
FirstName: string
LastName: string
}
"""

[<Test>]
let ``record definition with accessibility modifier with incorrect format, 2481`` () =
formatSourceString
false
"""
type Person =
private {
FirstName: string
LastName: string
}
"""
config
|> prepend newline
|> should
equal
"""
type Person = private {
FirstName: string
LastName: string
}
"""
2 changes: 1 addition & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3412,7 +3412,7 @@ and genMultilineSimpleRecordTypeDefn astContext openingBrace withKeyword ms ao'

and genMultilineSimpleRecordTypeDefnAlignBrackets astContext openingBrace withKeyword ms ao' fs closingBrace =
// the typeName is already printed
opt (indent +> sepNln) ao' genAccess
ifStroustrupElse (opt (sepSpace) ao' genAccess) (opt (indent +> sepNln) ao' genAccess)
+> enterNodeFor SynTypeDefnSimpleRepr_Record_OpeningBrace openingBrace
+> sepOpenSFixed
+> indentSepNlnUnindent (
Expand Down