This repository was archived by the owner on Jul 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Microsoft.DotNet.CodeFormatting.Tests/Rules
Microsoft.DotNet.CodeFormatting/Rules Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,28 @@ class C
157
157
158
158
var expected = @"// test
159
159
160
+ class C
161
+ {
162
+ }" ;
163
+ Verify ( source , expected ) ;
164
+ }
165
+
166
+ [ Fact ]
167
+ public void CSharpHeaderBeginsWithTargetHeader ( )
168
+ {
169
+ _options . CopyrightHeader = ImmutableArray . Create ( "// test" , "// test2" ) ;
170
+ var source = @"// test
171
+ // test2
172
+ // file summary
173
+
174
+ class C
175
+ {
176
+ }" ;
177
+
178
+ var expected = @"// test
179
+ // test2
180
+ // file summary
181
+
160
182
class C
161
183
{
162
184
}" ;
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ internal sealed partial class CopyrightHeaderRule : SyntaxFormattingRule, ISynta
18
18
private abstract class CommonRule
19
19
{
20
20
/// <summary>
21
- /// This is the normalized copyright header that has no comment delimeters .
21
+ /// This is the normalized copyright header that has no comment delimiters .
22
22
/// </summary>
23
23
private readonly ImmutableArray < string > _header ;
24
24
@@ -43,7 +43,18 @@ internal SyntaxNode Process(SyntaxNode syntaxNode)
43
43
private bool HasCopyrightHeader ( SyntaxNode syntaxNode )
44
44
{
45
45
var existingHeader = GetExistingHeader ( syntaxNode . GetLeadingTrivia ( ) ) ;
46
- return _header . SequenceEqual ( existingHeader ) ;
46
+ return SequnceStartsWith ( _header , existingHeader ) ;
47
+ }
48
+
49
+ private bool SequnceStartsWith ( ImmutableArray < string > header , List < string > existingHeader )
50
+ {
51
+ // Only try if the existing header is at least as long as the new copyright header
52
+ if ( existingHeader . Count >= header . Count ( ) )
53
+ {
54
+ return ! header . Where ( ( headerLine , i ) => existingHeader [ i ] != headerLine ) . Any ( ) ;
55
+ }
56
+
57
+ return false ;
47
58
}
48
59
49
60
private SyntaxNode AddCopyrightHeader ( SyntaxNode syntaxNode )
You can’t perform that action at this time.
0 commit comments