Skip to content

Commit d1a6ffb

Browse files
committed
Port pull request #1962 to stabilization
SA1303 should not report on enum members (cherry picked from commit 633bafa)
1 parent 7be4a33 commit d1a6ffb

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1303UnitTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ public async Task TestFieldWhichIsNotConstStartingWithLowerCaseAsync()
199199
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
200200
}
201201

202+
/// <summary>
203+
/// Regression test for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/1936.
204+
/// </summary>
205+
/// <remarks>SA1303 should not be reported on <c>enum</c> declarations. SA1300 will be reported in this case.</remarks>
206+
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
207+
[Fact]
208+
public async Task TestEnumDeclarationsDoNotReportAsync()
209+
{
210+
var testCode = @"
211+
public enum SpecialFile
212+
{
213+
iTunesMetadata
214+
}";
215+
216+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
217+
218+
}
219+
202220
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
203221
{
204222
yield return new SA1303ConstFieldNamesMustBeginWithUpperCaseLetter();

StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1303ConstFieldNamesMustBeginWithUpperCaseLetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void HandleFieldDeclaration(SymbolAnalysisContext context)
7171
{
7272
var symbol = context.Symbol as IFieldSymbol;
7373

74-
if (symbol == null || !symbol.IsConst)
74+
if (symbol == null || !symbol.IsConst || symbol.ContainingType?.TypeKind == TypeKind.Enum)
7575
{
7676
return;
7777
}

0 commit comments

Comments
 (0)