Skip to content

Commit

Permalink
Fix SA1312 getting reported for event field declarations
Browse files Browse the repository at this point in the history
Also added regression tests to related rules SA1306 and SA1313.

Fixes DotNetAnalyzers#1340
  • Loading branch information
sharwell committed Aug 31, 2015
1 parent 13682b5 commit c71608e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public async Task TestThatDiagnosticIsNotReportedAsync(string modifiers)
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, modifiers), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestThatDiagnosticIsNotReportedForEventFieldsAsync()
{
var testCode = @"using System;
public class TypeName
{
static event EventHandler bar;
static event EventHandler Bar;
event EventHandler car;
event EventHandler Car;
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestThatDiagnosticIsNotReportedForParametersAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ public async Task TestThatDiagnosticIsNotReportedForFieldsAsync()
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestThatDiagnosticIsNotReportedForEventFieldsAsync()
{
var testCode = @"using System;
public class TypeName
{
static event EventHandler bar;
static event EventHandler Bar;
event EventHandler car;
event EventHandler Car;
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestThatDiagnosticIsNotReportedForParametersAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ public async Task TestThatDiagnosticIsNotReportedForFieldsAsync()
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestThatDiagnosticIsNotReportedForEventFieldsAsync()
{
var testCode = @"using System;
public class TypeName
{
static event EventHandler bar;
static event EventHandler Bar;
event EventHandler car;
event EventHandler Car;
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestThatDiagnosticIsNotReportedForVariablesAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ private static void HandleCompilationStart(CompilationStartAnalysisContext conte
private static void HandleVariableDeclarationSyntax(SyntaxNodeAnalysisContext context)
{
VariableDeclarationSyntax syntax = (VariableDeclarationSyntax)context.Node;
if (syntax.Parent.IsKind(SyntaxKind.FieldDeclaration))
if (syntax.Parent.IsKind(SyntaxKind.FieldDeclaration)
|| syntax.Parent.IsKind(SyntaxKind.EventFieldDeclaration))
{
// This diagnostic is only for local variables.
return;
Expand Down

0 comments on commit c71608e

Please sign in to comment.