Skip to content

Commit a71c67d

Browse files
committed
Enable SA1640 code fix
1 parent 9cfb5e0 commit a71c67d

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1640UnitTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ public async Task TestCopyrightElementWithoutCompanyAttributeAsync()
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.SA1640Descriptor).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,13 +55,23 @@ public async Task TestCopyrightElementWithEmptyCompanyAttributeAsync()
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.SA1640Descriptor).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
/// <summary>
@@ -65,18 +85,28 @@ public async Task TestCopyrightElementWithWhitespaceOnlyCompanyAttributeAsync()
6585
// Copyright (c) FooCorp. All rights reserved.
6686
// </copyright>
6787
88+
namespace Bar
89+
{
90+
}
91+
";
92+
var fixedCode = @"// <copyright file=""Test0.cs"" company=""FooCorp"">
93+
// Copyright (c) FooCorp. All rights reserved.
94+
// </copyright>
95+
6896
namespace Bar
6997
{
7098
}
7199
";
72100

73101
var expectedDiagnostic = this.CSharpDiagnostic(FileHeaderAnalyzers.SA1640Descriptor).WithLocation(1, 4);
74102
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostic, CancellationToken.None).ConfigureAwait(false);
103+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
104+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
75105
}
76106

77107
protected override CodeFixProvider GetCSharpCodeFixProvider()
78108
{
79-
throw new System.NotImplementedException();
109+
return new FileHeaderCodeFixProvider();
80110
}
81111
}
82112
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ internal class FileHeaderCodeFixProvider : CodeFixProvider
3636
FileHeaderAnalyzers.SA1634Descriptor.Id,
3737
FileHeaderAnalyzers.SA1635Descriptor.Id,
3838
FileHeaderAnalyzers.SA1636Descriptor.Id,
39+
FileHeaderAnalyzers.SA1640Descriptor.Id,
3940
FileHeaderAnalyzers.SA1641Descriptor.Id);
4041

4142
/// <inheritdoc/>

0 commit comments

Comments
 (0)