-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
There is mixed use of explicit types and var keyword. There are also cases where the var keyword cannot be used. Rather than have mixed cases, update all code to use explicit types and enable .editorconfig rule to enforce code style Fixes #53
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ internal static bool IsMoqAsMethod(SemanticModel semanticModel, MemberAccessExpr | |
|
||
internal static bool IsCallbackOrReturnInvocation(SemanticModel semanticModel, InvocationExpressionSyntax callbackOrReturnsInvocation) | ||
{ | ||
var callbackOrReturnsMethod = callbackOrReturnsInvocation.Expression as MemberAccessExpressionSyntax; | ||
MemberAccessExpressionSyntax? callbackOrReturnsMethod = callbackOrReturnsInvocation.Expression as MemberAccessExpressionSyntax; | ||
|
||
Debug.Assert(callbackOrReturnsMethod != null, nameof(callbackOrReturnsMethod) + " != null"); | ||
|
||
|
@@ -30,7 +30,7 @@ internal static bool IsCallbackOrReturnInvocation(SemanticModel semanticModel, I | |
return false; | ||
} | ||
|
||
var methodName = callbackOrReturnsMethod.Name.ToString(); | ||
string? methodName = callbackOrReturnsMethod.Name.ToString(); | ||
|
||
// First fast check before walking semantic model | ||
if (!string.Equals(methodName, "Callback", StringComparison.Ordinal) | ||
|
@@ -39,7 +39,7 @@ internal static bool IsCallbackOrReturnInvocation(SemanticModel semanticModel, I | |
return false; | ||
} | ||
|
||
var symbolInfo = semanticModel.GetSymbolInfo(callbackOrReturnsMethod); | ||
SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(callbackOrReturnsMethod); | ||
return symbolInfo.CandidateReason switch | ||
{ | ||
CandidateReason.OverloadResolutionFailure => symbolInfo.CandidateSymbols.Any(IsCallbackOrReturnSymbol), | ||
|
@@ -50,39 +50,39 @@ internal static bool IsCallbackOrReturnInvocation(SemanticModel semanticModel, I | |
|
||
internal static InvocationExpressionSyntax? FindSetupMethodFromCallbackInvocation(SemanticModel semanticModel, ExpressionSyntax expression) | ||
{ | ||
var invocation = expression as InvocationExpressionSyntax; | ||
InvocationExpressionSyntax? invocation = expression as InvocationExpressionSyntax; | ||
if (invocation?.Expression is not MemberAccessExpressionSyntax method) return null; | ||
if (IsMoqSetupMethod(semanticModel, method)) return invocation; | ||
return FindSetupMethodFromCallbackInvocation(semanticModel, method.Expression); | ||
} | ||
|
||
internal static InvocationExpressionSyntax? FindMockedMethodInvocationFromSetupMethod(InvocationExpressionSyntax? setupInvocation) | ||
{ | ||
var setupLambdaArgument = setupInvocation?.ArgumentList.Arguments[0].Expression as LambdaExpressionSyntax; | ||
LambdaExpressionSyntax? setupLambdaArgument = setupInvocation?.ArgumentList.Arguments[0].Expression as LambdaExpressionSyntax; | ||
return setupLambdaArgument?.Body as InvocationExpressionSyntax; | ||
} | ||
|
||
internal static ExpressionSyntax? FindMockedMemberExpressionFromSetupMethod(InvocationExpressionSyntax? setupInvocation) | ||
{ | ||
var setupLambdaArgument = setupInvocation?.ArgumentList.Arguments[0].Expression as LambdaExpressionSyntax; | ||
LambdaExpressionSyntax? setupLambdaArgument = setupInvocation?.ArgumentList.Arguments[0].Expression as LambdaExpressionSyntax; | ||
return setupLambdaArgument?.Body as ExpressionSyntax; | ||
} | ||
|
||
internal static IEnumerable<IMethodSymbol> GetAllMatchingMockedMethodSymbolsFromSetupMethodInvocation(SemanticModel semanticModel, InvocationExpressionSyntax? setupMethodInvocation) | ||
{ | ||
var setupLambdaArgument = setupMethodInvocation?.ArgumentList.Arguments[0].Expression as LambdaExpressionSyntax; | ||
var mockedMethodInvocation = setupLambdaArgument?.Body as InvocationExpressionSyntax; | ||
LambdaExpressionSyntax? setupLambdaArgument = setupMethodInvocation?.ArgumentList.Arguments[0].Expression as LambdaExpressionSyntax; | ||
InvocationExpressionSyntax? mockedMethodInvocation = setupLambdaArgument?.Body as InvocationExpressionSyntax; | ||
|
||
return GetAllMatchingSymbols<IMethodSymbol>(semanticModel, mockedMethodInvocation); | ||
} | ||
|
||
internal static IEnumerable<T> GetAllMatchingSymbols<T>(SemanticModel semanticModel, ExpressionSyntax? expression) | ||
where T : class | ||
{ | ||
var matchingSymbols = new List<T>(); | ||
List<T>? matchingSymbols = new List<T>(); | ||
if (expression != null) | ||
{ | ||
var symbolInfo = semanticModel.GetSymbolInfo(expression); | ||
SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(expression); | ||
if (symbolInfo is { CandidateReason: CandidateReason.None, Symbol: T }) | ||
{ | ||
matchingSymbols.Add(symbolInfo.Symbol as T); | ||
Check warning on line 88 in Source/Moq.Analyzers/Helpers.cs GitHub Actions / build (windows-2022)
Check warning on line 88 in Source/Moq.Analyzers/Helpers.cs GitHub Actions / build (ubuntu-22.04)
Check warning on line 88 in Source/Moq.Analyzers/Helpers.cs GitHub Actions / build (windows-2022)
|
||
|
@@ -100,7 +100,7 @@ private static bool IsCallbackOrReturnSymbol(ISymbol? symbol) | |
{ | ||
// TODO: Check what is the best way to do such checks | ||
Check warning on line 101 in Source/Moq.Analyzers/Helpers.cs GitHub Actions / build (windows-2022)
Check warning on line 101 in Source/Moq.Analyzers/Helpers.cs GitHub Actions / build (ubuntu-22.04)
Check warning on line 101 in Source/Moq.Analyzers/Helpers.cs GitHub Actions / build (windows-2022)
Check warning on line 101 in Source/Moq.Analyzers/Helpers.cs GitHub Actions / build (ubuntu-22.04)
|
||
if (symbol is not IMethodSymbol methodSymbol) return false; | ||
var methodName = methodSymbol.ToString(); | ||
string? methodName = methodSymbol.ToString(); | ||
return methodName.StartsWith("Moq.Language.ICallback", StringComparison.Ordinal) | ||
|| methodName.StartsWith("Moq.Language.IReturns", StringComparison.Ordinal); | ||
} | ||
|