Skip to content

Commit 2a4f664

Browse files
committed
Enable FileHeaderCodeFixProvider for SA1635 (FileHeaderMustHaveCopyrightText)
1 parent 2a495dc commit 2a4f664

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/NoXmlFileHeaderUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ namespace Bar
159159
var expected = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1635Descriptor).WithLocation(1, 1);
160160
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
161161
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
162-
////await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
162+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
163163
}
164164

165165
/// <summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1635UnitTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@ public async Task TestFileHeaderWithShorthandCopyrightAsync()
2323
{
2424
var testCode = @"// <copyright file=""Test0.cs"" company=""FooCorp""/>
2525
26+
namespace Bar
27+
{
28+
}
29+
";
30+
var fixedCode = @"// <copyright file=""Test0.cs"" company=""FooCorp"">
31+
// Copyright (c) FooCorp. All rights reserved.
32+
// </copyright>
33+
2634
namespace Bar
2735
{
2836
}
2937
";
3038

3139
var expectedDiagnostic = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1635Descriptor).WithLocation(1, 4);
3240
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None).ConfigureAwait(false);
41+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
42+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
3343
}
3444

3545
/// <summary>
@@ -47,14 +57,25 @@ public async Task TestFileHeaderWithWhitespaceOnlyCopyrightAsync()
4757
"namespace Bar\r\n" +
4858
"{\r\n" +
4959
"}\r\n";
60+
string fixedCode =
61+
"// <copyright file=\"Test0.cs\" company=\"FooCorp\">\r\n" +
62+
"// Copyright (c) FooCorp. All rights reserved.\r\n" +
63+
"// </copyright>\r\n" +
64+
"\r\n" +
65+
"namespace Bar\r\n" +
66+
"{\r\n" +
67+
"}\r\n";
5068

5169
var expectedDiagnostic = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1635Descriptor).WithLocation(1, 4);
5270
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None).ConfigureAwait(false);
71+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
72+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
5373
}
5474

75+
/// <inheritdoc/>
5576
protected override CodeFixProvider GetCSharpCodeFixProvider()
5677
{
57-
throw new System.NotImplementedException();
78+
return new FileHeaderCodeFixProvider();
5879
}
5980
}
6081
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/FileHeaderCodeFixProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class FileHeaderCodeFixProvider : CodeFixProvider
3030
public override ImmutableArray<string> FixableDiagnosticIds { get; }
3131
= ImmutableArray.Create(
3232
FileHeaderAnalyzers.SA1633DescriptorMissing.Id,
33+
FileHeaderAnalyzers.SA1635Descriptor.Id,
3334
FileHeaderAnalyzers.SA1636Descriptor.Id);
3435

3536
/// <inheritdoc/>

0 commit comments

Comments
 (0)