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

Commit 7882beb

Browse files
committed
Fix SA1503: Braces must not be omitted
1 parent d89aa22 commit 7882beb

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

AsyncUsageAnalyzers/AsyncUsageAnalyzers/Naming/AvoidAsyncSuffixAnalyzer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,25 @@ public void HandleMethodDeclaration(SymbolAnalysisContext context)
6161
{
6262
IMethodSymbol symbol = (IMethodSymbol)context.Symbol;
6363
if (symbol.IsAsync)
64+
{
6465
return;
66+
}
6567

6668
if (!symbol.Name.EndsWith("Async", StringComparison.Ordinal))
69+
{
6770
return;
71+
}
6872

6973
if (symbol.Locations.IsDefaultOrEmpty)
74+
{
7075
return;
76+
}
7177

7278
Location location = symbol.Locations[0];
7379
if (!location.IsInSource || location.SourceTree.IsGeneratedDocument(this.generatedHeaderCache, context.CancellationToken))
80+
{
7481
return;
82+
}
7583

7684
if (!symbol.ReturnsVoid)
7785
{

AsyncUsageAnalyzers/AsyncUsageAnalyzers/Naming/UseAsyncSuffixAnalyzer.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,41 @@ public void HandleMethodDeclaration(SymbolAnalysisContext context)
6161
{
6262
IMethodSymbol symbol = (IMethodSymbol)context.Symbol;
6363
if (symbol.Name.EndsWith("Async", StringComparison.Ordinal))
64+
{
6465
return;
66+
}
6567

6668
if (symbol.Locations.IsDefaultOrEmpty)
69+
{
6770
return;
71+
}
6872

6973
Location location = symbol.Locations[0];
7074
if (!location.IsInSource || location.SourceTree.IsGeneratedDocument(this.generatedHeaderCache, context.CancellationToken))
75+
{
7176
return;
77+
}
7278

7379
// void-returning methods are not asynchronous according to their signature, even if they use `async`
7480
if (symbol.ReturnsVoid)
81+
{
7582
return;
83+
}
7684

7785
if (!string.Equals(nameof(Task), symbol.ReturnType?.Name, StringComparison.Ordinal))
86+
{
7887
return;
88+
}
7989

8090
if (!string.Equals(typeof(Task).Namespace, symbol.ReturnType?.ContainingNamespace?.ToString(), StringComparison.Ordinal))
91+
{
8192
return;
93+
}
8294

8395
if (symbol.MethodKind == MethodKind.PropertyGet || symbol.MethodKind == MethodKind.PropertySet)
96+
{
8497
return;
98+
}
8599

86100
context.ReportDiagnostic(Diagnostic.Create(Descriptor, symbol.Locations[0], symbol.Name));
87101
}

AsyncUsageAnalyzers/AsyncUsageAnalyzers/Reliability/AvoidAsyncVoidAnalyzer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,26 @@ private static void HandleAnonymousFunctionExpression(SyntaxNodeAnalysisContext
6262
{
6363
AnonymousFunctionExpressionSyntax node = (AnonymousFunctionExpressionSyntax)context.Node;
6464
if (node.AsyncKeyword.IsKind(SyntaxKind.None) || node.AsyncKeyword.IsMissing)
65+
{
6566
return;
67+
}
6668

6769
TypeInfo typeInfo = context.SemanticModel.GetTypeInfo(node);
6870
INamedTypeSymbol convertedType = typeInfo.ConvertedType as INamedTypeSymbol;
6971
if (convertedType == null)
72+
{
7073
return;
74+
}
7175

7276
if (convertedType.TypeKind != TypeKind.Delegate || convertedType.DelegateInvokeMethod == null)
77+
{
7378
return;
79+
}
7480

7581
if (!convertedType.DelegateInvokeMethod.ReturnsVoid)
82+
{
7683
return;
84+
}
7785

7886
context.ReportDiagnostic(Diagnostic.Create(Descriptor, node.AsyncKeyword.GetLocation(), "<anonymous>"));
7987
}
@@ -91,11 +99,15 @@ public void HandleMethodDeclaration(SymbolAnalysisContext context)
9199
{
92100
IMethodSymbol symbol = (IMethodSymbol)context.Symbol;
93101
if (!symbol.IsAsync || !symbol.ReturnsVoid)
102+
{
94103
return;
104+
}
95105

96106
Location location = symbol.Locations[0];
97107
if (!location.IsInSource || location.SourceTree.IsGeneratedDocument(this.generatedHeaderCache, context.CancellationToken))
108+
{
98109
return;
110+
}
99111

100112
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, symbol.Name));
101113
}

AsyncUsageAnalyzers/AsyncUsageAnalyzers/Usage/UseConfigureAwaitAnalyzer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ private static void HandleAwaitExpression(SyntaxNodeAnalysisContext context)
5555
AwaitExpressionSyntax syntax = (AwaitExpressionSyntax)context.Node;
5656
ExpressionSyntax expression = syntax.Expression;
5757
if (!IsTask(expression, context.SemanticModel))
58+
{
5859
return;
60+
}
5961

6062
context.ReportDiagnostic(Diagnostic.Create(Descriptor, expression.GetLocation()));
6163
}
@@ -64,7 +66,9 @@ private static bool IsTask(ExpressionSyntax expression, SemanticModel semanticMo
6466
{
6567
var type = semanticModel.GetTypeInfo(expression).Type as INamedTypeSymbol;
6668
if (type == null)
69+
{
6770
return false;
71+
}
6872

6973
INamedTypeSymbol taskType;
7074
if (type.IsGenericType)

0 commit comments

Comments
 (0)