From b642b7bc9bb3ab40ee2bfc1bbcfdf8f8ade97de2 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Sun, 17 Sep 2023 11:12:17 +0200 Subject: [PATCH] refactor: use Husky.NET instead of pre-commit --- .config/dotnet-tools.json | 18 +++++-- .editorconfig | 3 +- .husky/pre-commit | 4 ++ .husky/task-runner.json | 34 ++++++++++++ .pre-commit-config.yaml | 13 ----- INetMock.sln | 1 - .../Audit/Client/AuditApiClient.cs | 6 +-- .../Audit/Serialization/GenericReader.cs | 5 +- .../Audit/Serialization/TypedReader.cs | 10 +--- .../INetMockFixture.cs | 5 +- tests/INetMock.Client.Test/Hex/Converter.cs | 6 +-- .../INetMock.Client.Test.csproj | 54 +++++++++---------- 12 files changed, 91 insertions(+), 68 deletions(-) create mode 100755 .husky/pre-commit create mode 100644 .husky/task-runner.json delete mode 100644 .pre-commit-config.yaml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index cb895fd..e919e28 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,22 +3,34 @@ "isRoot": true, "tools": { "dotnet-grpc": { - "version": "2.46.0", + "version": "2.57.0", "commands": [ "dotnet-grpc" ] }, "nuke.globaltool": { - "version": "6.1.2", + "version": "7.0.5", "commands": [ "nuke" ] }, "gitversion.tool": { - "version": "5.10.3", + "version": "5.12.0", "commands": [ "dotnet-gitversion" ] + }, + "husky": { + "version": "0.6.1", + "commands": [ + "husky" + ] + }, + "jetbrains.resharper.globaltools": { + "version": "2023.2.1", + "commands": [ + "jb" + ] } } } \ No newline at end of file diff --git a/.editorconfig b/.editorconfig index 0202480..7236ae2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,6 +6,7 @@ end_of_line = lf charset = utf-8 insert_final_newline = true max_line_length = 120 +indent_size = 4 [*.xml] indent_size = 4 @@ -18,7 +19,7 @@ dotnet_style_qualification_for_field = false:warning dotnet_style_qualification_for_property = false:warning dotnet_style_qualification_for_method = false:warning dotnet_style_qualification_for_event = false:warning -dotnet_style_require_accessibility_modifiers = never:warning +dotnet_style_require_accessibility_modifiers = omit_if_default:warning csharp_style_expression_bodied_methods = true:silent csharp_style_expression_bodied_properties = true:warning diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..6937b36 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +dotnet husky run --group pre-commit diff --git a/.husky/task-runner.json b/.husky/task-runner.json new file mode 100644 index 0000000..4f173be --- /dev/null +++ b/.husky/task-runner.json @@ -0,0 +1,34 @@ +{ + "tasks": [ + { + "name": "dotnet-format", + "group": "pre-commit", + "command": "dotnet", + "args": [ + "dotnet-format", + "--include", + "${staged}" + ], + "include": [ + "**/*.cs", + "**/*.vb" + ] + }, + { + "name": "Run JB Clean Up Code", + "group": "pre-commit", + "command": "dotnet", + "pathMode": "relative", + "args": [ + "jb", + "cleanupcode", + "INetMock.sln", + "--telemetry-optout" + ], + "include": [ + "**/*.cs", + "**/*.vb" + ] + } + ] +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 9cbe814..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,13 +0,0 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks -repos: - - repo: https://github.com/dotnet/format - rev: "v5.1.225507" # Specify a tag or sha here, or run "pre-commit autoupdate" - hooks: - - id: dotnet-format - args: - - "" - - --folder - - --check - - --verbosity=detailed - - --include diff --git a/INetMock.sln b/INetMock.sln index 57e7881..dca24f4 100644 --- a/INetMock.sln +++ b/INetMock.sln @@ -7,7 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitignore = .gitignore - .pre-commit-config.yaml = .pre-commit-config.yaml README.md = README.md global.json = global.json EndProjectSection diff --git a/src/INetMock.Client/Audit/Client/AuditApiClient.cs b/src/INetMock.Client/Audit/Client/AuditApiClient.cs index 0d5113d..d1ecd62 100644 --- a/src/INetMock.Client/Audit/Client/AuditApiClient.cs +++ b/src/INetMock.Client/Audit/Client/AuditApiClient.cs @@ -48,9 +48,9 @@ public class AuditApiClient : IAuditApiClient public async Task RemoveFileSinkAsync(string targetPath, CancellationToken token = default) { var resp = await _auditClient.RemoveFileSinkAsync(new RemoveFileSinkRequest - { - TargetPath = targetPath - }, + { + TargetPath = targetPath + }, Metadata.Empty, null, token diff --git a/src/INetMock.Client/Audit/Serialization/GenericReader.cs b/src/INetMock.Client/Audit/Serialization/GenericReader.cs index 9682a61..110f0fb 100644 --- a/src/INetMock.Client/Audit/Serialization/GenericReader.cs +++ b/src/INetMock.Client/Audit/Serialization/GenericReader.cs @@ -37,8 +37,5 @@ public sealed class GenericReader : IEventReader public ValueTask DisposeAsync() => _reader.DisposeAsync(); - public void Dispose() - { - _reader.Dispose(); - } + public void Dispose() => _reader.Dispose(); } diff --git a/src/INetMock.Client/Audit/Serialization/TypedReader.cs b/src/INetMock.Client/Audit/Serialization/TypedReader.cs index 70da03d..1a7c080 100644 --- a/src/INetMock.Client/Audit/Serialization/TypedReader.cs +++ b/src/INetMock.Client/Audit/Serialization/TypedReader.cs @@ -76,13 +76,7 @@ public sealed class TypedReader : IEventReader where T : EventDetails, new } while (true); } - public void Dispose() - { - _reader.Dispose(); - } + public void Dispose() => _reader.Dispose(); - public ValueTask DisposeAsync() - { - return _reader.DisposeAsync(); - } + public ValueTask DisposeAsync() => _reader.DisposeAsync(); } diff --git a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs index dee07f7..11c73e4 100644 --- a/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs +++ b/tests/INetMock.Client.IntegrationTest/INetMockFixture.cs @@ -48,8 +48,5 @@ public class INetMockFixture : IAsyncLifetime INetMockSocketPath = $"http://{_inetmockContainer.Hostname}:{_inetmockContainer.GetMappedPublicPort(6767)}"; } - public async Task DisposeAsync() - { - await _inetmockContainer.StopAsync(); - } + public async Task DisposeAsync() => await _inetmockContainer.StopAsync(); } diff --git a/tests/INetMock.Client.Test/Hex/Converter.cs b/tests/INetMock.Client.Test/Hex/Converter.cs index d34abac..cd5d785 100644 --- a/tests/INetMock.Client.Test/Hex/Converter.cs +++ b/tests/INetMock.Client.Test/Hex/Converter.cs @@ -5,11 +5,9 @@ namespace INetMock.Client.Test.Hex; public static class Converter { - public static byte[] HexToByteArray(this string hex) - { - return Enumerable.Range(0, hex.Length) + public static byte[] HexToByteArray(this string hex) => + Enumerable.Range(0, hex.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .ToArray(); - } } diff --git a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj index facbef4..c9c1f6e 100644 --- a/tests/INetMock.Client.Test/INetMock.Client.Test.csproj +++ b/tests/INetMock.Client.Test/INetMock.Client.Test.csproj @@ -1,27 +1,27 @@ - - - - net6.0 - false - latest - enable - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - + + + net6.0 + false + latest + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + \ No newline at end of file