diff --git a/src/InlineIL.Fody/Support/Exceptions.cs b/src/InlineIL.Fody/Support/Exceptions.cs index dff3281..4669418 100644 --- a/src/InlineIL.Fody/Support/Exceptions.cs +++ b/src/InlineIL.Fody/Support/Exceptions.cs @@ -1,6 +1,7 @@ using Fody; using Mono.Cecil.Cil; +// ReSharper disable once RedundantDisableWarningComment #pragma warning disable CA1032 namespace InlineIL.Fody.Support; diff --git a/src/InlineIL.Tests.InvalidAssemblyToProcess/BasicTestCases.cs b/src/InlineIL.Tests.InvalidAssemblyToProcess/BasicTestCases.cs index 1e6dd88..2efdff8 100644 --- a/src/InlineIL.Tests.InvalidAssemblyToProcess/BasicTestCases.cs +++ b/src/InlineIL.Tests.InvalidAssemblyToProcess/BasicTestCases.cs @@ -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; @@ -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() diff --git a/src/InlineIL.Tests.UnverifiableAssemblyToProcess/BasicTestCases.cs b/src/InlineIL.Tests.UnverifiableAssemblyToProcess/BasicTestCases.cs index ee0ad32..f71a73c 100644 --- a/src/InlineIL.Tests.UnverifiableAssemblyToProcess/BasicTestCases.cs +++ b/src/InlineIL.Tests.UnverifiableAssemblyToProcess/BasicTestCases.cs @@ -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 @@ -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(); @@ -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(); diff --git a/src/InlineIL.Tests/Support/AssertionExtensions.cs b/src/InlineIL.Tests/Support/AssertionExtensions.cs index d3fc0f1..56b1d06 100644 --- a/src/InlineIL.Tests/Support/AssertionExtensions.cs +++ b/src/InlineIL.Tests/Support/AssertionExtensions.cs @@ -3,6 +3,7 @@ using JetBrains.Annotations; using Xunit; using Xunit.Sdk; +using NotNullAttribute = System.Diagnostics.CodeAnalysis.NotNullAttribute; namespace InlineIL.Tests.Support; @@ -25,11 +26,7 @@ public static void ShouldBeNull(this object? actual) => Assert.Null(actual); [ContractAnnotation("null => halt")] - public static T ShouldNotBeNull( -#if NETCOREAPP - [System.Diagnostics.CodeAnalysis.NotNull] -#endif - this T? actual) + public static T ShouldNotBeNull([NotNull] this T? actual) where T : class { Assert.NotNull(actual); diff --git a/src/InlineIL.Tests/Support/Attributes.cs b/src/InlineIL.Tests/Support/Attributes.cs new file mode 100644 index 0000000..9aecaa2 --- /dev/null +++ b/src/InlineIL.Tests/Support/Attributes.cs @@ -0,0 +1,94 @@ +// (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 diff --git a/src/InlineIL.Tests/Weaving/FixtureHelper.cs b/src/InlineIL.Tests/Weaving/FixtureHelper.cs index 07aeb22..61c147b 100644 --- a/src/InlineIL.Tests/Weaving/FixtureHelper.cs +++ b/src/InlineIL.Tests/Weaving/FixtureHelper.cs @@ -10,16 +10,16 @@ internal static class FixtureHelper public static string IsolateAssembly() { 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; @@ -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; } diff --git a/src/InlineIL/IL.Emit.Custom.cs b/src/InlineIL/IL.Emit.Custom.cs index 0be3d9c..0e49d11 100644 --- a/src/InlineIL/IL.Emit.Custom.cs +++ b/src/InlineIL/IL.Emit.Custom.cs @@ -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 { ///