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 problem with empty nested module generation #2729

Merged
merged 1 commit into from
Jan 19, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
* Optional constructor arguments are lost. [#2718](https://github.com/fsprojects/fantomas/issues/2718)
* Empty nested module. [#2721](https://github.com/fsprojects/fantomas/issues/2721~~~~)

## [5.2.0-alpha-012] - 2023-01-14

Expand Down
17 changes: 17 additions & 0 deletions src/Fantomas.Core.Tests/ModuleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,20 @@ module Ionide.VSCode.FSharp

open global.Node.ChildProcess
"""

[<Test>]
let ``empty nested module, 2721`` () =
formatSourceString
true
"""
module Graph =
begin end
"""
config
|> prepend newline
|> should
equal
"""
module Graph =
begin end
"""
6 changes: 5 additions & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3591,8 +3591,12 @@ let genModuleDecl (md: ModuleDecl) =
+> sepSpace
+> genSingleTextNode node.Equals
+> indentSepNlnUnindent (
colWithNlnWhenMappedNodeIsMultiline false ModuleDecl.Node genModuleDecl node.Declarations
ifElse
(List.isEmpty node.Declarations)
(!- "begin end")
(colWithNlnWhenMappedNodeIsMultiline false ModuleDecl.Node genModuleDecl node.Declarations)
)

|> genNode (ModuleDecl.Node md)
| ModuleDecl.TypeDefn td -> genTypeDefn td
| ModuleDecl.Val node -> genVal node None
Expand Down