Skip to content

Commit

Permalink
refactor: Adapt rules
Browse files Browse the repository at this point in the history
  • Loading branch information
densogiaichned committed Feb 18, 2024
1 parent ba5c816 commit 18a8552
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 63 deletions.
14 changes: 7 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.CLI/CLI/BaseOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommandLine;
using Serilog.Events;

namespace TcHaxx.Snappy.CLI;
namespace TcHaxx.Snappy.CLI.CLI;

public class BaseOptions
{
Expand Down
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.CLI/CLI/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TcHaxx.Snappy.CLI;
namespace TcHaxx.Snappy.CLI.CLI;

internal static class Constants
{
Expand Down
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.CLI/CLI/ExitCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TcHaxx.Snappy.CLI;
namespace TcHaxx.Snappy.CLI.CLI;

/// <summary>
/// Exit codes for this application.
Expand Down
12 changes: 6 additions & 6 deletions src/TcHaxx.Snappy.CLI/CLI/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using System.Text;

namespace TcHaxx.Snappy.CLI;
namespace TcHaxx.Snappy.CLI.CLI;

/// <summary>
/// Some helper methods/functions and extension methods.
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.CLI/CLI/InstallOptions.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.CLI/CLI/VerifyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/TcHaxx.Snappy.CLI/Commands/CommandInstall.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Serilog;
using TcHaxx.Snappy.CLI.CLI;

namespace TcHaxx.Snappy.CLI.Commands;

Expand Down
1 change: 1 addition & 0 deletions src/TcHaxx.Snappy.CLI/Commands/CommandVerify.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Serilog;
using TcHaxx.Snappy.CLI.CLI;
using TcHaxx.Snappy.TcADS;
using TcHaxx.Snappy.Verifier;

Expand Down
4 changes: 3 additions & 1 deletion src/TcHaxx.Snappy.CLI/Commands/ICommandInstall.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TcHaxx.Snappy.CLI.Commands;
using TcHaxx.Snappy.CLI.CLI;

namespace TcHaxx.Snappy.CLI.Commands;

internal interface ICommandInstall
{
Expand Down
4 changes: 3 additions & 1 deletion src/TcHaxx.Snappy.CLI/Commands/ICommandVerify.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace TcHaxx.Snappy.CLI.Commands;
using TcHaxx.Snappy.CLI.CLI;

namespace TcHaxx.Snappy.CLI.Commands;

internal interface ICommandVerify
{
Expand Down
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/TcHaxx.Snappy.Common/RPC/RpcMethodDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TcHaxx.Snappy.Common.RPC;

public class RpcMethodDescriptor : IRpcMethodDescriptor
{
readonly Queue<IVerifyMethod> _verifyMethods = new();
private readonly Queue<IVerifyMethod> _verifyMethods = new();

public RpcMethodDescriptor()
{
Expand Down
5 changes: 1 addition & 4 deletions src/TcHaxx.Snappy.Common/RPC/RpcMethodTransformException.cs
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
26 changes: 13 additions & 13 deletions src/TcHaxx.Snappy.TcADS/Symbols/SymbolFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -86,10 +86,10 @@ private static RpcMethod BuildRpcMethod(MethodInfo methodInfo, IEnumerable<KeyVa
var rpc = new RpcMethod(nameOrAlias);
foreach (var (k, v) in paramsKvp)
{
rpc.AddParameter(k.Name ?? "unknown", v, k.IsOut ? MethodParamFlags.Out : MethodParamFlags.In);
_ = rpc.AddParameter(k.Name ?? "unknown", v, k.IsOut ? MethodParamFlags.Out : MethodParamFlags.In);
}

rpc.SetReturnType(retValKvp.Value);
_ = rpc.SetReturnType(retValKvp.Value);
return rpc;
}

Expand All @@ -113,12 +113,12 @@ private KeyValuePair<ParameterInfo, IDataType> 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<ParameterInfo, IDataType>(returnValue, structType);
Expand All @@ -137,7 +137,7 @@ private KeyValuePair<ParameterInfo, IDataType> ConvertToDataType(ParameterInfo p
return new KeyValuePair<ParameterInfo, IDataType>(paramInfo, stringType);
}

bool isPrimitive = IsPrimitiveType(paramInfo.ParameterType);
var isPrimitive = IsPrimitiveType(paramInfo.ParameterType);
if (!isPrimitive)
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 4 additions & 5 deletions src/TcHaxx.Snappy.Verifier/IVerifyService.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
5 changes: 4 additions & 1 deletion src/TcHaxx.Snappy.Verifier/JsonConverter/DoubleConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace TcHaxx.Snappy.Verifier.JsonConverter;
internal class DoubleConverter(ushort precision) : WriteOnlyJsonConverter<double>
{

public override void Write(VerifyJsonWriter writer, double theDouble) =>
public override void Write(VerifyJsonWriter writer, double theDouble)
{
writer.WriteValue(theDouble.ToString($"F{precision}", CultureInfo.InvariantCulture));
}

}
31 changes: 15 additions & 16 deletions src/TcHaxx.Snappy.Verifier/VerificationResultExtension.cs
Original file line number Diff line number Diff line change
@@ -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:(?<diff>.*)(?<!\n)$", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
if (matchNew.Success)
{
var matchNew = Regex.Match(result.Diff, "^New:\n\nReceived:(?<diff>.*)(?<!\n)$", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
if (matchNew.Success)
{
result.Diff = $"New: {matchNew.Groups["diff"].Value}";
return result;
}
var matchCompareResult = Regex.Match(result.Diff, "^Compare Result:\n(?<diff>.*)(?<!\n)$", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
if (matchCompareResult.Success)
{
result.Diff = $"Compare Result:\n{matchCompareResult.Groups["diff"].Value}";
return result;
}

result.Diff = $"New: {matchNew.Groups["diff"].Value}";
return result;
}
var matchCompareResult = Regex.Match(result.Diff, "^Compare Result:\n(?<diff>.*)(?<!\n)$", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.Compiled);
if (matchCompareResult.Success)
{
result.Diff = $"Compare Result:\n{matchCompareResult.Groups["diff"].Value}";
return result;
}

return result;
}
}
2 changes: 1 addition & 1 deletion tests/TcHaxx.Snappy.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TcHaxx.Snappy.Tests;
namespace TcHaxx.Snappy.CLI.Tests;

public class UnitTest1
{
Expand Down

0 comments on commit 18a8552

Please sign in to comment.