Skip to content

Commit

Permalink
Fix ReSharper warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Jan 15, 2022
1 parent a2daa85 commit 3b1a487
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/InlineIL.Fody/Support/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Fody;
using Mono.Cecil.Cil;

// ReSharper disable once RedundantDisableWarningComment
#pragma warning disable CA1032

namespace InlineIL.Fody.Support;
Expand Down
5 changes: 3 additions & 2 deletions src/InlineIL.Tests.InvalidAssemblyToProcess/BasicTestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace InlineIL.Tests.InvalidAssemblyToProcess;

[SuppressMessage("ReSharper", "UnusedType.Global")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "NotAccessedField.Local")]
public class BasicTestCases
{
private int _intField;
Expand Down Expand Up @@ -48,7 +47,9 @@ public void InvalidPushUsage2()
IL.Pop(out int result);
a.foo = result;

static ref (int foo, int bar) GetRefToStruct(int _) => throw new InvalidOperationException();
[SuppressMessage("ReSharper", "UnusedParameter.Local")]
static ref (int foo, int bar) GetRefToStruct(int _)
=> throw new InvalidOperationException();
}

public void InvalidPushUsage3()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace InlineIL.Tests.UnverifiableAssemblyToProcess;
[SuppressMessage("ReSharper", "UnusedType.Global")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
[SuppressMessage("ReSharper", "RedundantAssignment")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "EntityNameCapturedOnly.Global")]
public unsafe class BasicTestCases : IUnverifiableBasicTestCases
Expand Down Expand Up @@ -51,6 +50,7 @@ public int PopPointerLocal(int* arg, int offset)

public int PopPointerArg(int* arg, int offset)
{
_ = arg; // Make ReSharper happy
Ldarg(nameof(arg));
Ldarg(nameof(offset));
Conv_I();
Expand Down Expand Up @@ -87,6 +87,7 @@ public int PopVoidPointerLocal(int* arg, int offset)

public int PopVoidPointerArg(void* arg, int offset)
{
_ = arg; // Make ReSharper happy
Ldarg(nameof(arg));
Ldarg(nameof(offset));
Conv_I();
Expand Down
7 changes: 2 additions & 5 deletions src/InlineIL.Tests/Support/AssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using JetBrains.Annotations;
using Xunit;
using Xunit.Sdk;
using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute;

namespace InlineIL.Tests.Support;

Expand All @@ -25,11 +26,7 @@ public static void ShouldBeNull(this object? actual)
=> Assert.Null(actual);

[ContractAnnotation("null => halt")]
public static T ShouldNotBeNull<T>(
#if NETCOREAPP
[System.Diagnostics.CodeAnalysis.NotNull]
#endif
this T? actual)
public static T ShouldNotBeNull<T>([NotNull] this T? actual)
where T : class
{
Assert.NotNull(actual);
Expand Down
94 changes: 94 additions & 0 deletions src/InlineIL.Tests/Support/Attributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// <auto-generated /> (disable inspections)

#if !NETCOREAPP

namespace System.Diagnostics.CodeAnalysis;

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
internal sealed class AllowNullAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
internal sealed class DisallowNullAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
internal sealed class MaybeNullAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
internal sealed class NotNullAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class MaybeNullWhenAttribute : Attribute
{
public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;

public bool ReturnValue { get; }
}

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class NotNullWhenAttribute : Attribute
{
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;

public bool ReturnValue { get; }
}

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
internal sealed class NotNullIfNotNullAttribute : Attribute
{
public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName;

public string ParameterName { get; }
}

[AttributeUsage(AttributeTargets.Method, Inherited = false)]
internal sealed class DoesNotReturnAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class DoesNotReturnIfAttribute : Attribute
{
public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;

public bool ParameterValue { get; }
}

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
internal sealed class MemberNotNullAttribute : Attribute
{
public MemberNotNullAttribute(string member) => Members = new[] { member };

public MemberNotNullAttribute(params string[] members) => Members = members;

public string[] Members { get; }
}

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new[] { member };
}

public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}

public bool ReturnValue { get; }

public string[] Members { get; }
}

#endif
8 changes: 4 additions & 4 deletions src/InlineIL.Tests/Weaving/FixtureHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ internal static class FixtureHelper
public static string IsolateAssembly<T>()
{
var assembly = typeof(T).Assembly;
var assemblyPath = assembly.Location!;
var assemblyPath = assembly.Location;
var assemblyDir = Path.GetDirectoryName(assemblyPath)!;
var rootTestDir = Path.Combine(assemblyDir, "WeavingTest");
var asmTestDir = Path.Combine(rootTestDir, Path.GetFileNameWithoutExtension(assemblyPath)!);
var asmTestDir = Path.Combine(rootTestDir, Path.GetFileNameWithoutExtension(assemblyPath));

EmptyDirectory(asmTestDir);
Directory.CreateDirectory(asmTestDir);

var destFile = CopyFile(assemblyPath, asmTestDir);
CopyFile(Path.ChangeExtension(assemblyPath, ".pdb")!, asmTestDir);
CopyFile(Path.ChangeExtension(assemblyPath, ".pdb"), asmTestDir);
CopyFile(Path.Combine(assemblyDir, "InlineIL.dll"), asmTestDir);

return destFile;
Expand All @@ -30,7 +30,7 @@ private static string CopyFile(string fileName, string targetDir)
if (!File.Exists(fileName))
throw new InvalidOperationException($"File not found: {fileName}");

var dest = Path.Combine(targetDir, Path.GetFileName(fileName)!);
var dest = Path.Combine(targetDir, Path.GetFileName(fileName));
File.Copy(fileName, dest);
return dest;
}
Expand Down
1 change: 0 additions & 1 deletion src/InlineIL/IL.Emit.Custom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace InlineIL;
partial class IL
{
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
[SuppressMessage("Naming", "CA1724:Type names should not match namespaces")]
partial class Emit
{
/// <summary>
Expand Down

0 comments on commit 3b1a487

Please sign in to comment.