Skip to content

Commit 9cfb5e0

Browse files
committed
Enable SA1641 code fix
1 parent b5f676f commit 9cfb5e0

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1641UnitTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ public async Task TestCopyrightElementWithWrongCompanyAttributeAsync()
2525
// Copyright (c) FooCorp. All rights reserved.
2626
// </copyright>
2727
28+
namespace Bar
29+
{
30+
}
31+
";
32+
var fixedCode = @"// <copyright file=""Test0.cs"" company=""FooCorp"">
33+
// Copyright (c) FooCorp. All rights reserved.
34+
// </copyright>
35+
2836
namespace Bar
2937
{
3038
}
3139
";
3240

3341
var expectedDiagnostic = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1641Descriptor).WithLocation(1, 4);
3442
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None).ConfigureAwait(false);
43+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
44+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
3545
}
3646

3747
/// <summary>
@@ -45,18 +55,28 @@ public async Task TestCopyrightElementWithInvalidCaseCompanyAttributeAsync()
4555
// Copyright (c) FooCorp. All rights reserved.
4656
// </copyright>
4757
58+
namespace Bar
59+
{
60+
}
61+
";
62+
var fixedCode = @"// <copyright file=""Test0.cs"" company=""FooCorp"">
63+
// Copyright (c) FooCorp. All rights reserved.
64+
// </copyright>
65+
4866
namespace Bar
4967
{
5068
}
5169
";
5270

5371
var expectedDiagnostic = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1641Descriptor).WithLocation(1, 4);
5472
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None).ConfigureAwait(false);
73+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
74+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
5575
}
5676

5777
protected override CodeFixProvider GetCSharpCodeFixProvider()
5878
{
59-
throw new System.NotImplementedException();
79+
return new FileHeaderCodeFixProvider();
6080
}
6181
}
6282
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ internal class FileHeaderCodeFixProvider : CodeFixProvider
3535
FileHeaderAnalyzers.SA1633DescriptorMissing.Id,
3636
FileHeaderAnalyzers.SA1634Descriptor.Id,
3737
FileHeaderAnalyzers.SA1635Descriptor.Id,
38-
FileHeaderAnalyzers.SA1636Descriptor.Id);
38+
FileHeaderAnalyzers.SA1636Descriptor.Id,
39+
FileHeaderAnalyzers.SA1641Descriptor.Id);
3940

4041
/// <inheritdoc/>
4142
public override FixAllProvider GetFixAllProvider()

0 commit comments

Comments
 (0)