Showing 27 of 513 total issues
File ConstructorArgumentsShouldMatchAnalyzer.cs
has 321 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
using System.Diagnostics.CodeAnalysis;
namespace Moq.Analyzers;
/// <summary>
Method AnyConstructorsFound
has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring. Open
Open
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "This should be refactored; suppressing for now to enable TreatWarningsAsErrors in CI.")]
private static bool AnyConstructorsFound(
IMethodSymbol[] constructors,
ArgumentSyntax[] arguments,
SyntaxNodeAnalysisContext context)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method AnyConstructorsFound
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "This should be refactored; suppressing for now to enable TreatWarningsAsErrors in CI.")]
private static bool AnyConstructorsFound(
IMethodSymbol[] constructors,
ArgumentSyntax[] arguments,
SyntaxNodeAnalysisContext context)
Method Analyze
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Should be fixed. Ignoring for now to avoid additional churn as part of larger refactor.")]
private static void Analyze(SyntaxNodeAnalysisContext context)
{
InvocationExpressionSyntax setupInvocation = (InvocationExpressionSyntax)context.Node;
Method GetAllMatchingSymbols
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static List<T> GetAllMatchingSymbols<T>(this SemanticModel semanticModel, ExpressionSyntax expression)
where T : class
{
List<T> matchingSymbols = new();
Method Analyze
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static void Analyze(SyntaxNodeAnalysisContext context)
{
// Check Moq version and skip analysis if the version is 4.16.0 or later
AssemblyIdentity? moqAssembly = context.Compilation.ReferencedAssemblyNames.FirstOrDefault(a => a.Name.Equals("Moq", StringComparison.OrdinalIgnoreCase));
Method AnalyzeInvocation
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static void AnalyzeInvocation(
SyntaxNodeAnalysisContext context,
MoqKnownSymbols knownSymbols,
InvocationExpressionSyntax invocationExpressionSyntax)
{
Method FixCallbackSignatureAsync
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static async Task<Document> FixCallbackSignatureAsync(SyntaxNode root, Document document, ParameterListSyntax? oldParameters, CancellationToken cancellationToken)
{
SemanticModel? semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
if (semanticModel is null)
Method RegisterCompilationStartAction
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static void RegisterCompilationStartAction(CompilationStartAnalysisContext context)
{
MoqKnownSymbols knownSymbols = new(context.Compilation);
// Ensure Moq is referenced in the compilation
Method Analyze
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static void Analyze(SyntaxNodeAnalysisContext context)
{
ObjectCreationExpressionSyntax objectCreation = (ObjectCreationExpressionSyntax)context.Node;
// TODO Think how to make this piece more elegant while fast
Method AnalyzeNewObject
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static void AnalyzeNewObject(OperationAnalysisContext context, ImmutableArray<INamedTypeSymbol> mockTypes, INamedTypeSymbol mockBehaviorSymbol)
{
if (context.Operation is not IObjectCreationOperation creationOperation)
{
return;
Method CreateDiagnostic
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
this Location location,
DiagnosticDescriptor rule,
IEnumerable<Location>? additionalLocations,
ImmutableDictionary<string, string?>? properties,
params object?[]? messageArgs)
Method CreateDiagnostic
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
this SyntaxNode node,
DiagnosticDescriptor rule,
IEnumerable<Location>? additionalLocations,
ImmutableDictionary<string, string?>? properties,
params object?[]? messageArgs) => node
Method CreateDiagnostic
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
this IOperation operation,
DiagnosticDescriptor rule,
IEnumerable<Location>? additionalLocations,
ImmutableDictionary<string, string?>? properties,
params object?[]? messageArgs) => operation.Syntax.CreateDiagnostic(rule, additionalLocations, properties, messageArgs);
Consider simplifying this complex logical expression. Open
Open
if ((arguments.Length < fixedParametersCount
|| (!hasParams && arguments.Length > fixedParametersCount)
|| (!hasParams && arguments.Length != fixedParametersCount))
&& requiredParameters != arguments.Length)
{
Method CreateDiagnostic
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
this SyntaxNode node,
DiagnosticDescriptor rule,
ImmutableDictionary<string, string?>? properties,
params object?[]? messageArgs) => node.CreateDiagnostic(rule, additionalLocations: null, properties, messageArgs);
Method CreateDiagnostic
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
this IOperation operation,
DiagnosticDescriptor rule,
ImmutableDictionary<string, string?>? properties,
params object?[]? messageArgs) => operation.CreateDiagnostic(rule, additionalLocations: null, properties, messageArgs);
Method CreateDiagnostic
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
this Location location,
DiagnosticDescriptor rule,
ImmutableDictionary<string, string?>? properties,
params object?[]? messageArgs) => location.CreateDiagnostic(rule, additionalLocations: null, properties, messageArgs);
Avoid too many return
statements within this method. Open
Open
return;
Avoid too many return
statements within this method. Open
Open
return;