Skip to content

Commit

Permalink
only call sepSpaceBeforeClassConstructor if we are generating a class (
Browse files Browse the repository at this point in the history
…#2284)

* only call sepSpaceBeforeClassConstructor if we are generating a class, fixes 2226

* Use Option.isNone
  • Loading branch information
dawedawe committed May 30, 2022
1 parent 3cdfaec commit 5e92752
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Fixed
* Explicit interface with SpaceBeforeClassConstructor. [#2226](https://github.com/fsprojects/fantomas/issues/2226)
* Spaces around binary operators in units of measure. [#2207](https://github.com/fsprojects/fantomas/issues/2207)

## [5.0.0-alpha-008] - 2022-05-28
Expand Down
35 changes: 35 additions & 0 deletions src/Fantomas.Core.Tests/InterfaceTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,38 @@ and Bar =
[<SomeAttribute>]
member this.SomeFunctionWithReturnType(a: int) : int = a + 5
"""

[<Test>]
let ``explicit interface with SpaceBeforeClassConstructor, 2226`` () =
formatSourceString
false
"""
type IInterface =
interface
end
type IInterface2 =
interface
abstract member X: unit -> unit
end
type IInterface3 =
abstract member X: unit -> unit
"""
{ config with SpaceBeforeClassConstructor = true }
|> prepend newline
|> should
equal
"""
type IInterface =
interface
end
type IInterface2 =
interface
abstract member X: unit -> unit
end
type IInterface3 =
abstract member X: unit -> unit
"""
4 changes: 3 additions & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3722,10 +3722,12 @@ and genTypeDefn
| TCSimple TCInterface -> Some range
| _ -> None

let isClass = Option.isNone interfaceRange

let astContext = { astContext with InterfaceRange = interfaceRange }

typeName
+> sepSpaceBeforeClassConstructor
+> onlyIf isClass sepSpaceBeforeClassConstructor
+> leadingExpressionIsMultiline (opt sepNone impCtor (genMemberDefn astContext)) (fun isMulti ctx ->
if isMulti
&& ctx.Config.AlternativeLongMemberDefinitions then
Expand Down

0 comments on commit 5e92752

Please sign in to comment.