diff --git a/.editorconfig b/.editorconfig index bd19e82..9630ed9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -22,10 +22,10 @@ dotnet_analyzer_diagnostic.category-Style.severity = error # Organize usings dotnet_sort_system_directives_first = true # this. preferences -dotnet_style_qualification_for_field = false:silent -dotnet_style_qualification_for_property = false:silent -dotnet_style_qualification_for_method = false:silent -dotnet_style_qualification_for_event = false:silent +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion # Language keywords vs BCL types preferences dotnet_style_predefined_type_for_locals_parameters_members = true:silent dotnet_style_predefined_type_for_member_access = true:silent @@ -35,8 +35,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:sil dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent # Modifier preferences -dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent -dotnet_style_readonly_field = true:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning +dotnet_style_readonly_field = true:warning # Expression-level preferences dotnet_style_object_initializer = true:suggestion dotnet_style_collection_initializer = true:suggestion @@ -168,7 +168,7 @@ 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:suggestion -csharp_style_namespace_declarations = block_scoped:silent +csharp_style_namespace_declarations = file_scoped:suggestion csharp_style_prefer_method_group_conversion = true:silent csharp_style_prefer_top_level_statements = true:silent csharp_style_prefer_primary_constructors = true:suggestion diff --git a/src/TcHaxx.Snappy.CLI/CLI/BaseOptions.cs b/src/TcHaxx.Snappy.CLI/CLI/BaseOptions.cs index 6d71da9..a09376d 100644 --- a/src/TcHaxx.Snappy.CLI/CLI/BaseOptions.cs +++ b/src/TcHaxx.Snappy.CLI/CLI/BaseOptions.cs @@ -1,7 +1,7 @@ using CommandLine; using Serilog.Events; -namespace TcHaxx.Snappy.CLI; +namespace TcHaxx.Snappy.CLI.CLI; public class BaseOptions { diff --git a/src/TcHaxx.Snappy.CLI/CLI/Constants.cs b/src/TcHaxx.Snappy.CLI/CLI/Constants.cs index d37495d..3603122 100644 --- a/src/TcHaxx.Snappy.CLI/CLI/Constants.cs +++ b/src/TcHaxx.Snappy.CLI/CLI/Constants.cs @@ -1,4 +1,4 @@ -namespace TcHaxx.Snappy.CLI; +namespace TcHaxx.Snappy.CLI.CLI; internal static class Constants { diff --git a/src/TcHaxx.Snappy.CLI/CLI/ExitCodes.cs b/src/TcHaxx.Snappy.CLI/CLI/ExitCodes.cs index a446216..8949284 100644 --- a/src/TcHaxx.Snappy.CLI/CLI/ExitCodes.cs +++ b/src/TcHaxx.Snappy.CLI/CLI/ExitCodes.cs @@ -1,4 +1,4 @@ -namespace TcHaxx.Snappy.CLI; +namespace TcHaxx.Snappy.CLI.CLI; /// /// Exit codes for this application. diff --git a/src/TcHaxx.Snappy.CLI/CLI/Helper.cs b/src/TcHaxx.Snappy.CLI/CLI/Helper.cs index 9b52f55..8b8ea6d 100644 --- a/src/TcHaxx.Snappy.CLI/CLI/Helper.cs +++ b/src/TcHaxx.Snappy.CLI/CLI/Helper.cs @@ -1,7 +1,7 @@ using System.Reflection; using System.Text; -namespace TcHaxx.Snappy.CLI; +namespace TcHaxx.Snappy.CLI.CLI; /// /// Some helper methods/functions and extension methods. @@ -42,15 +42,15 @@ internal static string GetApplicationHeader(Assembly assembly) .FirstOrDefault(x => x.Key.Equals("RepositoryUrl"))?.Value ?? string.Empty; var delimiter = new string(Constants.CLI_DELIMITER, Console.BufferWidth); - sb.Append($"{delimiter}\n"); - sb.Append($"{assembly.GetName().Name} V{version}".Center() + "\n"); - sb.Append($"{copyright.Center()}\n"); + _ = sb.Append($"{delimiter}\n"); + _ = sb.Append($"{assembly.GetName().Name} V{version}".Center() + "\n"); + _ = sb.Append($"{copyright.Center()}\n"); if (!string.IsNullOrWhiteSpace(repoUrl)) { - sb.Append($"{repoUrl.Center()}\n"); + _ = sb.Append($"{repoUrl.Center()}\n"); } - sb.Append($"{delimiter}\n"); + _ = sb.Append($"{delimiter}\n"); return sb.ToString(); } diff --git a/src/TcHaxx.Snappy.CLI/CLI/InstallOptions.cs b/src/TcHaxx.Snappy.CLI/CLI/InstallOptions.cs index 2d55751..db813a2 100644 --- a/src/TcHaxx.Snappy.CLI/CLI/InstallOptions.cs +++ b/src/TcHaxx.Snappy.CLI/CLI/InstallOptions.cs @@ -1,6 +1,6 @@ using CommandLine; -namespace TcHaxx.Snappy.CLI; +namespace TcHaxx.Snappy.CLI.CLI; [Verb("install", false, HelpText = "Install TcHaxx.Snappy.library.")] internal class InstallOptions : BaseOptions diff --git a/src/TcHaxx.Snappy.CLI/CLI/VerifyOptions.cs b/src/TcHaxx.Snappy.CLI/CLI/VerifyOptions.cs index f44e1e4..1c229b7 100644 --- a/src/TcHaxx.Snappy.CLI/CLI/VerifyOptions.cs +++ b/src/TcHaxx.Snappy.CLI/CLI/VerifyOptions.cs @@ -2,7 +2,7 @@ using TcHaxx.Snappy.TcADS.Options; using TcHaxx.Snappy.Verifier.Options; -namespace TcHaxx.Snappy.CLI; +namespace TcHaxx.Snappy.CLI.CLI; [Verb("verify", false, HelpText = "Verify.")] public class VerifyOptions : BaseOptions, ITcAdsOptions, IVerifierOptions diff --git a/src/TcHaxx.Snappy.CLI/Commands/CommandInstall.cs b/src/TcHaxx.Snappy.CLI/Commands/CommandInstall.cs index 514feab..3f6f887 100644 --- a/src/TcHaxx.Snappy.CLI/Commands/CommandInstall.cs +++ b/src/TcHaxx.Snappy.CLI/Commands/CommandInstall.cs @@ -1,4 +1,5 @@ using Serilog; +using TcHaxx.Snappy.CLI.CLI; namespace TcHaxx.Snappy.CLI.Commands; diff --git a/src/TcHaxx.Snappy.CLI/Commands/CommandVerify.cs b/src/TcHaxx.Snappy.CLI/Commands/CommandVerify.cs index 0ed32f8..8e574bf 100644 --- a/src/TcHaxx.Snappy.CLI/Commands/CommandVerify.cs +++ b/src/TcHaxx.Snappy.CLI/Commands/CommandVerify.cs @@ -1,4 +1,5 @@ using Serilog; +using TcHaxx.Snappy.CLI.CLI; using TcHaxx.Snappy.TcADS; using TcHaxx.Snappy.Verifier; diff --git a/src/TcHaxx.Snappy.CLI/Commands/ICommandInstall.cs b/src/TcHaxx.Snappy.CLI/Commands/ICommandInstall.cs index 1b05001..01344c8 100644 --- a/src/TcHaxx.Snappy.CLI/Commands/ICommandInstall.cs +++ b/src/TcHaxx.Snappy.CLI/Commands/ICommandInstall.cs @@ -1,4 +1,6 @@ -namespace TcHaxx.Snappy.CLI.Commands; +using TcHaxx.Snappy.CLI.CLI; + +namespace TcHaxx.Snappy.CLI.Commands; internal interface ICommandInstall { diff --git a/src/TcHaxx.Snappy.CLI/Commands/ICommandVerify.cs b/src/TcHaxx.Snappy.CLI/Commands/ICommandVerify.cs index 59877ee..783c27e 100644 --- a/src/TcHaxx.Snappy.CLI/Commands/ICommandVerify.cs +++ b/src/TcHaxx.Snappy.CLI/Commands/ICommandVerify.cs @@ -1,4 +1,6 @@ -namespace TcHaxx.Snappy.CLI.Commands; +using TcHaxx.Snappy.CLI.CLI; + +namespace TcHaxx.Snappy.CLI.Commands; internal interface ICommandVerify { diff --git a/src/TcHaxx.Snappy.CLI/Program.cs b/src/TcHaxx.Snappy.CLI/Program.cs index 863c00a..13a172a 100644 --- a/src/TcHaxx.Snappy.CLI/Program.cs +++ b/src/TcHaxx.Snappy.CLI/Program.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Core; -using TcHaxx.Snappy.CLI; +using TcHaxx.Snappy.CLI.CLI; using TcHaxx.Snappy.CLI.Commands; using TcHaxx.Snappy.CLI.Logging; using TcHaxx.Snappy.Common.RPC; diff --git a/src/TcHaxx.Snappy.Common/RPC/RpcMethodDescriptor.cs b/src/TcHaxx.Snappy.Common/RPC/RpcMethodDescriptor.cs index 9759808..b736257 100644 --- a/src/TcHaxx.Snappy.Common/RPC/RpcMethodDescriptor.cs +++ b/src/TcHaxx.Snappy.Common/RPC/RpcMethodDescriptor.cs @@ -4,7 +4,7 @@ namespace TcHaxx.Snappy.Common.RPC; public class RpcMethodDescriptor : IRpcMethodDescriptor { - readonly Queue _verifyMethods = new(); + private readonly Queue _verifyMethods = new(); public RpcMethodDescriptor() { diff --git a/src/TcHaxx.Snappy.Common/RPC/RpcMethodTransformException.cs b/src/TcHaxx.Snappy.Common/RPC/RpcMethodTransformException.cs index 133077d..cb32bc1 100644 --- a/src/TcHaxx.Snappy.Common/RPC/RpcMethodTransformException.cs +++ b/src/TcHaxx.Snappy.Common/RPC/RpcMethodTransformException.cs @@ -1,8 +1,5 @@ namespace TcHaxx.Snappy.Common.RPC; -public class RpcMethodTransformException : Exception +public class RpcMethodTransformException(string message) : Exception(message) { - public RpcMethodTransformException(string message) : base(message) - { - } } diff --git a/src/TcHaxx.Snappy.TcADS/Symbols/SymbolFactory.cs b/src/TcHaxx.Snappy.TcADS/Symbols/SymbolFactory.cs index 9d6fa92..9ff4e09 100644 --- a/src/TcHaxx.Snappy.TcADS/Symbols/SymbolFactory.cs +++ b/src/TcHaxx.Snappy.TcADS/Symbols/SymbolFactory.cs @@ -32,8 +32,8 @@ public void AddSymbols(ServerSymbolFactory? serverSymbolFactory) return; } - uint idxGrp = 0x80000001; - uint idxOffset = 0x10000000; + var idxGrp = 0x80000001u; + var idxOffset = 0x10000000u; foreach (var rpcMethodDescription in _rpcMethodDescriptor.GetRpcMethodDescription()) { var paramsKvp = GetMethodParameter(rpcMethodDescription.Parameters); @@ -43,16 +43,16 @@ public void AddSymbols(ServerSymbolFactory? serverSymbolFactory) AddToServerSymbolFactory(serverSymbolFactory, [retValKvp]); var fullName = rpcMethodDescription.Method.ReflectedType?.FullName ?? rpcMethodDescription.Method.Name; - DataArea dataArea = new DataArea($"DATA::{fullName}", idxGrp, idxOffset++, 0x10000); + var dataArea = new DataArea($"DATA::{fullName}", idxGrp, idxOffset++, 0x10000); - serverSymbolFactory.AddDataArea(dataArea); + _ = serverSymbolFactory.AddDataArea(dataArea); var rpc = BuildRpcMethod(rpcMethodDescription.Method, paramsKvp, retValKvp); - StructType dtStructRpc = new StructType($"STRUCT::{fullName}"); - dtStructRpc.AddMethod(rpc); - serverSymbolFactory.AddType(dtStructRpc); - serverSymbolFactory.AddSymbol(fullName, dtStructRpc, dataArea); + var dtStructRpc = new StructType($"STRUCT::{fullName}"); + _ = dtStructRpc.AddMethod(rpc); + _ = serverSymbolFactory.AddType(dtStructRpc); + _ = serverSymbolFactory.AddSymbol(fullName, dtStructRpc, dataArea); _mappedStructTypeToRpcMethod.Add(dtStructRpc, rpcMethodDescription.RpcInvocableMethod); } @@ -86,10 +86,10 @@ private static RpcMethod BuildRpcMethod(MethodInfo methodInfo, IEnumerable GetMethodReturnValue(ParameterInf if (stringAttribute is not null && field.FieldType == typeof(string)) { var stringType = ToStringType(field); - structType.AddAligned(new Member(field.Name ?? "unknown", stringType)); + _ = structType.AddAligned(new Member(field.Name ?? "unknown", stringType)); } else { var dt = new PrimitiveType(field.Name ?? "unknown", field.FieldType); - structType.AddAligned(new Member(field.Name ?? "unknown", dt)); + _ = structType.AddAligned(new Member(field.Name ?? "unknown", dt)); } } return new KeyValuePair(returnValue, structType); @@ -137,7 +137,7 @@ private KeyValuePair ConvertToDataType(ParameterInfo p return new KeyValuePair(paramInfo, stringType); } - bool isPrimitive = IsPrimitiveType(paramInfo.ParameterType); + var isPrimitive = IsPrimitiveType(paramInfo.ParameterType); if (!isPrimitive) { #pragma warning disable CA2208 // Instantiate argument exceptions correctly diff --git a/src/TcHaxx.Snappy.Verifier.Tests/JsonConverter/DoubleConverterTests.cs b/src/TcHaxx.Snappy.Verifier.Tests/JsonConverter/DoubleConverterTests.cs index 65ae84a..cf1929c 100644 --- a/src/TcHaxx.Snappy.Verifier.Tests/JsonConverter/DoubleConverterTests.cs +++ b/src/TcHaxx.Snappy.Verifier.Tests/JsonConverter/DoubleConverterTests.cs @@ -25,6 +25,6 @@ public async Task ShouldUseDoublePrecision(ushort precision, params double[] val _.Converters.Add(new DoubleConverter(precision)); }); - await Verify(values, settings).UseParameters(precision); + _ = await Verify(values, settings).UseParameters(precision); } } diff --git a/src/TcHaxx.Snappy.Verifier/IVerifyService.cs b/src/TcHaxx.Snappy.Verifier/IVerifyService.cs index f93de95..312a033 100644 --- a/src/TcHaxx.Snappy.Verifier/IVerifyService.cs +++ b/src/TcHaxx.Snappy.Verifier/IVerifyService.cs @@ -1,10 +1,9 @@ using TcHaxx.Snappy.Common.Verify; using TcHaxx.Snappy.Verifier.Options; -namespace TcHaxx.Snappy.Verifier +namespace TcHaxx.Snappy.Verifier; + +public interface IVerifyService : IVerifyMethod { - public interface IVerifyService : IVerifyMethod - { - public IVerifierOptions Options { get; set; } - } + public IVerifierOptions Options { get; set; } } diff --git a/src/TcHaxx.Snappy.Verifier/JsonConverter/DoubleConverter.cs b/src/TcHaxx.Snappy.Verifier/JsonConverter/DoubleConverter.cs index 763f687..b67934f 100644 --- a/src/TcHaxx.Snappy.Verifier/JsonConverter/DoubleConverter.cs +++ b/src/TcHaxx.Snappy.Verifier/JsonConverter/DoubleConverter.cs @@ -5,6 +5,9 @@ namespace TcHaxx.Snappy.Verifier.JsonConverter; internal class DoubleConverter(ushort precision) : WriteOnlyJsonConverter { - public override void Write(VerifyJsonWriter writer, double theDouble) => + public override void Write(VerifyJsonWriter writer, double theDouble) + { writer.WriteValue(theDouble.ToString($"F{precision}", CultureInfo.InvariantCulture)); + } + } diff --git a/src/TcHaxx.Snappy.Verifier/VerificationResultExtension.cs b/src/TcHaxx.Snappy.Verifier/VerificationResultExtension.cs index 869bb99..740e308 100644 --- a/src/TcHaxx.Snappy.Verifier/VerificationResultExtension.cs +++ b/src/TcHaxx.Snappy.Verifier/VerificationResultExtension.cs @@ -1,26 +1,25 @@ using System.Text.RegularExpressions; using TcHaxx.Snappy.Common.Verify; -namespace TcHaxx.Snappy.Verifier +namespace TcHaxx.Snappy.Verifier; + +internal static class VerificationResultExtension { - internal static class VerificationResultExtension + internal static VerificationResult ToCompactDiff(this VerificationResult result) { - internal static VerificationResult ToCompactDiff(this VerificationResult result) + var matchNew = Regex.Match(result.Diff, "^New:\n\nReceived:(?.*)(?.*)(?.*)(?.*)(?