Skip to content

Commit b6fcdd2

Browse files
authored
Unix line breaks (#146)
* Manually change newline of test files to LF * Use Unix newline in TripleSlashSyntaxRewriter * Change the SyntaxTrivia from CarriageReturnLineFeed to LineFeed * .editorconfig * .gitattributes
1 parent e36bcfe commit b6fcdd2

File tree

7 files changed

+22
-24
lines changed

7 files changed

+22
-24
lines changed

.editorconfig

+2-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ insert_final_newline = true
1111
indent_style = space
1212
indent_size = 4
1313
trim_trailing_whitespace = true
14+
end_of_line = lf
15+
charset = utf-8
1416

1517
# Generated code
1618
[*{_AssemblyInfo.cs,.notsupported.cs,AsmOffsets.cs}]
@@ -183,10 +185,3 @@ indent_size = 2
183185
# YAML config files
184186
[*.{yml,yaml}]
185187
indent_size = 2
186-
187-
# Shell scripts
188-
[*.sh]
189-
end_of_line = lf
190-
[*.{cmd,bat}]
191-
end_of_line = crlf
192-

.gitattributes

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Set default behavior to automatically normalize line endings.
2-
* text=auto
2+
* text=auto eol=lf
33

44
*.doc diff=astextplain
55
*.DOC diff=astextplain
@@ -54,6 +54,7 @@
5454
*.fs text=auto
5555
*.fsx text=auto
5656
*.hs text=auto
57+
*.xml text=auto
5758

5859
*.csproj text=auto
5960
*.vbproj text=auto

src/PortToTripleSlash/src/libraries/RoslynTripleSlash/TripleSlashSyntaxRewriter.cs

+14-12
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ internal class TripleSlashSyntaxRewriter : CSharpSyntaxRewriter
9292
{
9393
#region Private members
9494

95+
private static readonly string UnixNewLine = "\n";
96+
9597
private static readonly string[] ReservedKeywords = new[] { "abstract", "async", "await", "false", "null", "sealed", "static", "true", "virtual" };
9698

9799
private static readonly string[] MarkdownUnconvertableStrings = new[] { "](~/includes", "[!INCLUDE" };
@@ -437,7 +439,7 @@ private static SyntaxNode GetNodeWithTrivia(SyntaxTriviaList leadingWhitespace,
437439
if (leadingTrivia[0].IsKind(SyntaxKind.EndOfLineTrivia))
438440
{
439441
// Ensure the endline that separates nodes is respected
440-
finalTrivia = new SyntaxTriviaList(SyntaxFactory.ElasticCarriageReturnLineFeed)
442+
finalTrivia = new SyntaxTriviaList(SyntaxFactory.ElasticLineFeed)
441443
.AddRange(finalTrivia);
442444
}
443445
}
@@ -476,7 +478,7 @@ private static SyntaxTriviaList GetLeadingDoubleSlashComments(SyntaxNode node, S
476478
doubleSlashComments = doubleSlashComments
477479
.AddRange(leadingWhitespace)
478480
.Add(trivia)
479-
.Add(SyntaxFactory.CarriageReturnLineFeed);
481+
.Add(SyntaxFactory.LineFeed);
480482
}
481483
}
482484

@@ -697,12 +699,12 @@ private static XmlTextSyntax GetTextAsCommentedTokens(string text, SyntaxTriviaL
697699

698700
// collapse newlines to a single one
699701
string whitespace = Regex.Replace(leadingWhitespace.ToFullString(), @"(\r?\n)+", "");
700-
SyntaxToken whitespaceToken = SyntaxFactory.XmlTextNewLine(Environment.NewLine + whitespace);
702+
SyntaxToken whitespaceToken = SyntaxFactory.XmlTextNewLine(UnixNewLine + whitespace);
701703

702704
SyntaxTrivia leadingTrivia = SyntaxFactory.SyntaxTrivia(SyntaxKind.DocumentationCommentExteriorTrivia, string.Empty);
703705
SyntaxTriviaList leading = SyntaxTriviaList.Create(leadingTrivia);
704706

705-
string[] lines = text.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
707+
string[] lines = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
706708

707709
var tokens = new List<SyntaxToken>();
708710

@@ -740,7 +742,7 @@ private static SyntaxTriviaList GetXmlTrivia(XmlNodeSyntax node, SyntaxTriviaLis
740742

741743
return leadingWhitespace
742744
.Add(docCommentTrivia)
743-
.Add(SyntaxFactory.CarriageReturnLineFeed);
745+
.Add(SyntaxFactory.LineFeed);
744746
}
745747

746748
// Generates a custom SyntaxTrivia object containing a triple slashed xml element with optional attributes.
@@ -765,9 +767,9 @@ private static SyntaxTriviaList GetXmlTrivia(string name, SyntaxList<XmlAttribut
765767

766768
private static string WrapInRemarks(string acum)
767769
{
768-
string wrapped = Environment.NewLine + "<format type=\"text/markdown\"><![CDATA[" + Environment.NewLine;
770+
string wrapped = UnixNewLine + "<format type=\"text/markdown\"><![CDATA[" + UnixNewLine;
769771
wrapped += acum;
770-
wrapped += Environment.NewLine + "]]></format>" + Environment.NewLine;
772+
wrapped += UnixNewLine + "]]></format>" + UnixNewLine;
771773
return wrapped;
772774
}
773775

@@ -776,7 +778,7 @@ private static string WrapCodeIncludes(string[] splitted, ref int n)
776778
string acum = string.Empty;
777779
while (n < splitted.Length && splitted[n].ContainsStrings(MarkdownCodeIncludes))
778780
{
779-
acum += Environment.NewLine + splitted[n];
781+
acum += UnixNewLine + splitted[n];
780782
if ((n + 1) < splitted.Length && splitted[n + 1].ContainsStrings(MarkdownCodeIncludes))
781783
{
782784
n++;
@@ -802,7 +804,7 @@ private static SyntaxTriviaList GetFormattedRemarks(IDocsAPI api, SyntaxTriviaLi
802804
}
803805
else
804806
{
805-
string[] splitted = remarks.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
807+
string[] splitted = remarks.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
806808
string updatedRemarks = string.Empty;
807809
for (int n = 0; n < splitted.Length; n++)
808810
{
@@ -814,7 +816,7 @@ private static SyntaxTriviaList GetFormattedRemarks(IDocsAPI api, SyntaxTriviaLi
814816
n++;
815817
while (n < splitted.Length && splitted[n].StartsWith(">"))
816818
{
817-
acum += Environment.NewLine + splitted[n];
819+
acum += UnixNewLine + splitted[n];
818820
if ((n + 1) < splitted.Length && splitted[n + 1].StartsWith(">"))
819821
{
820822
n++;
@@ -843,14 +845,14 @@ private static SyntaxTriviaList GetFormattedRemarks(IDocsAPI api, SyntaxTriviaLi
843845
}
844846
else
845847
{
846-
example += Environment.NewLine + line;
848+
example += UnixNewLine + line;
847849
}
848850
n++;
849851
}
850852
}
851853
else
852854
{
853-
updatedRemarks += ReplaceMarkdownWithXmlElements(Environment.NewLine + line, api.Params, api.TypeParams);
855+
updatedRemarks += ReplaceMarkdownWithXmlElements(UnixNewLine + line, api.Params, api.TypeParams);
854856
}
855857
}
856858

src/PortToTripleSlash/tests/PortToTripleSlash/TestData/Basic/MyEnum.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ URL entities: %23%28%2C%29 must remain unconverted.
4848
</Docs>
4949
</Member>
5050
</Members>
51-
</Type>
51+
</Type>

src/PortToTripleSlash/tests/PortToTripleSlash/TestData/Basic/MyType.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,4 @@ There are also a `true` and a `null`.
230230
</Docs>
231231
</Member>
232232
</Members>
233-
</Type>
233+
</Type>

src/PortToTripleSlash/tests/PortToTripleSlash/TestData/Generics/MyGenericType`1+Enumerator.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
<Docs>
77
<summary>This is the MyGenericType{T}.Enumerator class summary.</summary>
88
</Docs>
9-
</Type>
9+
</Type>

src/PortToTripleSlash/tests/PortToTripleSlash/TestData/Generics/MyGenericType`1.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Contains the nested class <xref:MyNamespace.MyGenericType%601.Enumerator>.
1313
]]></format>
1414
</remarks>
1515
</Docs>
16-
</Type>
16+
</Type>

0 commit comments

Comments
 (0)