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

refactor: fix analyzer warnings (2) #711

Merged
merged 17 commits into from
Jan 12, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix MA0089: Use an overload with char instead of string
vbreuss committed Jan 12, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 346ac393fb8b60bd194585c3b4f3b62d1986e205
Original file line number Diff line number Diff line change
@@ -29,7 +29,9 @@ internal MethodStatistic(int counter, string name, params ParameterDescription[]
Parameters = parameters;
}

#pragma warning disable MA0089 // Use an overload with char instead of string
/// <inheritdoc cref="object.ToString()" />
public override string ToString()
=> $"{Name}({string.Join(",", Parameters.Select(p => p.ToString()))})";
#pragma warning restore MA0089
}
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ public SpanParameterDescription(ReadOnlySpan<T> value) : base(false)

/// <inheritdoc cref="object.ToString()" />
public override string ToString()
=> $"[{string.Join(",", Value)}]";
=> $"[{string.Join(',', Value)}]";
}
#endif
}
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ private static void AssertExceptionMessage<TException>(TException exception,
{
#pragma warning disable MA0074
Execute.Assertion
.ForCondition(exception.Message.Contains(messageContains, StringComparison.Ordinal))
.ForCondition(exception.Message.Contains(messageContains))
.BecauseOf(because, becauseArgs)
.WithDefaultIdentifier("type")
.FailWith(
Original file line number Diff line number Diff line change
@@ -149,9 +149,12 @@ public static string PrintType(this Type type)

if (type.GenericTypeArguments.Length > 0)
{

#pragma warning disable MA0089 // Use an overload with char instead of string
return type.Name.Substring(0, type.Name.Length - 2) +
"<" + string.Join(",",
type.GenericTypeArguments.Select(x => x.PrintType())) + ">";
#pragma warning restore MA0089
}

return type.Name;
Original file line number Diff line number Diff line change
@@ -24,8 +24,7 @@ public void NormalizePath_Unix_RootedPath_ShouldRemoveDriveInfo(string part1)

MockFileSystem fileSystem = new();

string path =
fileSystem.GetDefaultDrive().Name.Replace("\\", "/", StringComparison.Ordinal) + part1;
string path = fileSystem.GetDefaultDrive().Name.Replace('\\', '/') + part1;
string expectedPath = part1.PrefixRoot(fileSystem);
path = path.NormalizePath(fileSystem);

Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ public void ToString_WithReadOnlySpan_ShouldSetIsOutParameterToFalse(string buff
{
ReadOnlySpan<char> value = buffer.AsSpan();
ParameterDescription sut = ParameterDescription.FromParameter(value);
string expectedString = $"[{string.Join(",", buffer.ToCharArray())}]";
string expectedString = $"[{string.Join(',', buffer.ToCharArray())}]";

string? result = sut.ToString();

@@ -129,7 +129,7 @@ public void ToString_WithSpan_ShouldSetIsOutParameterToFalse(int[] buffer)
{
Span<int> value = buffer.AsSpan();
ParameterDescription sut = ParameterDescription.FromParameter(value);
string expectedString = $"[{string.Join(",", buffer)}]";
string expectedString = $"[{string.Join(',', buffer)}]";

string? result = sut.ToString();

Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ private static void CheckMethodCall(StringBuilder builder,
Type mockType,
Type testType)
{
#pragma warning disable MA0089 // Use an overload with char instead of string
string expectedName = $"Method_{methodInfo.Name}_{string.Join("_", methodInfo
.GetParameters()
.Select(x => FirstCharToUpperAsSpan(GetName(x.ParameterType, true)
@@ -44,6 +45,7 @@ private static void CheckMethodCall(StringBuilder builder,
// ReSharper disable once StringLiteralTypo
.Replace("IEnumerablestring", "IEnumerableString", StringComparison.Ordinal)
.Replace("[]", "Array", StringComparison.Ordinal))))}{(parameters.Length > 0 ? "_" : "")}ShouldRegisterCall";
#pragma warning restore MA0089
if (testType.GetMethod(expectedName) != null)
{
return;
@@ -303,8 +305,10 @@ private static string GetName(Type type, bool firstCharUpperCase)
int idx = type.Name.IndexOf('`', StringComparison.Ordinal);
if (idx > 0)
{
#pragma warning disable MA0089 // Use an overload with char instead of string
return
$"{type.Name.Substring(0, idx)}<{string.Join(",", type.GenericTypeArguments.Select(x => GetName(x, firstCharUpperCase)))}>";
#pragma warning restore MA0089
}

return type.ToString();