Skip to content

Commit

Permalink
Add a pipe when a single case DU has attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Dec 15, 2019
1 parent 4913ed6 commit 7ad5e3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/Fantomas.Tests/UnionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,16 @@ type internal Foo = private | Bar
|> should equal """namespace meh
type internal Foo = private | Bar
"""

[<Test>]
let ``preserve pipe when single choice contains attribute, 596`` () =
formatSourceString false """type [<StringEnum>] [<RequireQualifiedAccess>] PayableFilters =
| [<CompiledName "statusSelector">] Status
""" config
|> prepend newline
|> should equal """
[<StringEnum>]
[<RequireQualifiedAccess>]
type PayableFilters = | [<CompiledName "statusSelector">] Status
"""
4 changes: 2 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,8 +1525,8 @@ and genTypeDefn astContext (TypeDef(ats, px, ao, tds, tcs, tdr, ms, s, preferPos
let unionCases =
match xs with
| [] -> id
| [x] when List.isEmpty ms ->
let hasVerticalBar = Option.isSome ao'
| [UnionCase(attrs, _,_,_,_) as x] when List.isEmpty ms ->
let hasVerticalBar = Option.isSome ao' || not (List.isEmpty attrs)

indent +> sepSpace +> sepNlnBasedOnTrivia
+> genTrivia tdr.Range
Expand Down

0 comments on commit 7ad5e3f

Please sign in to comment.