Skip to content

Commit

Permalink
cleanup before 2.3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed May 23, 2023
1 parent 24e2742 commit 0e8d1c1
Show file tree
Hide file tree
Showing 37 changed files with 243 additions and 181 deletions.
70 changes: 70 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,73 @@ csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:warning
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_lambdas = when_on_single_line:silent
csharp_style_expression_bodied_local_functions = when_on_single_line:silent

[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 3
indent_size = 3
1 change: 0 additions & 1 deletion Harmony.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
global.json = global.json
LICENSE = LICENSE
nuget.config = nuget.config
README.md = README.md
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion Harmony/Documentation/Documentation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MonoModReorg.Core" Version="$(MonoModCoreVersion)" />
<PackageReference Include="MonoMod.Core" Version="$(MonoModCoreVersion)" />

<!-- Reference assemblies are needed for non-Windows .NET Framework targeting builds. -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
Expand Down
29 changes: 15 additions & 14 deletions Harmony/Documentation/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Design", "CA1034:Nested types should not be visible")]
[assembly: SuppressMessage("Design", "CA1052:Static holder types should be Static or NotInheritable")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types")]
[assembly: SuppressMessage("Design", "CA1034")]
[assembly: SuppressMessage("Design", "CA1052")]
[assembly: SuppressMessage("Design", "CA1031")]

[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used")]
[assembly: SuppressMessage("Style", "IDE0025:Use expression body for properties")]
[assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter")]
[assembly: SuppressMessage("Style", "IDE0044:Add readonly modifier")]
[assembly: SuppressMessage("Style", "IDE0062:")]
[assembly: SuppressMessage("Style", "IDE0059:Unnecessary assignment of a value")]
[assembly: SuppressMessage("Style", "IDE0058")]
[assembly: SuppressMessage("Style", "IDE0025")]
[assembly: SuppressMessage("Style", "IDE0060")]
[assembly: SuppressMessage("Style", "IDE0044")]
[assembly: SuppressMessage("Style", "IDE0062")]
[assembly: SuppressMessage("Style", "IDE0059")]

[assembly: SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible")]
[assembly: SuppressMessage("Usage", "CA2211")]

[assembly: SuppressMessage("CodeQuality", "IDE0051:Remove unused private members")]
[assembly: SuppressMessage("CodeQuality", "IDE0051")]

[assembly: SuppressMessage("Performance", "CA1822:Mark members as static")]
[assembly: SuppressMessage("Performance", "CA1806:Do not ignore method results")]
[assembly: SuppressMessage("Performance", "CA1822")]
[assembly: SuppressMessage("Performance", "CA1806")]

[assembly: SuppressMessage("", "CS0649:")]
[assembly: SuppressMessage("", "CS0649")]
[assembly: SuppressMessage("", "IDE0251")]
4 changes: 2 additions & 2 deletions Harmony/Documentation/examples/execution_with.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static R ReplacementMethod(T optionalThisArgument /*, ... arguments ... */ )
ex = EditFinalizer(ex, ref result);
finalized = true;

if (ex is object) throw ex;
if (ex is not null) throw ex;
return result;
}
catch (Exception e)
Expand All @@ -61,7 +61,7 @@ static R ReplacementMethod(T optionalThisArgument /*, ... arguments ... */ )
else
{
// alternative 2: at least one non-void finalizer
if (ex is object) throw ex;
if (ex is not null) throw ex;
}

return result;
Expand Down
4 changes: 2 additions & 2 deletions Harmony/Extras/FastAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public static GetterHandler<T, S> CreateFieldGetter<T, S>(params string[] names)
foreach (var name in names)
{
var field = typeof(T).GetField(name, AccessTools.all);
if (field is object)
if (field is not null)
return CreateGetterHandler<T, S>(field);

var property = typeof(T).GetProperty(name, AccessTools.all);
if (property is object)
if (property is not null)
return CreateGetterHandler<T, S>(property);
}

Expand Down
28 changes: 19 additions & 9 deletions Harmony/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Performance", "CA1813:Avoid unsealed attributes")]
[assembly: SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types")]
[assembly: SuppressMessage("Design", "CA1018:Mark attributes with AttributeUsageAttribute")]
[assembly: SuppressMessage("", "CA1825")]

[assembly: SuppressMessage("Code Quality", "IDE0051")]
[assembly: SuppressMessage("Code Quality", "IDE0057")]
[assembly: SuppressMessage("Performance", "CA1813")]
[assembly: SuppressMessage("Performance", "CA1810")]
[assembly: SuppressMessage("Performance", "CA1822")]
[assembly: SuppressMessage("Performance", "CA1825")]

[assembly: SuppressMessage("Design", "CA1031")]
[assembly: SuppressMessage("Design", "CA1018")]

[assembly: SuppressMessage("CodeQuality", "IDE0051")]
[assembly: SuppressMessage("CodeQuality", "IDE0057")]
[assembly: SuppressMessage("CodeQuality", "IDE0079")]

[assembly: SuppressMessage("", "IDE0251")]
[assembly: SuppressMessage("Style", "IDE0270")]
[assembly: SuppressMessage("Usage", "CA2211")]
[assembly: SuppressMessage("GeneratedRegex", "SYSLIB1045")]

[assembly: SuppressMessage("Reliability", "CA2020:Prevent from behavioral change", Justification = "<Pending>", Scope = "member", Target = "~M:HarmonyLib.FileLog.LogBytes(System.Int64,System.Int32)")]
[assembly: SuppressMessage("Performance", "CA1850:Prefer static 'HashData' method over 'ComputeHash'", Justification = "<Pending>", Scope = "member", Target = "~M:HarmonyLib.FileLog.LogBytes(System.Int64,System.Int32)")]
5 changes: 1 addition & 4 deletions Harmony/Harmony.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MonoModReorg.Core" Version="$(MonoModCoreVersion)">
<!-- <PrivateAssets Condition="$(ILRepackInternalize)">all</PrivateAssets> -->
</PackageReference>

<PackageReference Include="MonoMod.Core" Version="$(MonoModCoreVersion)" />
<!-- Reference assemblies are needed for non-Windows .NET Framework targeting builds. -->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
</ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions Harmony/Internal/CodeTranspiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List<object>
var isStartBlock = blocks.FirstOrDefault(block => block.blockType != ExceptionBlockType.EndExceptionBlock);
var isEndBlock = blocks.FirstOrDefault(block => block.blockType == ExceptionBlockType.EndExceptionBlock);

if (isStartBlock is object && isEndBlock is null)
if (isStartBlock is not null && isEndBlock is null)
{
var pairInstruction = originalInstructions.Skip(originalIndex + 1).FirstOrDefault(instr =>
{
Expand All @@ -77,7 +77,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List<object>
blocks = blocksObject as List<ExceptionBlock>;
return blocks.Any();
});
if (pairInstruction is object)
if (pairInstruction is not null)
{
var pairStart = originalIndex + 1;
var pairEnd = pairStart + originalInstructions.Skip(pairStart).ToList().IndexOf(pairInstruction) - 1;
Expand All @@ -94,7 +94,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List<object>
blocks = blocksObject as List<ExceptionBlock>;
return blocks.Any();
});
if (pairInstruction is object)
if (pairInstruction is not null)
{
pairStart = opIndex + 1;
pairEnd = pairStart + newInstructions.Skip(opIndex + 1).ToList().IndexOf(pairInstruction) - 1;
Expand All @@ -104,7 +104,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List<object>
}
}
}
if (isStartBlock is null && isEndBlock is object)
if (isStartBlock is null && isEndBlock is not null)
{
var pairInstruction = originalInstructions.GetRange(0, originalIndex).LastOrDefault(instr =>
{
Expand All @@ -115,7 +115,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List<object>
blocks = blocksObject as List<ExceptionBlock>;
return blocks.Any();
});
if (pairInstruction is object)
if (pairInstruction is not null)
{
var pairStart = originalInstructions.GetRange(0, originalIndex).LastIndexOf(pairInstruction);
var pairEnd = originalIndex;
Expand All @@ -132,7 +132,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List<object>
blocks = blocksObject as List<ExceptionBlock>;
return blocks.Any();
});
if (pairInstruction is object)
if (pairInstruction is not null)
{
pairStart = newInstructions.GetRange(0, opIndex).LastIndexOf(pairInstruction);
pairEnd = opIndex;
Expand Down Expand Up @@ -235,7 +235,7 @@ internal List<CodeInstruction> GetResult(ILGenerator generator, MethodBase metho

// remember the order of the original input (for detection of dupped code instructions)
List<object> originalInstructions = null;
if (unassignedValues is object)
if (unassignedValues is not null)
originalInstructions = instructions.Cast<object>().ToList();

// call the transpiler
Expand All @@ -245,7 +245,7 @@ internal List<CodeInstruction> GetResult(ILGenerator generator, MethodBase metho
instructions = newInstructions;

// convert result back to 'our' CodeInstruction and re-assign otherwise lost fields
if (unassignedValues is object)
if (unassignedValues is not null)
instructions = ConvertToOurInstructions(instructions, typeof(CodeInstruction), originalInstructions, unassignedValues);
});

Expand Down
4 changes: 2 additions & 2 deletions Harmony/Internal/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal static string FormatArgument(object argument, string extra = null)
var type = argument.GetType();

if (argument is MethodBase method)
return method.FullDescription() + (extra is object ? " " + extra : "");
return method.FullDescription() + (extra is not null ? " " + extra : "");

if (argument is FieldInfo field)
return $"{field.FieldType.FullDescription()} {field.DeclaringType.FullDescription()}::{field.Name}";
Expand Down Expand Up @@ -351,7 +351,7 @@ internal void Emit(OpCode opcode, long arg)
internal void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes)
{
instructions.Add(CurrentPos(), new CodeInstruction(opcode, methodInfo));
var extra = optionalParameterTypes is object && optionalParameterTypes.Length > 0 ? optionalParameterTypes.Description() : null;
var extra = optionalParameterTypes is not null && optionalParameterTypes.Length > 0 ? optionalParameterTypes.Description() : null;
LogIL(opcode, methodInfo, extra);
il.EmitCall(opcode, methodInfo, optionalParameterTypes);
}
Expand Down
10 changes: 5 additions & 5 deletions Harmony/Internal/MethodCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal static List<CodeInstruction> GetInstructions(ILGenerator generator, Met
var copier = new MethodCopier(method, generator, originalVariables);

var info = Harmony.GetPatchInfo(method);
if (info is object)
if (info is not null)
{
var sortedTranspilers = PatchFunctions.GetSortedPatchMethods(method, info.Transpilers.ToArray(), false);
for (var i = 0; i < maxTranspilers && i < sortedTranspilers.Count; i++)
Expand Down Expand Up @@ -111,7 +111,7 @@ internal MethodBodyReader(MethodBase method, ILGenerator generator)

var type = method.DeclaringType;

if (type is object && type.IsGenericType)
if (type is not null && type.IsGenericType)
{
try { typeArguments = type.GetGenericArguments(); }
catch { typeArguments = null; }
Expand Down Expand Up @@ -219,7 +219,7 @@ internal void HandleNativeMethod()
internal void DeclareVariables(LocalBuilder[] existingVariables)
{
if (generator is null) return;
if (existingVariables is object)
if (existingVariables is not null)
variables = existingVariables;
else
variables = localVariables.Select(lvi => generator.DeclareLocal(lvi.LocalType, lvi.IsPinned)).ToArray();
Expand Down Expand Up @@ -329,7 +329,7 @@ internal List<CodeInstruction> FinalizeILCodes(Emitter emitter, List<MethodInfo>
case OperandType.InlineSwitch:
{
var targets = ilInstruction.operand as ILInstruction[];
if (targets is object)
if (targets is not null)
{
var labels = new List<Label>();
foreach (var target in targets)
Expand All @@ -347,7 +347,7 @@ internal List<CodeInstruction> FinalizeILCodes(Emitter emitter, List<MethodInfo>
case OperandType.InlineBrTarget:
{
var target = ilInstruction.operand as ILInstruction;
if (target is object)
if (target is not null)
{
var label = generator.DefineLabel();
target.labels.Add(label);
Expand Down
Loading

0 comments on commit 0e8d1c1

Please sign in to comment.