rjmurillo/moq.analyzers

View on GitHub

Showing 487 of 513 total issues

File ConstructorArgumentsShouldMatchAnalyzer.cs has 321 lines of code (exceeds 250 allowed). Consider refactoring.
Open

using System.Diagnostics.CodeAnalysis;

namespace Moq.Analyzers;

/// <summary>
Severity: Minor
Found in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs - About 3 hrs to fix

    Method AnyConstructorsFound has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
    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)
    Severity: Minor
    Found in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs - About 3 hrs to fix

    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

        [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)
    Severity: Major
    Found in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs - About 2 hrs to fix

      Method Analyze has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      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;
      
      
      Severity: Minor
      Found in src/Analyzers/SetupShouldBeUsedOnlyForOverridableMembersAnalyzer.cs - About 1 hr to fix

        Method GetAllMatchingSymbols has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static List<T> GetAllMatchingSymbols<T>(this SemanticModel semanticModel, ExpressionSyntax expression)
                where T : class
            {
                List<T> matchingSymbols = new();
        
        
        Severity: Minor
        Found in src/Common/SemanticModelExtensions.cs - About 1 hr to fix

          Method Analyze has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          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));
          
          
          Severity: Minor
          Found in src/Analyzers/SetupShouldNotIncludeAsyncResultAnalyzer.cs - About 1 hr to fix

            Method AnalyzeInvocation has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static void AnalyzeInvocation(
                    SyntaxNodeAnalysisContext context,
                    MoqKnownSymbols knownSymbols,
                    InvocationExpressionSyntax invocationExpressionSyntax)
                {
            Severity: Minor
            Found in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs - About 1 hr to fix

              Method FixCallbackSignatureAsync has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              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)
              Severity: Minor
              Found in src/CodeFixes/CallbackSignatureShouldMatchMockedMethodCodeFix.cs - About 1 hr to fix

                Method RegisterCompilationStartAction has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private static void RegisterCompilationStartAction(CompilationStartAnalysisContext context)
                    {
                        MoqKnownSymbols knownSymbols = new(context.Compilation);
                
                        // Ensure Moq is referenced in the compilation
                Severity: Minor
                Found in src/Analyzers/SetExplicitMockBehaviorAnalyzer.cs - About 1 hr to fix

                  Method Analyze has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private static void Analyze(SyntaxNodeAnalysisContext context)
                      {
                          ObjectCreationExpressionSyntax objectCreation = (ObjectCreationExpressionSyntax)context.Node;
                  
                          // TODO Think how to make this piece more elegant while fast
                  Severity: Minor
                  Found in src/Analyzers/NoSealedClassMocksAnalyzer.cs - About 1 hr to fix

                    Method AnalyzeNewObject has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private static void AnalyzeNewObject(OperationAnalysisContext context, ImmutableArray<INamedTypeSymbol> mockTypes, INamedTypeSymbol mockBehaviorSymbol)
                        {
                            if (context.Operation is not IObjectCreationOperation creationOperation)
                            {
                                return;
                    Severity: Minor
                    Found in src/Analyzers/SetExplicitMockBehaviorAnalyzer.cs - About 1 hr to fix

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          private static void VerifyDelegateMockAttempt(
                          SyntaxNodeAnalysisContext context,
                          ArgumentListSyntax? argumentList,
                          ArgumentSyntax[] arguments)
                          {
                      Severity: Minor
                      Found in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs and 1 other location - About 55 mins to fix
                      src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs on lines 126..142

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 83.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                          private static void VerifyInterfaceMockAttempt(
                              SyntaxNodeAnalysisContext context,
                              ArgumentListSyntax? argumentList,
                              ArgumentSyntax[] arguments)
                          {
                      Severity: Minor
                      Found in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs and 1 other location - About 55 mins to fix
                      src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs on lines 109..124

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 83.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Method CreateDiagnostic has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                              this Location location,
                              DiagnosticDescriptor rule,
                              IEnumerable<Location>? additionalLocations,
                              ImmutableDictionary<string, string?>? properties,
                              params object?[]? messageArgs)
                      Severity: Minor
                      Found in src/Common/DiagnosticExtensions.cs - About 45 mins to fix

                        Method CreateDiagnostic has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                                this SyntaxNode node,
                                DiagnosticDescriptor rule,
                                IEnumerable<Location>? additionalLocations,
                                ImmutableDictionary<string, string?>? properties,
                                params object?[]? messageArgs) => node
                        Severity: Minor
                        Found in src/Common/DiagnosticExtensions.cs - About 45 mins to fix

                          Method CreateDiagnostic has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                                  this IOperation operation,
                                  DiagnosticDescriptor rule,
                                  IEnumerable<Location>? additionalLocations,
                                  ImmutableDictionary<string, string?>? properties,
                                  params object?[]? messageArgs) => operation.Syntax.CreateDiagnostic(rule, additionalLocations, properties, messageArgs);
                          Severity: Minor
                          Found in src/Common/DiagnosticExtensions.cs - About 45 mins to fix

                            Consider simplifying this complex logical expression.
                            Open

                                        if ((arguments.Length < fixedParametersCount
                                             || (!hasParams && arguments.Length > fixedParametersCount)
                                             || (!hasParams && arguments.Length != fixedParametersCount))
                                            && requiredParameters != arguments.Length)
                                        {
                            Severity: Major
                            Found in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs - About 40 mins to fix

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                      foreach (IArgumentOperation argument in invocationOperation.Arguments)
                                      {
                                          if (argument.Value is IFieldReferenceOperation fieldReferenceOperation)
                                          {
                                              ISymbol field = fieldReferenceOperation.Member;
                              Severity: Minor
                              Found in src/Analyzers/SetExplicitMockBehaviorAnalyzer.cs and 1 other location - About 40 mins to fix
                              src/Analyzers/SetExplicitMockBehaviorAnalyzer.cs on lines 89..99

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 68.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                      foreach (IArgumentOperation argument in creationOperation.Arguments)
                                      {
                                          if (argument.Value is IFieldReferenceOperation fieldReferenceOperation)
                                          {
                                              ISymbol field = fieldReferenceOperation.Member;
                              Severity: Minor
                              Found in src/Analyzers/SetExplicitMockBehaviorAnalyzer.cs and 1 other location - About 40 mins to fix
                              src/Analyzers/SetExplicitMockBehaviorAnalyzer.cs on lines 117..127

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 68.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Method CreateDiagnostic has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                      this SyntaxNode node,
                                      DiagnosticDescriptor rule,
                                      ImmutableDictionary<string, string?>? properties,
                                      params object?[]? messageArgs) => node.CreateDiagnostic(rule, additionalLocations: null, properties, messageArgs);
                              Severity: Minor
                              Found in src/Common/DiagnosticExtensions.cs - About 35 mins to fix
                                Severity
                                Category
                                Status
                                Source
                                Language