Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit 2f975f9

Browse files
committed
Fix multiline copyright header rule
1 parent 32fec62 commit 2f975f9

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Rules/CopyrightHeaderRuleTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ class C
2929

3030
var expected = @"// test
3131
32+
class C
33+
{
34+
}";
35+
Verify(source, expected);
36+
37+
}
38+
39+
[Fact]
40+
public void CSharpSimpleMultiline()
41+
{
42+
_options.CopyrightHeader = ImmutableArray.Create("test1", "test2");
43+
var source = @"
44+
class C
45+
{
46+
}";
47+
48+
var expected = @"// test1
49+
// test2
50+
3251
class C
3352
{
3453
}";
@@ -48,6 +67,27 @@ class C
4867

4968
var expected = @"// test
5069
70+
class C
71+
{
72+
}";
73+
Verify(source, expected);
74+
75+
}
76+
77+
[Fact]
78+
public void CSharpPreserveExistingMultiline()
79+
{
80+
_options.CopyrightHeader = ImmutableArray.Create("test1", "test2");
81+
var source = @"// test1
82+
// test2
83+
84+
class C
85+
{
86+
}";
87+
88+
var expected = @"// test1
89+
// test2
90+
5191
class C
5292
{
5393
}";

src/Microsoft.DotNet.CodeFormatting/Rules/CopyrightHeaderRule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private List<string> GetExistingHeader(SyntaxTriviaList triviaList)
7979
{
8080
headerList.Add(GetCommentText(triviaList[i].ToFullString()));
8181
i++;
82+
MovePastBlankLines(triviaList, ref i);
8283
}
8384

8485
return headerList;

0 commit comments

Comments
 (0)