From b4b6ac05b4a05a6038de344b8e627a084d86cb52 Mon Sep 17 00:00:00 2001 From: Bela VanderVoort Date: Tue, 8 Feb 2022 14:47:34 -0600 Subject: [PATCH] Handles an edge case from #580 --- .../FormattingTests/TestFiles/Comments_EdgeCase.cst | 7 +++++++ .../TestFiles/Comments_EdgeCase.expected.cst | 7 +++++++ Src/CSharpier/DocPrinter/DocPrinter.cs | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.cst b/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.cst index b4b599a27..a9e7941e8 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.cst +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.cst @@ -15,4 +15,11 @@ public class ClassName /// Tabs here /// public class ClassName { } +} + +public interface Interface +{ + /// + /// tab here before < + void Method(); } \ No newline at end of file diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.expected.cst b/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.expected.cst index 589389fbc..5ed614d4f 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.expected.cst +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/Comments_EdgeCase.expected.cst @@ -17,3 +17,10 @@ public class ClassName /// public class ClassName { } } + +public interface Interface +{ + /// + /// tab here before < + void Method(); +} diff --git a/Src/CSharpier/DocPrinter/DocPrinter.cs b/Src/CSharpier/DocPrinter/DocPrinter.cs index 4a7babc20..2143f81f1 100644 --- a/Src/CSharpier/DocPrinter/DocPrinter.cs +++ b/Src/CSharpier/DocPrinter/DocPrinter.cs @@ -187,9 +187,10 @@ private void AppendComment(LeadingComment leadingComment, Indent indent) // * keeps the * in line // */ var firstLineIndentLength = - firstLine!.Replace("\t", " ").Length - firstLine.TrimStart().Length; + firstLine!.Replace("\t", " ").Length + - firstLine.TrimStart().Replace("\t", " ").Length; var secondLineIndentLength = - line.Replace("\t", " ").Length - line.TrimStart().Length; + line.Replace("\t", " ").Length - line.TrimStart().Replace("\t", " ").Length; extraIndent = new string( ' ', Math.Max(secondLineIndentLength - firstLineIndentLength, 0)