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

Remove ECS0200 suppression and update WellKnownTypes to not trigger ECS0600 #236

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 11 additions & 11 deletions src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,18 @@
return;
}

switch (genericNameSyntax.Identifier.Value)
if (genericNameSyntax.Identifier.Value is not string genericNameSyntaxIdentifierValue)
{
case WellKnownTypeNames.Create:
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.MockFactory, true, true);
break;

case WellKnownTypeNames.Of:
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.MockName, false, true);
break;
return;
}
rjmurillo marked this conversation as resolved.
Show resolved Hide resolved

default:
return;
if (string.Equals(genericNameSyntaxIdentifierValue, WellKnownTypeNames.Create, StringComparison.Ordinal))
{
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.MockFactory, true, true);
}
else if (string.Equals(genericNameSyntaxIdentifierValue, WellKnownTypeNames.Of, StringComparison.Ordinal))

Check failure on line 217 in src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Analyzers/ConstructorArgumentsShouldMatchAnalyzer.cs#L217

Add the missing 'else' clause with either the appropriate action or a suitable comment as to why no action is taken.
{
AnalyzeInvocation(context, invocationExpressionSyntax, WellKnownTypeNames.Mock, false, true);
rjmurillo marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -286,7 +286,7 @@
// Quick check
if (!string.Equals(
genericNameSyntax.Identifier.ValueText,
WellKnownTypeNames.MockName,
WellKnownTypeNames.Mock,
StringComparison.Ordinal))
{
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/MoqMethodDescriptorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
internal abstract class MoqMethodDescriptorBase
{
private static readonly string ContainingNamespace = WellKnownTypeNames.Moq;
private static readonly string ContainingType = WellKnownTypeNames.MockName;
private static readonly string ContainingType = WellKnownTypeNames.Mock;

public abstract bool IsMatch(SemanticModel semanticModel, MemberAccessExpressionSyntax memberAccessSyntax, CancellationToken cancellationToken);

rjmurillo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
24 changes: 11 additions & 13 deletions src/Common/WellKnownTypeNames.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
namespace Moq.Analyzers.Common;

#pragma warning disable ECS0200 // Consider using readonly instead of const for flexibility

internal static class WellKnownTypeNames
{
internal const string Moq = nameof(Moq);
internal const string MockName = "Mock";
internal const string MockBehavior = nameof(MockBehavior);
internal const string MockFactory = nameof(MockFactory);
internal const string MoqMock = $"{Moq}.{MockName}";
internal const string MoqMock1 = $"{MoqMock}`1";
internal const string MoqBehavior = $"{Moq}.{MockBehavior}";
internal const string MoqRepository = $"{Moq}.MockRepository";
internal const string As = nameof(As);
internal const string Create = nameof(Create);
internal const string Of = nameof(Of);
internal static readonly string Moq = nameof(Moq);
MattKotsenas marked this conversation as resolved.
Show resolved Hide resolved
internal static readonly string Mock = nameof(Mock);
rjmurillo marked this conversation as resolved.
Show resolved Hide resolved
internal static readonly string MockBehavior = nameof(MockBehavior);
internal static readonly string MockFactory = nameof(MockFactory);
internal static readonly string MoqMock = $"{Moq}.{Mock}";
internal static readonly string MoqMock1 = $"{MoqMock}`1";
internal static readonly string MoqBehavior = $"{Moq}.{MockBehavior}";
internal static readonly string MoqRepository = $"{Moq}.MockRepository";
internal static readonly string As = nameof(As);
internal static readonly string Create = nameof(Create);
internal static readonly string Of = nameof(Of);
}