Skip to content

Commit 49b2e80

Browse files
authored
Don't group xml comments onto a single line (#1748)
closes #1747
1 parent adf7026 commit 49b2e80

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Src/CSharpier.Core/Xml/XNodePrinters/ElementChildren.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,18 @@ public static Doc PrintChild(RawNode child, PrintingContext context)
113113
public static Doc PrintBetweenLine(RawNode prevNode, RawNode nextNode)
114114
{
115115
return
116-
(prevNode.IsTextLike() && nextNode.IsTextLike())
116+
(
117+
prevNode.NodeType is XmlNodeType.Text or XmlNodeType.CDATA
118+
&& nextNode.NodeType is XmlNodeType.Text or XmlNodeType.CDATA
119+
)
120+
|| (
121+
prevNode.NodeType is XmlNodeType.Text or XmlNodeType.CDATA
122+
&& nextNode.NodeType is XmlNodeType.Comment
123+
)
124+
|| (
125+
prevNode.NodeType is XmlNodeType.Comment
126+
&& nextNode.NodeType is XmlNodeType.Text or XmlNodeType.CDATA
127+
)
117128
|| (
118129
prevNode.NodeType is XmlNodeType.Text or XmlNodeType.CDATA
119130
&& nextNode.NodeType is XmlNodeType.Element

Src/CSharpier.Tests/FormattingTests/TestFiles/xml/Comments.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
CA1031; <!-- Since this is not a library project, catching general exceptions is OK -->
66
IDE0005; <!-- Allow unused usings -->
77
</NoWarn>
8+
<element>
9+
<!-- This is the first line comment-->
10+
<!-- This is the second line of my comment-->
11+
</element>
812
</Root>

0 commit comments

Comments
 (0)