Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit db8f860

Browse files
committed
[#21] Allowing UseAsyncSuffixAnalyzer to ignore property getter and setters;
1 parent 79ddddc commit db8f860

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

AsyncUsageAnalyzers/AsyncUsageAnalyzers.Test/Naming/UseAsyncSuffixUnitTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ class ClassName
143143
await VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
144144
}
145145

146+
[Fact]
147+
public async Task TestPropertyGetterAndSetterTaskAsync()
148+
{
149+
string testCode = @"
150+
using System.Threading.Tasks;
151+
class ClassName
152+
{
153+
public Task<string> TaskString { get; set; }
154+
}
155+
";
156+
await VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
157+
}
158+
146159
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
147160
{
148161
return new UseAsyncSuffixAnalyzer();

AsyncUsageAnalyzers/AsyncUsageAnalyzers/Naming/UseAsyncSuffixAnalyzer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ private void HandleMethodDeclaration(SymbolAnalysisContext context)
5858
if (!string.Equals(typeof(Task).Namespace, symbol.ReturnType?.ContainingNamespace?.ToString(), StringComparison.Ordinal))
5959
return;
6060

61+
if (symbol.MethodKind == MethodKind.PropertyGet || symbol.MethodKind == MethodKind.PropertySet)
62+
return;
63+
6164
context.ReportDiagnostic(Diagnostic.Create(Descriptor, symbol.Locations[0], symbol.Name));
6265
}
6366
}

0 commit comments

Comments
 (0)