From 09c842e057475d84710599f3171745c3bbe805ec Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Fri, 12 Jun 2020 14:20:29 +0200 Subject: [PATCH] Don't consider attribute above field a proper candidate for trivia after. Fixes #910 (#912) --- src/Fantomas.Tests/TypeDeclarationTests.fs | 23 +++++++++++++++++++++- src/Fantomas/Trivia.fs | 10 ++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Fantomas.Tests/TypeDeclarationTests.fs b/src/Fantomas.Tests/TypeDeclarationTests.fs index 3bf244acd3..a313815e42 100644 --- a/src/Fantomas.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Tests/TypeDeclarationTests.fs @@ -1306,4 +1306,25 @@ type VersionMismatchDuringDeserializationException(message: string, innerExcepti type VersionMismatchDuringDeserializationException(message : string, innerException : System.Exception) = inherit System.Exception(message, innerException) -""" \ No newline at end of file +""" + +[] +let ``type record declaration with attributes, 910`` () = + formatSourceString false """type Commenter = + { [] + DisplayName: string } + +type Message = + { [] + Body: string } +""" config + |> prepend newline + |> should equal """ +type Commenter = + { [] + DisplayName: string } + +type Message = + { [] + Body: string } +""" diff --git a/src/Fantomas/Trivia.fs b/src/Fantomas/Trivia.fs index 8a98bc6f97..ecc3ef5da7 100644 --- a/src/Fantomas/Trivia.fs +++ b/src/Fantomas/Trivia.fs @@ -204,11 +204,17 @@ let private triviaBetweenAttributeAndParentBinding (triviaNodes: TriviaNodeAssig | MainNode("SynModuleSigDecl.NestedModule") | MainNode("ValSpfn") | MainNode("SynMemberDefn.Member") - | MainNode("SynMemberDefn.LetBindings") -> true + | MainNode("SynMemberDefn.LetBindings") + | MainNode("Field") -> true | _ -> false ) |> List.pairwise + filteredNodes |> List.tryFind (function + | f, a when (f.Type = MainNode("Field") + && a.Type = MainNode("SynAttributeList") + && f.Range.StartLine = a.Range.StartLine + && a.Range.StartLine + 1 = f.Range.EndLine) -> true | a, p when (a.Type = MainNode("SynAttributeList") && a.Range.StartLine < line && a.Range.StartLine = a.Range.EndLine) -> match p.Type with | MainNode("SynModuleDecl.Let") when (p.Range.StartLine > line) -> true @@ -216,7 +222,7 @@ let private triviaBetweenAttributeAndParentBinding (triviaNodes: TriviaNodeAssig | MainNode("SynModuleDecl.Types") when (p.Range.StartLine > line) -> true | _ -> false | _ -> false) - |> Option.map fst + |> Option.bind (fun (a,_) -> if a.Type = MainNode("SynAttributeList") then Some a else None) let private findASTNodeOfTypeThatContains (nodes: TriviaNodeAssigner list) typeName range = nodes