Skip to content

Commit

Permalink
bugfix: Shouldn't remove space after colon (#1192)
Browse files Browse the repository at this point in the history
* bugfix: Shouldn't remove space after colon

fixes #908

* Using sepColon instead of introducing a new duplicate one

* fix CheckFormating issue

Co-authored-by: Florian Verdonck <[email protected]>
  • Loading branch information
aarani and nojaf authored Oct 16, 2020
1 parent 0f6b3ad commit 3f63954
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
20 changes: 10 additions & 10 deletions src/Fantomas.Tests/AttributeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type Foo =
|> should equal """
[<DataContract>]
type Foo =
{ [<field:DataMember>]
{ [<field: DataMember>]
Bar: string }
"""

Expand Down Expand Up @@ -336,22 +336,22 @@ open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
[<assembly:AssemblyTitle("Foo")>]
[<assembly:AssemblyDescription("")>]
[<assembly: AssemblyTitle("Foo")>]
[<assembly: AssemblyDescription("")>]
do ()
"""

[<Test>]
let ``should preserve single return type attribute`` () =
formatSourceString false """let f x : [<return: Attribute>] int = x""" config
|> should equal """let f x: [<return:Attribute>] int = x
|> should equal """let f x: [<return: Attribute>] int = x
"""

[<Test>]
let ``should preserve multiple return type attributes`` () =
formatSourceString false """let f x : [<return: AttributeOne;AttributeTwo;AttributeThree("foo")>] int = x""" config
|> should equal """let f x: [<return:AttributeOne; AttributeTwo; AttributeThree("foo")>] int = x
|> should equal """let f x: [<return: AttributeOne; AttributeTwo; AttributeThree("foo")>] int = x
"""

[<Test>]
Expand Down Expand Up @@ -480,11 +480,11 @@ open System
open System.Reflection
open System.Runtime.InteropServices
[<assembly:CLSCompliant(true)>]
[<assembly:ComVisible(false)>]
[<assembly:AssemblyTitle("AltCover.Visualizer")>]
[<assembly:AssemblyDescription("Coverage and static analysis visualizer for NCover (possibly extended) and OpenCover")>]
[<assembly:System.Resources.NeutralResourcesLanguageAttribute("en-GB")>]
[<assembly: CLSCompliant(true)>]
[<assembly: ComVisible(false)>]
[<assembly: AssemblyTitle("AltCover.Visualizer")>]
[<assembly: AssemblyDescription("Coverage and static analysis visualizer for NCover (possibly extended) and OpenCover")>]
[<assembly: System.Resources.NeutralResourcesLanguageAttribute("en-GB")>]
()
"""

Expand Down
40 changes: 20 additions & 20 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,14 @@ open System.Diagnostics.CodeAnalysis
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
[<assembly:InternalsVisibleTo("AltCover.FSApi, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
[<assembly: InternalsVisibleTo("AltCover.FSApi, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
#if NETCOREAPP2_0
[<assembly:InternalsVisibleTo("dotnet-altcover, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
[<assembly:InternalsVisibleTo("global-altcover, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
[<assembly: InternalsVisibleTo("dotnet-altcover, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
[<assembly: InternalsVisibleTo("global-altcover, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
#endif
[<assembly:CLSCompliant(true)>]
[<assembly:ComVisible(false)>]
[<assembly:System.Resources.NeutralResourcesLanguageAttribute("en-GB")>]
[<assembly: CLSCompliant(true)>]
[<assembly: ComVisible(false)>]
[<assembly: System.Resources.NeutralResourcesLanguageAttribute("en-GB")>]
let foo = ()
"""

Expand Down Expand Up @@ -860,14 +860,14 @@ open System.Diagnostics.CodeAnalysis
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
[<assembly:InternalsVisibleTo("AltCover.FSApi, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
[<assembly: InternalsVisibleTo("AltCover.FSApi, PublicKey=0024000004800000940000000602000000240000525341310004000001000100916443A2EE1D294E8CFA7666FB3F512D998D7CEAC4909E35EDB2AC1E104DE68890A93716D1D1931F7228AAC0523CACF50FD82CDB4CCF4FF4BF0DED95E3A383F4F371E3B82C45502CE74D7D572583495208C1905E0F1E8A3CCE66C4C75E4CA32E9A8F8DEE64E059C0DC0266E8D2CB6D7EBD464B47E062F80B63D390E389217FB7")>]
#if NETCOREAPP2_0
#endif
[<assembly:CLSCompliant(true)>]
[<assembly:ComVisible(false)>]
[<assembly:System.Resources.NeutralResourcesLanguageAttribute("en-GB")>]
[<assembly: CLSCompliant(true)>]
[<assembly: ComVisible(false)>]
[<assembly: System.Resources.NeutralResourcesLanguageAttribute("en-GB")>]
let foo = ()
"""

Expand All @@ -882,30 +882,30 @@ do ()
""" config
|> prepend newline
|> should equal """
[<assembly:Foo>]
[<assembly: Foo>]
#if BAR
#endif
[<assembly:Meh>]
[<assembly: Meh>]
do ()
"""

[<Test>]
let ``hash directive between attributes, bar`` () =
formatSourceStringWithDefines [ "BAR" ] """[<assembly:Foo()>]
#if BAR
[<assembly:Bar()>]
[<assembly: Bar()>]
#endif
[<assembly:Meh()>]
[<assembly: Meh()>]
do ()
""" config
|> prepend newline
|> should equal """
[<assembly:Foo>]
[<assembly: Foo>]
#if BAR
[<assembly:Bar>]
[<assembly: Bar>]
#endif
[<assembly:Meh>]
[<assembly: Meh>]
do ()
"""

Expand All @@ -920,11 +920,11 @@ do ()
""" config
|> prepend newline
|> should equal """
[<assembly:Foo>]
[<assembly: Foo>]
#if BAR
[<assembly:Bar>]
[<assembly: Bar>]
#endif
[<assembly:Meh>]
[<assembly: Meh>]
do ()
"""

Expand Down
11 changes: 4 additions & 7 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -480,28 +480,25 @@ and genAccess (Access s) = !-s
and genAttribute astContext (Attribute (s, e, target)) =
match e with
// Special treatment for function application on attributes
| ConstExpr (Const "()", _) ->
!- "[<" +> opt sepColonFixed target (!-)
-- s
-- ">]"
| ConstExpr (Const "()", _) -> !- "[<" +> opt sepColon target (!-) -- s -- ">]"
| e ->
let argSpacing =
if hasParenthesis e then id else sepSpace

!- "[<" +> opt sepColonFixed target (!-) -- s
!- "[<" +> opt sepColon target (!-) -- s
+> argSpacing
+> genExpr astContext e
-- ">]"

and genAttributesCore astContext (ats: SynAttribute seq) =
let genAttributeExpr astContext (Attribute (s, e, target) as attr) =
match e with
| ConstExpr (Const "()", _) -> opt sepColonFixed target (!-) -- s
| ConstExpr (Const "()", _) -> opt sepColon target (!-) -- s
| e ->
let argSpacing =
if hasParenthesis e then id else sepSpace

opt sepColonFixed target (!-) -- s
opt sepColon target (!-) -- s
+> argSpacing
+> genExpr astContext e
|> genTriviaFor SynAttribute_ attr.Range
Expand Down

0 comments on commit 3f63954

Please sign in to comment.