Skip to content

Commit 3246839

Browse files
committed
SA1303 should not report on enum members
1 parent e60c596 commit 3246839

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

4+
using System.Threading.Tasks;
45
namespace StyleCop.Analyzers.Test.NamingRules
56
{
67
using System.Collections.Generic;
@@ -199,6 +200,24 @@ public async Task TestFieldWhichIsNotConstStartingWithLowerCaseAsync()
199200
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
200201
}
201202

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