Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ConcurrentExecution and disable generated code analysis #70

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public static TAnalyzerTest SetDefaults<TAnalyzerTest, TVerifier>(this TAnalyzer
where TVerifier : IVerifier, new()
{
test.ReferenceAssemblies = ReferenceAssemblies.Net.Net80.AddPackages([new PackageIdentity("Moq", "4.8.2")]); // TODO: See https://github.com/rjmurillo/moq.analyzers/issues/58
test.TestBehaviors = TestBehaviors.SkipGeneratedCodeCheck; // TODO: We should enable the generated code check

return test;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class AsShouldBeUsedOnlyForInterfaceAnalyzer : DiagnosticAnalyzer

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.InvocationExpression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.InvocationExpression);
}

Expand Down Expand Up @@ -57,9 +59,9 @@
for (int i = 0; i < mockedMethodArguments.Count; i++)
{
var mockedMethodArgumentType = context.SemanticModel.GetTypeInfo(mockedMethodArguments[i].Expression, context.CancellationToken);
var lambdaParameterType = context.SemanticModel.GetTypeInfo(lambdaParameters[i].Type, context.CancellationToken);

Check warning on line 62 in Source/Moq.Analyzers/CallbackSignatureShouldMatchMockedMethodAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Possible null reference argument for parameter 'expression' in 'TypeInfo CSharpExtensions.GetTypeInfo(SemanticModel? semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken = default(CancellationToken))'.

Check warning on line 62 in Source/Moq.Analyzers/CallbackSignatureShouldMatchMockedMethodAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Possible null reference argument for parameter 'expression' in 'TypeInfo CSharpExtensions.GetTypeInfo(SemanticModel? semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken = default(CancellationToken))'.
string mockedMethodTypeName = mockedMethodArgumentType.ConvertedType.ToString();

Check warning on line 63 in Source/Moq.Analyzers/CallbackSignatureShouldMatchMockedMethodAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Dereference of a possibly null reference.

Check warning on line 63 in Source/Moq.Analyzers/CallbackSignatureShouldMatchMockedMethodAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Dereference of a possibly null reference.
string lambdaParameterTypeName = lambdaParameterType.ConvertedType.ToString();

Check warning on line 64 in Source/Moq.Analyzers/CallbackSignatureShouldMatchMockedMethodAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Dereference of a possibly null reference.

Check warning on line 64 in Source/Moq.Analyzers/CallbackSignatureShouldMatchMockedMethodAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Dereference of a possibly null reference.
if (mockedMethodTypeName != lambdaParameterTypeName)
{
var diagnostic = Diagnostic.Create(Rule, callbackLambda.ParameterList.GetLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.ObjectCreationExpression);
}

Expand Down Expand Up @@ -45,7 +47,7 @@
if (mockedTypeSymbol == null) return;

// Skip first argument if it is not vararg - typically it is MockingBehavior argument
var constructorArguments = objectCreation.ArgumentList.Arguments.Skip(varArgsConstructorParameterIdx == 0 ? 0 : 1).ToArray();

Check warning on line 50 in Source/Moq.Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Dereference of a possibly null reference.

Check warning on line 50 in Source/Moq.Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Dereference of a possibly null reference.

if (!mockedTypeSymbol.IsAbstract)
{
Expand All @@ -69,7 +71,7 @@
// Check all constructors of the abstract type
foreach (var constructor in mockedTypeSymbol.Constructors)
{
if (AreParametersMatching(constructor.Parameters, argumentTypes))

Check warning on line 74 in Source/Moq.Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Argument of type 'ITypeSymbol?[]' cannot be used for parameter 'argumentTypes2' of type 'ITypeSymbol[]' in 'bool ConstructorArgumentsShouldMatchAnalyzer.AreParametersMatching(ImmutableArray<IParameterSymbol> constructorParameters, ITypeSymbol[] argumentTypes2)' due to differences in the nullability of reference types.
{
return; // Found a matching constructor
}
Expand All @@ -85,7 +87,7 @@
GenericNameSyntax genericName)
{
var typeArguments = genericName.TypeArgumentList.Arguments;
if (typeArguments == null || typeArguments.Count != 1) return null;

Check warning on line 90 in Source/Moq.Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Possible null reference return.
var mockedTypeSymbolInfo = context.SemanticModel.GetSymbolInfo(typeArguments[0], context.CancellationToken);
var mockedTypeSymbol = mockedTypeSymbolInfo.Symbol as INamedTypeSymbol;
if (mockedTypeSymbol == null || mockedTypeSymbol.TypeKind != TypeKind.Class) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.ObjectCreationExpression);
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Moq.Analyzers/NoMethodsInPropertySetupAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.InvocationExpression);
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.ObjectCreationExpression);
}

Expand All @@ -26,11 +28,11 @@
var objectCreation = (ObjectCreationExpressionSyntax)context.Node;

// TODO Think how to make this piece more elegant while fast
GenericNameSyntax genericName = objectCreation.Type as GenericNameSyntax;

Check warning on line 31 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Converting null literal or possible null value to non-nullable type.

Check warning on line 31 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Converting null literal or possible null value to non-nullable type.
if (objectCreation.Type is QualifiedNameSyntax)
{
var qualifiedName = objectCreation.Type as QualifiedNameSyntax;
genericName = qualifiedName.Right as GenericNameSyntax;

Check warning on line 35 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Dereference of a possibly null reference.

Check warning on line 35 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Converting null literal or possible null value to non-nullable type.

Check warning on line 35 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Dereference of a possibly null reference.

Check warning on line 35 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

Converting null literal or possible null value to non-nullable type.
}

if (genericName?.Identifier == null || genericName.TypeArgumentList == null) return;
Expand All @@ -47,7 +49,7 @@

// Find mocked type
var typeArguments = genericName.TypeArgumentList.Arguments;
if (typeArguments == null || typeArguments.Count != 1) return;

Check warning on line 52 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The result of the expression is always 'false' since a value of type 'SeparatedSyntaxList<TypeSyntax>' is never equal to 'null' of type 'SeparatedSyntaxList<TypeSyntax>?'

Check warning on line 52 in Source/Moq.Analyzers/NoSealedClassMocksAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04)

The result of the expression is always 'false' since a value of type 'SeparatedSyntaxList<TypeSyntax>' is never equal to 'null' of type 'SeparatedSyntaxList<TypeSyntax>?'
var symbolInfo = context.SemanticModel.GetSymbolInfo(typeArguments[0], context.CancellationToken);
var symbol = symbolInfo.Symbol as INamedTypeSymbol;
if (symbol == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class SetupShouldBeUsedOnlyForOverridableMembersAnalyzer : DiagnosticAnal

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.InvocationExpression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class SetupShouldNotIncludeAsyncResultAnalyzer : DiagnosticAnalyzer

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.InvocationExpression);
}

Expand Down
Loading