From 92af7b068451ad9c7465f84ccbd798d61ad1abfe Mon Sep 17 00:00:00 2001 From: Akihiko Odaki <nekomanma@pixiv.co.jp> Date: Sat, 26 Oct 2019 19:05:29 +0900 Subject: [PATCH] Do not trim spaces at the beginning in copyright header comment The copyright header rule trims spaces at the begginings of code comment lines. However, it does not perform the same operation for raw texts. That difference makes the rule think a code comment line and a raw text line different even if they are same. Such a raw text including a line beginning with spaces include Apache-2.0's copyright notice. This change fixes the problem by removing the code trimming spaces. Additionally, this change takes spaces added when introducing new copyright headers into account. --- .../Rules/CopyrightHeaderRule.CSharp.cs | 2 +- .../Rules/CopyrightHeaderRule.VisualBasic.cs | 2 +- .../Rules/CopyrightHeaderRule.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.CSharp.cs b/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.CSharp.cs index df0be36b..ffd264db 100644 --- a/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.CSharp.cs +++ b/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.CSharp.cs @@ -45,7 +45,7 @@ protected override bool IsNewLine(SyntaxTrivia trivia) protected override SyntaxTrivia CreateLineComment(string commentText) { - return SyntaxFactory.Comment("// " + commentText); + return SyntaxFactory.Comment("//" + commentText); } protected override SyntaxTrivia CreateNewLine() diff --git a/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.VisualBasic.cs b/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.VisualBasic.cs index f19d27cf..3915105f 100644 --- a/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.VisualBasic.cs +++ b/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.VisualBasic.cs @@ -44,7 +44,7 @@ protected override bool IsNewLine(SyntaxTrivia trivia) protected override SyntaxTrivia CreateLineComment(string commentText) { - return SyntaxFactory.CommentTrivia("' " + commentText); + return SyntaxFactory.CommentTrivia("'" + commentText); } protected override SyntaxTrivia CreateNewLine() diff --git a/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.cs b/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.cs index f297bfea..5b092ad5 100644 --- a/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.cs +++ b/src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.cs @@ -190,15 +190,15 @@ private static string GetCommentText(string line) { if (line.StartsWith("'")) { - return line.Substring(1).TrimStart(); + return line.Substring(1); } if (line.StartsWith("//")) { - return line.Substring(2).TrimStart(); + return line.Substring(2); } - return line; + return " " + line; } public override bool SupportsLanguage(string languageName)