From 1023b1417cb64bd8f7c81c2bf039cb9db4ae44e7 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 16 Jul 2026 16:18:22 +0700 Subject: [PATCH 1/5] Add dotnet format config and CI enforcement workflow Add .editorconfig capturing the project's conventions and a Format workflow that runs `dotnet format --verify-no-changes` on PRs and pushes to main. The vendored Ycs port is excluded via generated_code. Co-Authored-By: Claude Opus 4.8 --- .editorconfig | 81 +++++++++++++++++++++++++++++++++++ .github/workflows/format.yaml | 26 +++++++++++ 2 files changed, 107 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/format.yaml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..12ab161 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,81 @@ +root = true + +# All files +[*] +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +# Project & config files +[*.{csproj,props,targets,json,yml,yaml}] +indent_size = 2 + +[*.{md,markdown}] +trim_trailing_whitespace = false + +# Vendored third-party code (C# port of Yjs) — excluded from formatting/analysis. +# dotnet format skips files marked as generated. +[src/Ycs/**.cs] +generated_code = true + +# C# files +[*.cs] +# Namespaces +csharp_style_namespace_declarations = file_scoped:warning + +# 'this.' preferences — prefer omitting +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 + +# Language keywords vs BCL types +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# var preferences — prefer var when the type is apparent +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = false:suggestion + +# Modern language features +csharp_style_expression_bodied_methods = when_on_single_line:suggestion +csharp_style_expression_bodied_properties = true:suggestion +csharp_style_expression_bodied_accessors = true:suggestion +csharp_prefer_braces = true:suggestion +csharp_style_prefer_switch_expression = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_pattern_matching_over_as_with_null_check = true:warning + +# Null checking +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion + +# Using directives +csharp_using_directive_placement = outside_namespace:warning +dotnet_sort_system_directives_first = true + +# New line preferences (Allman braces — matches existing code) +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true + +# Indentation +csharp_indent_case_contents = true +csharp_indent_switch_labels = true + +# Spacing +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_method_call_parameter_list_parentheses = false diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 0000000..7ef8ccd --- /dev/null +++ b/.github/workflows/format.yaml @@ -0,0 +1,26 @@ +name: Format + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + format: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install .NET + uses: actions/setup-dotnet@v4 + + # Verifies the code matches .editorconfig (whitespace + code style + analyzers). + # Fails the build if anything is out of format. To fix locally, run: + # dotnet format + - name: Verify formatting + run: dotnet format --verify-no-changes From d01da57b0ddcae5127ef57acbc420f9eda243662 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 16 Jul 2026 16:21:07 +0700 Subject: [PATCH 2/5] Fix xUnit1051 and IDE0019 format diagnostics - Pass TestContext.Current.CancellationToken to ToBlockingEnumerable and File.ReadAllLinesAsync so tests cancel responsively (xUnit1051). - Use `is not SqliteConnection` pattern matching instead of `as` + null check in DataModelTestBase.ForkDatabase (IDE0019). Co-Authored-By: Claude Opus 4.8 --- src/SIL.Harmony.Tests/DataModelTestBase.cs | 3 +-- src/SIL.Harmony.Tests/JsonSyncableTests.cs | 2 +- src/SIL.Harmony.Tests/Syncable/SyncableTests.cs | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/SIL.Harmony.Tests/DataModelTestBase.cs b/src/SIL.Harmony.Tests/DataModelTestBase.cs index 80402eb..77a87be 100644 --- a/src/SIL.Harmony.Tests/DataModelTestBase.cs +++ b/src/SIL.Harmony.Tests/DataModelTestBase.cs @@ -52,8 +52,7 @@ public DataModelTestBase ForkDatabase(bool alwaysValidate = true) { var connection = new SqliteConnection("Data Source=:memory:"); connection.Open(); - var existingConnection = DbContext.Database.GetDbConnection() as SqliteConnection; - if (existingConnection is null) throw new InvalidOperationException("Database is not SQLite"); + if (DbContext.Database.GetDbConnection() is not SqliteConnection existingConnection) throw new InvalidOperationException("Database is not SQLite"); existingConnection.BackupDatabase(connection); var newTestBase = new DataModelTestBase(connection, alwaysValidate, performanceTest: _performanceTest); newTestBase.SetCurrentDate(currentDate.DateTime); diff --git a/src/SIL.Harmony.Tests/JsonSyncableTests.cs b/src/SIL.Harmony.Tests/JsonSyncableTests.cs index f3977b7..26c3ef2 100644 --- a/src/SIL.Harmony.Tests/JsonSyncableTests.cs +++ b/src/SIL.Harmony.Tests/JsonSyncableTests.cs @@ -67,7 +67,7 @@ public async Task DoesNotDuplicateFileLines() var file = new FileInfo(Path.Combine(dir.FullName, $"{JsonSyncable.FilenamePrefix}{commit.ClientId}{JsonSyncable.FilenameExtension}")); - var lines = await File.ReadAllLinesAsync(file.FullName); + var lines = await File.ReadAllLinesAsync(file.FullName, TestContext.Current.CancellationToken); lines.Should().HaveCount(1); } finally diff --git a/src/SIL.Harmony.Tests/Syncable/SyncableTests.cs b/src/SIL.Harmony.Tests/Syncable/SyncableTests.cs index fd7cb51..7d96fb7 100644 --- a/src/SIL.Harmony.Tests/Syncable/SyncableTests.cs +++ b/src/SIL.Harmony.Tests/Syncable/SyncableTests.cs @@ -213,7 +213,7 @@ public async Task CanSync_AddDependentWithMultipleChanges(ISyncableTestBackend l var syncResults = await remote.Syncable.SyncWith(local.Syncable); await SyncableTestHelpers.MirrorToReadModelsAsync(remote, local, syncResults); - remote.ReadModel.QueryLatest().ToBlockingEnumerable().Should() - .BeEquivalentTo(local.ReadModel.QueryLatest().ToBlockingEnumerable()); + remote.ReadModel.QueryLatest().ToBlockingEnumerable(TestContext.Current.CancellationToken).Should() + .BeEquivalentTo(local.ReadModel.QueryLatest().ToBlockingEnumerable(TestContext.Current.CancellationToken)); } } From a50dcd35fab1d37ed9d167cfadc570a9ecf6a32c Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 16 Jul 2026 16:37:02 +0700 Subject: [PATCH 3/5] Apply dotnet format across the codebase Normalize whitespace, strip UTF-8 BOMs, add final newlines, and sort using directives to satisfy the new .editorconfig / Format workflow. Formatting-only changes; no behavioral changes. Vendored src/Ycs is excluded from formatting. Co-Authored-By: Claude Opus 4.8 --- src/SIL.Harmony.Core/ChangeEntity.cs | 2 +- src/SIL.Harmony.Core/CommitBase.cs | 2 +- src/SIL.Harmony.Core/CommitMetadata.cs | 2 +- src/SIL.Harmony.Core/CrdtConstants.cs | 2 +- .../EntityNotFoundException.cs | 2 +- src/SIL.Harmony.Core/HybridDateTime.cs | 2 +- src/SIL.Harmony.Core/IChangeContext.cs | 2 +- src/SIL.Harmony.Core/IObjectBase.cs | 2 +- src/SIL.Harmony.Core/IRemoteResourceService.cs | 2 +- src/SIL.Harmony.Core/QueryHelpers.cs | 6 +++--- src/SIL.Harmony.Core/ServerCommit.cs | 2 +- src/SIL.Harmony.Core/SyncState.cs | 4 ++-- src/SIL.Harmony.Linq2db/Linq2dbKernel.cs | 2 +- .../Changes/AddWordImageChange.cs | 2 +- .../Changes/EditExampleChange.cs | 2 +- .../Changes/NewDefinitionChange.cs | 2 +- .../Changes/NewExampleChange.cs | 4 ++-- .../Changes/NewWordChange.cs | 2 +- .../Changes/SetAntonymReferenceChange.cs | 2 +- .../Changes/SetDefinitionPartOfSpeechChange.cs | 2 +- src/SIL.Harmony.Sample/Changes/SetTagChange.cs | 4 ++-- .../Changes/SetWordNoteChange.cs | 2 +- .../Changes/SetWordTextChange.cs | 2 +- .../Changes/TagWordChange.cs | 2 +- src/SIL.Harmony.Sample/CrdtSampleKernel.cs | 4 ++-- src/SIL.Harmony.Sample/Models/Definition.cs | 4 ++-- src/SIL.Harmony.Sample/Models/Example.cs | 6 +++--- src/SIL.Harmony.Sample/Models/Tag.cs | 2 +- src/SIL.Harmony.Sample/Models/Word.cs | 2 +- src/SIL.Harmony.Sample/Models/WordTag.cs | 2 +- src/SIL.Harmony.Sample/SampleDbContext.cs | 8 ++++---- .../Adapter/CustomObjectAdapterTests.cs | 2 +- src/SIL.Harmony.Tests/CommitTests.cs | 2 +- src/SIL.Harmony.Tests/ConfigTests.cs | 2 +- .../Core/HybridDateTimeTests.cs | 6 +++--- .../DataModelIntegrityTests.cs | 2 +- .../DataModelPerformanceTests.cs | 18 +++++++++--------- .../DataModelReferenceTests.cs | 6 +++--- .../DataModelSimpleChanges.cs | 2 +- src/SIL.Harmony.Tests/DataModelTestBase.cs | 17 ++++++++++------- src/SIL.Harmony.Tests/DataQueryTests.cs | 6 +++--- src/SIL.Harmony.Tests/DbContextTests.cs | 2 +- src/SIL.Harmony.Tests/DefinitionTests.cs | 6 +++--- src/SIL.Harmony.Tests/DeleteAndCreateTests.cs | 2 +- src/SIL.Harmony.Tests/ExampleSentenceTests.cs | 6 +++--- src/SIL.Harmony.Tests/GlobalUsings.cs | 2 +- .../Mocks/MockTimeProvider.cs | 2 +- src/SIL.Harmony.Tests/ModelSnapshotTests.cs | 2 +- src/SIL.Harmony.Tests/ModuleInit.cs | 4 ++-- src/SIL.Harmony.Tests/MultiThreadingTests.cs | 2 +- .../ObjectBaseTestingHelpers.cs | 4 ++-- src/SIL.Harmony.Tests/PersistExtraDataTests.cs | 2 +- src/SIL.Harmony.Tests/RepositoryTests.cs | 12 +++++++----- .../RemoteResourcesMetadataTests.cs | 2 +- .../ResourceTests/RemoteResourcesTests.cs | 2 +- .../ResourceTests/RemoteServiceMock.cs | 2 +- .../ResourceTests/WordResourceTests.cs | 5 +++-- src/SIL.Harmony.Tests/SnapshotTests.cs | 6 +++--- src/SIL.Harmony.Tests/SyncTests.cs | 6 +++--- .../Adapters/CustomAdapterProvider.cs | 4 ++-- .../Adapters/DefaultAdapterProvider.cs | 2 +- .../Adapters/IObjectAdapterProvider.cs | 2 +- src/SIL.Harmony/Changes/DeleteChange.cs | 2 +- src/SIL.Harmony/Changes/SetOrderChange.cs | 2 +- src/SIL.Harmony/CommitValidationException.cs | 6 +++--- src/SIL.Harmony/CrdtConfig.cs | 8 ++++---- src/SIL.Harmony/CrdtKernel.cs | 2 +- src/SIL.Harmony/DataModel.cs | 5 ++++- src/SIL.Harmony/Db/CrdtDbContextFactory.cs | 2 +- .../Db/CrdtDbContextOptionsExtensions.cs | 2 +- src/SIL.Harmony/Db/CrdtRepository.cs | 6 +++--- src/SIL.Harmony/Entities/IPolyType.cs | 4 ++-- src/SIL.Harmony/Helpers/DerivedTypeHelper.cs | 4 ++-- src/SIL.Harmony/Helpers/LinqHelpers.cs | 8 ++++---- .../Resource/CreateRemoteResourceChange.cs | 2 +- .../CreateRemoteResourcePendingUpload.cs | 2 +- src/SIL.Harmony/Resource/HarmonyResource.cs | 4 ++-- src/SIL.Harmony/Resource/LocalResource.cs | 2 +- src/SIL.Harmony/Resource/RemoteResource.cs | 2 +- .../RemoteResourceNotEnabledException.cs | 2 +- .../Resource/RemoteResourceUploadedChange.cs | 2 +- src/SIL.Harmony/ResourceService.cs | 6 +++--- src/SIL.Harmony/SnapshotWorker.cs | 4 ++-- src/SIL.Harmony/SyncHelper.cs | 5 +++-- 84 files changed, 159 insertions(+), 149 deletions(-) diff --git a/src/SIL.Harmony.Core/ChangeEntity.cs b/src/SIL.Harmony.Core/ChangeEntity.cs index fec7213..4668988 100644 --- a/src/SIL.Harmony.Core/ChangeEntity.cs +++ b/src/SIL.Harmony.Core/ChangeEntity.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace SIL.Harmony.Core; diff --git a/src/SIL.Harmony.Core/CommitBase.cs b/src/SIL.Harmony.Core/CommitBase.cs index f60930b..265230b 100644 --- a/src/SIL.Harmony.Core/CommitBase.cs +++ b/src/SIL.Harmony.Core/CommitBase.cs @@ -1,4 +1,4 @@ -using System.IO.Hashing; +using System.IO.Hashing; using System.Text.Json.Serialization; namespace SIL.Harmony.Core; diff --git a/src/SIL.Harmony.Core/CommitMetadata.cs b/src/SIL.Harmony.Core/CommitMetadata.cs index eae61f5..b5493ff 100644 --- a/src/SIL.Harmony.Core/CommitMetadata.cs +++ b/src/SIL.Harmony.Core/CommitMetadata.cs @@ -1,4 +1,4 @@ -namespace SIL.Harmony.Core; +namespace SIL.Harmony.Core; public class CommitMetadata { diff --git a/src/SIL.Harmony.Core/CrdtConstants.cs b/src/SIL.Harmony.Core/CrdtConstants.cs index 215eca9..ae05e54 100644 --- a/src/SIL.Harmony.Core/CrdtConstants.cs +++ b/src/SIL.Harmony.Core/CrdtConstants.cs @@ -1,4 +1,4 @@ -namespace SIL.Harmony.Core; +namespace SIL.Harmony.Core; public static class CrdtConstants { diff --git a/src/SIL.Harmony.Core/EntityNotFoundException.cs b/src/SIL.Harmony.Core/EntityNotFoundException.cs index 6bcbb0a..eba1090 100644 --- a/src/SIL.Harmony.Core/EntityNotFoundException.cs +++ b/src/SIL.Harmony.Core/EntityNotFoundException.cs @@ -1,3 +1,3 @@ -namespace SIL.Harmony.Core; +namespace SIL.Harmony.Core; public class EntityNotFoundException(string message) : Exception(message); diff --git a/src/SIL.Harmony.Core/HybridDateTime.cs b/src/SIL.Harmony.Core/HybridDateTime.cs index e3a2510..c40b067 100644 --- a/src/SIL.Harmony.Core/HybridDateTime.cs +++ b/src/SIL.Harmony.Core/HybridDateTime.cs @@ -1,4 +1,4 @@ - + namespace SIL.Harmony.Core; /// diff --git a/src/SIL.Harmony.Core/IChangeContext.cs b/src/SIL.Harmony.Core/IChangeContext.cs index e9efd0f..1c92da6 100644 --- a/src/SIL.Harmony.Core/IChangeContext.cs +++ b/src/SIL.Harmony.Core/IChangeContext.cs @@ -8,7 +8,7 @@ public interface IChangeContext { var snapshot = await GetSnapshot(entityId); if (snapshot is null) return null; - return (T) snapshot.Entity.DbObject; + return (T)snapshot.Entity.DbObject; } public async ValueTask IsObjectDeleted(Guid entityId) => (await GetSnapshot(entityId))?.EntityIsDeleted ?? true; diff --git a/src/SIL.Harmony.Core/IObjectBase.cs b/src/SIL.Harmony.Core/IObjectBase.cs index a3646ce..3f574cd 100644 --- a/src/SIL.Harmony.Core/IObjectBase.cs +++ b/src/SIL.Harmony.Core/IObjectBase.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace SIL.Harmony.Core; diff --git a/src/SIL.Harmony.Core/IRemoteResourceService.cs b/src/SIL.Harmony.Core/IRemoteResourceService.cs index d5725d3..fe0b1b6 100644 --- a/src/SIL.Harmony.Core/IRemoteResourceService.cs +++ b/src/SIL.Harmony.Core/IRemoteResourceService.cs @@ -1,4 +1,4 @@ -namespace SIL.Harmony.Core; +namespace SIL.Harmony.Core; /// /// interface to facilitate downloading of resources, typically implemented in application code diff --git a/src/SIL.Harmony.Core/QueryHelpers.cs b/src/SIL.Harmony.Core/QueryHelpers.cs index 7bf1c54..55c67fa 100644 --- a/src/SIL.Harmony.Core/QueryHelpers.cs +++ b/src/SIL.Harmony.Core/QueryHelpers.cs @@ -111,7 +111,7 @@ private static IEnumerable GetMissingCommitsForClient( } } - public static IQueryable DefaultOrder(this IQueryable queryable) where T: CommitBase + public static IQueryable DefaultOrder(this IQueryable queryable) where T : CommitBase { return queryable .OrderBy(c => c.HybridDateTime.DateTime) @@ -119,7 +119,7 @@ public static IQueryable DefaultOrder(this IQueryable queryable) where .ThenBy(c => c.Id); } - public static IEnumerable DefaultOrder(this IEnumerable queryable) where T: CommitBase + public static IEnumerable DefaultOrder(this IEnumerable queryable) where T : CommitBase { return queryable .OrderBy(c => c.HybridDateTime.DateTime) @@ -127,7 +127,7 @@ public static IEnumerable DefaultOrder(this IEnumerable queryable) wher .ThenBy(c => c.Id); } - public static IQueryable DefaultOrderDescending(this IQueryable queryable) where T: CommitBase + public static IQueryable DefaultOrderDescending(this IQueryable queryable) where T : CommitBase { return queryable .OrderByDescending(c => c.HybridDateTime.DateTime) diff --git a/src/SIL.Harmony.Core/ServerCommit.cs b/src/SIL.Harmony.Core/ServerCommit.cs index 535ee84..d540770 100644 --- a/src/SIL.Harmony.Core/ServerCommit.cs +++ b/src/SIL.Harmony.Core/ServerCommit.cs @@ -1,4 +1,4 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization; using System.Text.Json; using System.Text.Json.Serialization; diff --git a/src/SIL.Harmony.Core/SyncState.cs b/src/SIL.Harmony.Core/SyncState.cs index 57e3e07..c743a40 100644 --- a/src/SIL.Harmony.Core/SyncState.cs +++ b/src/SIL.Harmony.Core/SyncState.cs @@ -1,4 +1,4 @@ -namespace SIL.Harmony.Core; +namespace SIL.Harmony.Core; public record SyncState(Dictionary ClientHeads); public interface IChangesResult @@ -6,7 +6,7 @@ public interface IChangesResult IEnumerable MissingFromClient { get; } SyncState ServerSyncState { get; } } -public record ChangesResult(TCommit[] MissingFromClient, SyncState ServerSyncState): IChangesResult where TCommit : CommitBase +public record ChangesResult(TCommit[] MissingFromClient, SyncState ServerSyncState) : IChangesResult where TCommit : CommitBase { IEnumerable IChangesResult.MissingFromClient => MissingFromClient; public static ChangesResult Empty => new([], new SyncState([])); diff --git a/src/SIL.Harmony.Linq2db/Linq2dbKernel.cs b/src/SIL.Harmony.Linq2db/Linq2dbKernel.cs index a4d9f8f..82f990a 100644 --- a/src/SIL.Harmony.Linq2db/Linq2dbKernel.cs +++ b/src/SIL.Harmony.Linq2db/Linq2dbKernel.cs @@ -1,10 +1,10 @@ -using SIL.Harmony.Core; using LinqToDB.EntityFrameworkCore; using LinqToDB.Extensions.Logging; using LinqToDB.Mapping; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using SIL.Harmony.Core; namespace SIL.Harmony.Linq2db; diff --git a/src/SIL.Harmony.Sample/Changes/AddWordImageChange.cs b/src/SIL.Harmony.Sample/Changes/AddWordImageChange.cs index 009e6d1..b17669a 100644 --- a/src/SIL.Harmony.Sample/Changes/AddWordImageChange.cs +++ b/src/SIL.Harmony.Sample/Changes/AddWordImageChange.cs @@ -12,4 +12,4 @@ public override async ValueTask ApplyChange(Word entity, IChangeContext context) { if (!await context.IsObjectDeleted(ImageId)) entity.ImageResourceId = ImageId; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Sample/Changes/EditExampleChange.cs b/src/SIL.Harmony.Sample/Changes/EditExampleChange.cs index 187f3c5..28fe5b1 100644 --- a/src/SIL.Harmony.Sample/Changes/EditExampleChange.cs +++ b/src/SIL.Harmony.Sample/Changes/EditExampleChange.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/Changes/NewDefinitionChange.cs b/src/SIL.Harmony.Sample/Changes/NewDefinitionChange.cs index 8804c1c..c7c7fc5 100644 --- a/src/SIL.Harmony.Sample/Changes/NewDefinitionChange.cs +++ b/src/SIL.Harmony.Sample/Changes/NewDefinitionChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/Changes/NewExampleChange.cs b/src/SIL.Harmony.Sample/Changes/NewExampleChange.cs index fb04a40..f54b80c 100644 --- a/src/SIL.Harmony.Sample/Changes/NewExampleChange.cs +++ b/src/SIL.Harmony.Sample/Changes/NewExampleChange.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; @@ -41,7 +41,7 @@ public override async ValueTask NewEntity(Commit commit, IChangeContext Id = EntityId, DefinitionId = DefinitionId, YTextBlob = UpdateBlob, - DeletedAt = await context.IsObjectDeleted(DefinitionId)? commit.DateTime : null + DeletedAt = await context.IsObjectDeleted(DefinitionId) ? commit.DateTime : null }; } } diff --git a/src/SIL.Harmony.Sample/Changes/NewWordChange.cs b/src/SIL.Harmony.Sample/Changes/NewWordChange.cs index 2cf7c48..7bc793e 100644 --- a/src/SIL.Harmony.Sample/Changes/NewWordChange.cs +++ b/src/SIL.Harmony.Sample/Changes/NewWordChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/Changes/SetAntonymReferenceChange.cs b/src/SIL.Harmony.Sample/Changes/SetAntonymReferenceChange.cs index 4e02ed1..aabdf53 100644 --- a/src/SIL.Harmony.Sample/Changes/SetAntonymReferenceChange.cs +++ b/src/SIL.Harmony.Sample/Changes/SetAntonymReferenceChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/Changes/SetDefinitionPartOfSpeechChange.cs b/src/SIL.Harmony.Sample/Changes/SetDefinitionPartOfSpeechChange.cs index 7f16ad4..00a11fc 100644 --- a/src/SIL.Harmony.Sample/Changes/SetDefinitionPartOfSpeechChange.cs +++ b/src/SIL.Harmony.Sample/Changes/SetDefinitionPartOfSpeechChange.cs @@ -13,4 +13,4 @@ public override ValueTask ApplyChange(Definition entity, IChangeContext context) entity.PartOfSpeech = PartOfSpeech; return ValueTask.CompletedTask; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Sample/Changes/SetTagChange.cs b/src/SIL.Harmony.Sample/Changes/SetTagChange.cs index e5e3699..63e2c4d 100644 --- a/src/SIL.Harmony.Sample/Changes/SetTagChange.cs +++ b/src/SIL.Harmony.Sample/Changes/SetTagChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; @@ -15,7 +15,7 @@ public override async ValueTask NewEntity(Commit commit, IChangeContext con { Id = EntityId, Text = Text, - DeletedAt = tagExists ? commit.DateTime : null + DeletedAt = tagExists ? commit.DateTime : null }; } diff --git a/src/SIL.Harmony.Sample/Changes/SetWordNoteChange.cs b/src/SIL.Harmony.Sample/Changes/SetWordNoteChange.cs index e8360a7..a03629e 100644 --- a/src/SIL.Harmony.Sample/Changes/SetWordNoteChange.cs +++ b/src/SIL.Harmony.Sample/Changes/SetWordNoteChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/Changes/SetWordTextChange.cs b/src/SIL.Harmony.Sample/Changes/SetWordTextChange.cs index 3d782de..314fec3 100644 --- a/src/SIL.Harmony.Sample/Changes/SetWordTextChange.cs +++ b/src/SIL.Harmony.Sample/Changes/SetWordTextChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/Changes/TagWordChange.cs b/src/SIL.Harmony.Sample/Changes/TagWordChange.cs index 2614e1e..14475ed 100644 --- a/src/SIL.Harmony.Sample/Changes/TagWordChange.cs +++ b/src/SIL.Harmony.Sample/Changes/TagWordChange.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using SIL.Harmony.Changes; using SIL.Harmony.Entities; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/CrdtSampleKernel.cs b/src/SIL.Harmony.Sample/CrdtSampleKernel.cs index 40491b5..5a9dbab 100644 --- a/src/SIL.Harmony.Sample/CrdtSampleKernel.cs +++ b/src/SIL.Harmony.Sample/CrdtSampleKernel.cs @@ -1,10 +1,10 @@ using System.Diagnostics; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using SIL.Harmony.Changes; using SIL.Harmony.Linq2db; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; namespace SIL.Harmony.Sample; diff --git a/src/SIL.Harmony.Sample/Models/Definition.cs b/src/SIL.Harmony.Sample/Models/Definition.cs index 4eef28f..8fb5e24 100644 --- a/src/SIL.Harmony.Sample/Models/Definition.cs +++ b/src/SIL.Harmony.Sample/Models/Definition.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; namespace SIL.Harmony.Sample.Models; @@ -39,4 +39,4 @@ public IObjectBase Copy() DeletedAt = DeletedAt }; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Sample/Models/Example.cs b/src/SIL.Harmony.Sample/Models/Example.cs index bd78191..8606f80 100644 --- a/src/SIL.Harmony.Sample/Models/Example.cs +++ b/src/SIL.Harmony.Sample/Models/Example.cs @@ -1,10 +1,10 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using SIL.Harmony.Entities; using Ycs; namespace SIL.Harmony.Sample.Models; -public class Example: IObjectBase +public class Example : IObjectBase { public Guid Id { get; init; } public DateTimeOffset? DeletedAt { get; set; } @@ -49,4 +49,4 @@ public IObjectBase Copy() YTextBlob = YTextBlob }; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Sample/Models/Tag.cs b/src/SIL.Harmony.Sample/Models/Tag.cs index 82e687f..0f77e2b 100644 --- a/src/SIL.Harmony.Sample/Models/Tag.cs +++ b/src/SIL.Harmony.Sample/Models/Tag.cs @@ -27,4 +27,4 @@ public IObjectBase Copy() DeletedAt = DeletedAt }; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Sample/Models/Word.cs b/src/SIL.Harmony.Sample/Models/Word.cs index 5a8fe05..866fb49 100644 --- a/src/SIL.Harmony.Sample/Models/Word.cs +++ b/src/SIL.Harmony.Sample/Models/Word.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Entities; +using SIL.Harmony.Entities; namespace SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Sample/Models/WordTag.cs b/src/SIL.Harmony.Sample/Models/WordTag.cs index a067114..4bb3716 100644 --- a/src/SIL.Harmony.Sample/Models/WordTag.cs +++ b/src/SIL.Harmony.Sample/Models/WordTag.cs @@ -32,4 +32,4 @@ public IObjectBase Copy() DeletedAt = DeletedAt }; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Sample/SampleDbContext.cs b/src/SIL.Harmony.Sample/SampleDbContext.cs index a1ef3da..4523ec9 100644 --- a/src/SIL.Harmony.Sample/SampleDbContext.cs +++ b/src/SIL.Harmony.Sample/SampleDbContext.cs @@ -1,11 +1,11 @@ -using SIL.Harmony.Changes; -using SIL.Harmony.Db; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; +using SIL.Harmony.Changes; +using SIL.Harmony.Db; namespace SIL.Harmony.Sample; -public class SampleDbContext(DbContextOptionsoptions, IOptions crdtConfig): DbContext(options), ICrdtDbContext +public class SampleDbContext(DbContextOptions options, IOptions crdtConfig) : DbContext(options), ICrdtDbContext { protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -15,4 +15,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) public DbSet Commits => Set(); public DbSet> ChangeEntities => Set>(); public DbSet Snapshots => Set(); -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/Adapter/CustomObjectAdapterTests.cs b/src/SIL.Harmony.Tests/Adapter/CustomObjectAdapterTests.cs index 0be8f90..0ecea1c 100644 --- a/src/SIL.Harmony.Tests/Adapter/CustomObjectAdapterTests.cs +++ b/src/SIL.Harmony.Tests/Adapter/CustomObjectAdapterTests.cs @@ -196,4 +196,4 @@ await dataModel.AddChange(Guid.NewGuid(), dataModel.QueryLatest().ToBlockingEnumerable(TestContext.Current.CancellationToken).Should().NotBeEmpty(); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/CommitTests.cs b/src/SIL.Harmony.Tests/CommitTests.cs index 660f3ca..ce24adf 100644 --- a/src/SIL.Harmony.Tests/CommitTests.cs +++ b/src/SIL.Harmony.Tests/CommitTests.cs @@ -1,9 +1,9 @@ using System.IO.Hashing; using System.Text.Json; +using Microsoft.Extensions.DependencyInjection; using SIL.Harmony.Changes; using SIL.Harmony.Sample; using SIL.Harmony.Sample.Changes; -using Microsoft.Extensions.DependencyInjection; namespace SIL.Harmony.Tests; diff --git a/src/SIL.Harmony.Tests/ConfigTests.cs b/src/SIL.Harmony.Tests/ConfigTests.cs index 89b41b5..e8ca40d 100644 --- a/src/SIL.Harmony.Tests/ConfigTests.cs +++ b/src/SIL.Harmony.Tests/ConfigTests.cs @@ -29,4 +29,4 @@ public void CanGetChangeTypes() var types = config.ChangeTypes.ToArray(); types.Should().BeEquivalentTo([typeof(NewDefinitionChange), typeof(SetWordTextChange)]); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs b/src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs index 840bec1..cb75ae3 100644 --- a/src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs +++ b/src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs @@ -10,7 +10,7 @@ public void Equals_TrueWhenTheSame() (dateTime == otherDateTime).Should().BeTrue(); } - + [Fact] public void Equals_FalseWhenDifferentDateTime() { @@ -19,7 +19,7 @@ public void Equals_FalseWhenDifferentDateTime() (dateTime != otherDateTime).Should().BeTrue(); } - + [Fact] public void Equals_FalseWhenDifferentCounter() { @@ -72,4 +72,4 @@ public void CompareTo_ReturnsOneWhenThisIsGreaterThanOther() var result = dateTime.CompareTo(otherDateTime); result.Should().Be(1); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/DataModelIntegrityTests.cs b/src/SIL.Harmony.Tests/DataModelIntegrityTests.cs index dee531f..a4382cc 100644 --- a/src/SIL.Harmony.Tests/DataModelIntegrityTests.cs +++ b/src/SIL.Harmony.Tests/DataModelIntegrityTests.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Sample.Models; +using SIL.Harmony.Sample.Models; namespace SIL.Harmony.Tests; diff --git a/src/SIL.Harmony.Tests/DataModelPerformanceTests.cs b/src/SIL.Harmony.Tests/DataModelPerformanceTests.cs index 3e97ac8..5eca65c 100644 --- a/src/SIL.Harmony.Tests/DataModelPerformanceTests.cs +++ b/src/SIL.Harmony.Tests/DataModelPerformanceTests.cs @@ -20,9 +20,9 @@ public class DataModelPerformanceTests(ITestOutputHelper output) [Fact] public void AddingChangePerformance() { - #if DEBUG +#if DEBUG Assert.Fail("This test is disabled in debug builds, not reliable"); - #endif +#endif var summary = BenchmarkRunner.Run( ManualConfig.CreateEmpty() @@ -38,7 +38,7 @@ public void AddingChangePerformance() ratio.Should().BeInRange(0, 7, "performance should not get worse, benchmark " + benchmarkCase.DisplayInfo); } } - + //enable this to profile tests private static readonly bool trace = (Environment.GetEnvironmentVariable("DOTNET_TRACE") ?? "false") != "false"; private async Task StartTrace() @@ -53,14 +53,14 @@ private async Task StartTrace() DotTrace.Attach(config); DotTrace.StartCollectingData(); } - + private void StopTrace() { if (!trace) return; DotTrace.SaveData(); DotTrace.Detach(); } - + private static async Task MeasureTime(Func action, int iterations = 10) { var total = TimeSpan.Zero; @@ -105,7 +105,7 @@ internal static async Task BulkInsertChanges(DataModelTestBase dataModelTest, in var parentHash = (await dataModelTest.WriteNextChange(dataModelTest.SetWord(Guid.NewGuid(), "entity 1"))).Hash; for (var i = 0; i < count; i++) { - var change = (SetWordTextChange) dataModelTest.SetWord(Guid.NewGuid(), $"entity {i}"); + var change = (SetWordTextChange)dataModelTest.SetWord(Guid.NewGuid(), $"entity {i}"); var commitId = Guid.NewGuid(); var commit = new Commit(commitId) { @@ -206,13 +206,13 @@ public void IterationSetup() _ = _emptyDataModel.WriteNextChange(_emptyDataModel.SetWord(Guid.NewGuid(), "entity1")).Result; _dataModelTestBase = _templateModel.ForkDatabase(false); } - + [Benchmark(Baseline = true), BenchmarkCategory("WriteChange")] public Commit AddSingleChangePerformance() { return _emptyDataModel.WriteNextChange(_emptyDataModel.SetWord(Guid.NewGuid(), "entity1")).Result; } - + [Benchmark, BenchmarkCategory("WriteChange")] public Commit AddSingleChangeWithManySnapshots() { @@ -235,4 +235,4 @@ public void GlobalCleanup() _templateModel.DisposeAsync().GetAwaiter().GetResult(); } } -#pragma warning restore VSTHRD002 \ No newline at end of file +#pragma warning restore VSTHRD002 diff --git a/src/SIL.Harmony.Tests/DataModelReferenceTests.cs b/src/SIL.Harmony.Tests/DataModelReferenceTests.cs index 7d77c4f..064234c 100644 --- a/src/SIL.Harmony.Tests/DataModelReferenceTests.cs +++ b/src/SIL.Harmony.Tests/DataModelReferenceTests.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using SIL.Harmony.Changes; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; @@ -342,10 +342,10 @@ await AddCommitsViaSync([ deleteWordCommit ]); var snapshot = await DbContext.Snapshots.SingleAsync(s => s.CommitId == initialWordCommit.Id, TestContext.Current.CancellationToken); - var initialWord = (Word) snapshot.Entity; + var initialWord = (Word)snapshot.Entity; initialWord.AntonymId.Should().Be(_word1Id); snapshot = await DbContext.Snapshots.SingleAsync(s => s.CommitId == deleteWordCommit.Id && s.EntityId == wordId, TestContext.Current.CancellationToken); - var wordWithoutRef = (Word) snapshot.Entity; + var wordWithoutRef = (Word)snapshot.Entity; wordWithoutRef.AntonymId.Should().BeNull(); } diff --git a/src/SIL.Harmony.Tests/DataModelSimpleChanges.cs b/src/SIL.Harmony.Tests/DataModelSimpleChanges.cs index 8d92cc1..39f9907 100644 --- a/src/SIL.Harmony.Tests/DataModelSimpleChanges.cs +++ b/src/SIL.Harmony.Tests/DataModelSimpleChanges.cs @@ -1,8 +1,8 @@ +using Microsoft.EntityFrameworkCore; using SIL.Harmony.Changes; using SIL.Harmony.Db; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; -using Microsoft.EntityFrameworkCore; namespace SIL.Harmony.Tests; diff --git a/src/SIL.Harmony.Tests/DataModelTestBase.cs b/src/SIL.Harmony.Tests/DataModelTestBase.cs index 77a87be..756162d 100644 --- a/src/SIL.Harmony.Tests/DataModelTestBase.cs +++ b/src/SIL.Harmony.Tests/DataModelTestBase.cs @@ -1,13 +1,13 @@ using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using SIL.Harmony.Changes; +using SIL.Harmony.Db; using SIL.Harmony.Sample; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; using SIL.Harmony.Tests.Mocks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using SIL.Harmony.Db; namespace SIL.Harmony.Tests; @@ -47,7 +47,7 @@ public DataModelTestBase(SqliteConnection connection, bool alwaysValidate = true DbContext.Database.EnsureCreated(); DataModel = _services.GetRequiredService(); } - + public DataModelTestBase ForkDatabase(bool alwaysValidate = true) { var connection = new SqliteConnection("Data Source=:memory:"); @@ -110,7 +110,10 @@ protected async ValueTask WriteChange(Guid clientId, }; commit.ChangeEntities.AddRange(changes.Select((change, index) => new ChangeEntity { - Change = change, Index = index, CommitId = commit.Id, EntityId = change.EntityId + Change = change, + Index = index, + CommitId = commit.Id, + EntityId = change.EntityId })); return commit; } @@ -184,4 +187,4 @@ protected IEnumerable AllData() .OfType() .Concat(DbContext.Set().OrderBy(w => w.Text)); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/DataQueryTests.cs b/src/SIL.Harmony.Tests/DataQueryTests.cs index 37705b2..73c182a 100644 --- a/src/SIL.Harmony.Tests/DataQueryTests.cs +++ b/src/SIL.Harmony.Tests/DataQueryTests.cs @@ -1,9 +1,9 @@ -using SIL.Harmony.Sample.Models; using Microsoft.EntityFrameworkCore; +using SIL.Harmony.Sample.Models; namespace SIL.Harmony.Tests; -public class DataQueryTests: DataModelTestBase +public class DataQueryTests : DataModelTestBase { private readonly Guid _entity1Id = Guid.NewGuid(); public override async ValueTask InitializeAsync() @@ -19,4 +19,4 @@ public async Task CanQueryLatestData() var entry = entries.Should().ContainSingle().Subject; entry.Text.Should().Be("entity1"); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/DbContextTests.cs b/src/SIL.Harmony.Tests/DbContextTests.cs index 3b7677d..8733439 100644 --- a/src/SIL.Harmony.Tests/DbContextTests.cs +++ b/src/SIL.Harmony.Tests/DbContextTests.cs @@ -5,7 +5,7 @@ namespace SIL.Harmony.Tests; -public class DbContextTests: DataModelTestBase +public class DbContextTests : DataModelTestBase { [Fact] public async Task VerifyModel() diff --git a/src/SIL.Harmony.Tests/DefinitionTests.cs b/src/SIL.Harmony.Tests/DefinitionTests.cs index 40ceac0..82ae35d 100644 --- a/src/SIL.Harmony.Tests/DefinitionTests.cs +++ b/src/SIL.Harmony.Tests/DefinitionTests.cs @@ -1,6 +1,6 @@ -using SIL.Harmony.Changes; -using SIL.Harmony.Sample.Models; using Microsoft.EntityFrameworkCore; +using SIL.Harmony.Changes; +using SIL.Harmony.Sample.Models; namespace SIL.Harmony.Tests; @@ -104,4 +104,4 @@ public async Task ConsistentlySortsItems() definitionAId ); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/DeleteAndCreateTests.cs b/src/SIL.Harmony.Tests/DeleteAndCreateTests.cs index 0397054..d9797e1 100644 --- a/src/SIL.Harmony.Tests/DeleteAndCreateTests.cs +++ b/src/SIL.Harmony.Tests/DeleteAndCreateTests.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using SIL.Harmony.Changes; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; diff --git a/src/SIL.Harmony.Tests/ExampleSentenceTests.cs b/src/SIL.Harmony.Tests/ExampleSentenceTests.cs index aba4a6c..e2670db 100644 --- a/src/SIL.Harmony.Tests/ExampleSentenceTests.cs +++ b/src/SIL.Harmony.Tests/ExampleSentenceTests.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; @@ -10,7 +10,7 @@ public IChange NewExampleSentence(Guid wordId, string text, Guid? exampleId = de { return NewExampleChange.FromString(wordId, text, exampleId); } - + [Fact] public async Task CanAddAnExampleSentenceToAWord() { @@ -69,4 +69,4 @@ public async Task CanEditExampleText() actualExample.Should().NotBeSameAs(example); actualExample!.YText.ToString().Should().Be("Yo What's up Bob"); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/GlobalUsings.cs b/src/SIL.Harmony.Tests/GlobalUsings.cs index 7fef4b0..7b25ddd 100644 --- a/src/SIL.Harmony.Tests/GlobalUsings.cs +++ b/src/SIL.Harmony.Tests/GlobalUsings.cs @@ -1,2 +1,2 @@ +global using FluentAssertions; global using Xunit; -global using FluentAssertions; \ No newline at end of file diff --git a/src/SIL.Harmony.Tests/Mocks/MockTimeProvider.cs b/src/SIL.Harmony.Tests/Mocks/MockTimeProvider.cs index 30d5f67..809d634 100644 --- a/src/SIL.Harmony.Tests/Mocks/MockTimeProvider.cs +++ b/src/SIL.Harmony.Tests/Mocks/MockTimeProvider.cs @@ -1,6 +1,6 @@ namespace SIL.Harmony.Tests.Mocks; -public class MockTimeProvider: IHybridDateTimeProvider +public class MockTimeProvider : IHybridDateTimeProvider { public static HybridDateTime Time(int hour, int counter = 0) => new(new DateTime(2022, 1, 1, 0, 0, 0).AddHours(hour), counter); private HybridDateTime? _nextDateTime; diff --git a/src/SIL.Harmony.Tests/ModelSnapshotTests.cs b/src/SIL.Harmony.Tests/ModelSnapshotTests.cs index a638445..0924deb 100644 --- a/src/SIL.Harmony.Tests/ModelSnapshotTests.cs +++ b/src/SIL.Harmony.Tests/ModelSnapshotTests.cs @@ -1,5 +1,5 @@ -using SIL.Harmony.Sample.Models; using Microsoft.EntityFrameworkCore; +using SIL.Harmony.Sample.Models; namespace SIL.Harmony.Tests; diff --git a/src/SIL.Harmony.Tests/ModuleInit.cs b/src/SIL.Harmony.Tests/ModuleInit.cs index 3d3b9ab..35aff33 100644 --- a/src/SIL.Harmony.Tests/ModuleInit.cs +++ b/src/SIL.Harmony.Tests/ModuleInit.cs @@ -1,8 +1,8 @@ using System.Linq.Expressions; using System.Runtime.CompilerServices; using Argon; -using SIL.Harmony.Sample; using Microsoft.Extensions.DependencyInjection; +using SIL.Harmony.Sample; namespace SIL.Harmony.Tests; @@ -46,4 +46,4 @@ private static void AddHashConverter(Expression> expression) return $"Hash_{index + 1}"; }); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/MultiThreadingTests.cs b/src/SIL.Harmony.Tests/MultiThreadingTests.cs index 6efee0f..b6d6855 100644 --- a/src/SIL.Harmony.Tests/MultiThreadingTests.cs +++ b/src/SIL.Harmony.Tests/MultiThreadingTests.cs @@ -63,4 +63,4 @@ public async Task CanApplyChangesWithoutError() } } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/ObjectBaseTestingHelpers.cs b/src/SIL.Harmony.Tests/ObjectBaseTestingHelpers.cs index 41ad0d6..9002760 100644 --- a/src/SIL.Harmony.Tests/ObjectBaseTestingHelpers.cs +++ b/src/SIL.Harmony.Tests/ObjectBaseTestingHelpers.cs @@ -4,6 +4,6 @@ public static class ObjectBaseTestingHelpers { public static T Is(this IObjectBase obj) where T : class { - return (T) obj.DbObject; + return (T)obj.DbObject; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/PersistExtraDataTests.cs b/src/SIL.Harmony.Tests/PersistExtraDataTests.cs index 4182729..9eb6993 100644 --- a/src/SIL.Harmony.Tests/PersistExtraDataTests.cs +++ b/src/SIL.Harmony.Tests/PersistExtraDataTests.cs @@ -82,4 +82,4 @@ public async Task CanPersistExtraData() extraDataModel.DateTime.Should().Be(commit.HybridDateTime.DateTime); extraDataModel.Counter.Should().Be(commit.HybridDateTime.Counter); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony.Tests/RepositoryTests.cs b/src/SIL.Harmony.Tests/RepositoryTests.cs index 3a697ea..45acfd8 100644 --- a/src/SIL.Harmony.Tests/RepositoryTests.cs +++ b/src/SIL.Harmony.Tests/RepositoryTests.cs @@ -1,12 +1,12 @@ -using SIL.Harmony.Db; -using SIL.Harmony.Sample; -using SIL.Harmony.Sample.Models; -using SIL.Harmony.Tests.Mocks; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using SIL.Harmony.Changes; +using SIL.Harmony.Db; +using SIL.Harmony.Sample; using SIL.Harmony.Sample.Changes; +using SIL.Harmony.Sample.Models; +using SIL.Harmony.Tests.Mocks; namespace SIL.Harmony.Tests; @@ -44,7 +44,9 @@ private Commit Commit(Guid id, HybridDateTime hybridDateTime) var entityId = Guid.NewGuid(); return new Commit(id) { - ClientId = Guid.Empty, HybridDateTime = hybridDateTime, ChangeEntities = + ClientId = Guid.Empty, + HybridDateTime = hybridDateTime, + ChangeEntities = [ new ChangeEntity() { diff --git a/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesMetadataTests.cs b/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesMetadataTests.cs index ce7ac98..bc1b798 100644 --- a/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesMetadataTests.cs +++ b/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesMetadataTests.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using Microsoft.Extensions.DependencyInjection; using SIL.Harmony.Resource; using SIL.Harmony.Sample; diff --git a/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs b/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs index fa65dab..d0573f4 100644 --- a/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs +++ b/src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using SIL.Harmony.Resource; diff --git a/src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs b/src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs index b4d880a..7b523e9 100644 --- a/src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs +++ b/src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs @@ -28,7 +28,7 @@ public Task DownloadResource(string remoteId, string localResour File.Copy(remoteId, localPath); return Task.FromResult(new DownloadResult(localPath)); } - + private readonly Queue _throwOnUpload = new(); public async Task> UploadResource(Guid resourceId, string localPath, MediaMetadata? metadata = null) diff --git a/src/SIL.Harmony.Tests/ResourceTests/WordResourceTests.cs b/src/SIL.Harmony.Tests/ResourceTests/WordResourceTests.cs index 15fc149..9dcff80 100644 --- a/src/SIL.Harmony.Tests/ResourceTests/WordResourceTests.cs +++ b/src/SIL.Harmony.Tests/ResourceTests/WordResourceTests.cs @@ -1,10 +1,11 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using Microsoft.Extensions.DependencyInjection; using SIL.Harmony.Sample; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; namespace SIL.Harmony.Tests.ResourceTests; -public class WordResourceTests: DataModelTestBase + +public class WordResourceTests : DataModelTestBase { private RemoteServiceMock _remoteServiceMock = new(); private ResourceService _resourceService => _services.GetRequiredService>(); diff --git a/src/SIL.Harmony.Tests/SnapshotTests.cs b/src/SIL.Harmony.Tests/SnapshotTests.cs index 3a9028b..b136841 100644 --- a/src/SIL.Harmony.Tests/SnapshotTests.cs +++ b/src/SIL.Harmony.Tests/SnapshotTests.cs @@ -1,7 +1,7 @@ -using SIL.Harmony.Sample.Models; -using SIL.Harmony.Sample.Changes; -using SIL.Harmony.Changes; using Microsoft.EntityFrameworkCore; +using SIL.Harmony.Changes; +using SIL.Harmony.Sample.Changes; +using SIL.Harmony.Sample.Models; namespace SIL.Harmony.Tests; diff --git a/src/SIL.Harmony.Tests/SyncTests.cs b/src/SIL.Harmony.Tests/SyncTests.cs index bc49df0..a3d7d66 100644 --- a/src/SIL.Harmony.Tests/SyncTests.cs +++ b/src/SIL.Harmony.Tests/SyncTests.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using SIL.Harmony.Sample.Changes; using SIL.Harmony.Sample.Models; @@ -121,7 +121,7 @@ public async Task CanSync_AddDependentWithMultipleChanges() _client2.DataModel.QueryLatest().ToBlockingEnumerable(TestContext.Current.CancellationToken).Should() .BeEquivalentTo(_client1.DataModel.QueryLatest().ToBlockingEnumerable(TestContext.Current.CancellationToken)); } - + [Fact] public async Task CanSyncCommitsWithMoreEntitiesThanTheSqliteParameterLimit() { @@ -149,4 +149,4 @@ public async Task CanSyncCommitsWithMoreEntitiesThanTheSqliteParameterLimit() _client1.DbContext.Set().Should().HaveCount(totalEntityCount); } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony/Adapters/CustomAdapterProvider.cs b/src/SIL.Harmony/Adapters/CustomAdapterProvider.cs index 00b723e..978bb94 100644 --- a/src/SIL.Harmony/Adapters/CustomAdapterProvider.cs +++ b/src/SIL.Harmony/Adapters/CustomAdapterProvider.cs @@ -18,7 +18,7 @@ public CustomAdapterProvider(ObjectTypeListBuilder objectTypeListBuilder) _objectTypeListBuilder = objectTypeListBuilder; JsonTypes.AddDerivedType(typeof(IObjectBase), typeof(TCustomAdapter), TCustomAdapter.TypeName); } - + public CustomAdapterProvider AddWithCustomPolymorphicMapping(string typeName, Action>? configureEntry = null ) where T : class, TCommonInterface @@ -69,4 +69,4 @@ public interface ICustomAdapter : IObjectBase, IPolyTyp public static abstract TSelf Create(TCommonInterface obj); static string IPolyType.TypeName => TSelf.AdapterTypeName; public static abstract string AdapterTypeName { get; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony/Adapters/DefaultAdapterProvider.cs b/src/SIL.Harmony/Adapters/DefaultAdapterProvider.cs index b764ba9..420019e 100644 --- a/src/SIL.Harmony/Adapters/DefaultAdapterProvider.cs +++ b/src/SIL.Harmony/Adapters/DefaultAdapterProvider.cs @@ -44,4 +44,4 @@ public bool CanAdapt(object obj) } private Dictionary> JsonTypes => objectTypeListBuilder.JsonTypes; -} \ No newline at end of file +} diff --git a/src/SIL.Harmony/Adapters/IObjectAdapterProvider.cs b/src/SIL.Harmony/Adapters/IObjectAdapterProvider.cs index 712223d..3e133f3 100644 --- a/src/SIL.Harmony/Adapters/IObjectAdapterProvider.cs +++ b/src/SIL.Harmony/Adapters/IObjectAdapterProvider.cs @@ -10,4 +10,4 @@ internal interface IObjectAdapterProvider IEnumerable GetRegistrations(); IObjectBase Adapt(object obj); bool CanAdapt(object obj); -} \ No newline at end of file +} diff --git a/src/SIL.Harmony/Changes/DeleteChange.cs b/src/SIL.Harmony/Changes/DeleteChange.cs index 9cd951c..79daca4 100644 --- a/src/SIL.Harmony/Changes/DeleteChange.cs +++ b/src/SIL.Harmony/Changes/DeleteChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Entities; +using SIL.Harmony.Entities; namespace SIL.Harmony.Changes; diff --git a/src/SIL.Harmony/Changes/SetOrderChange.cs b/src/SIL.Harmony/Changes/SetOrderChange.cs index bc42aec..fac189b 100644 --- a/src/SIL.Harmony/Changes/SetOrderChange.cs +++ b/src/SIL.Harmony/Changes/SetOrderChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Entities; +using SIL.Harmony.Entities; namespace SIL.Harmony.Changes; diff --git a/src/SIL.Harmony/CommitValidationException.cs b/src/SIL.Harmony/CommitValidationException.cs index f8f1844..0c5b91e 100644 --- a/src/SIL.Harmony/CommitValidationException.cs +++ b/src/SIL.Harmony/CommitValidationException.cs @@ -1,8 +1,8 @@ -namespace SIL.Harmony; +namespace SIL.Harmony; -public class CommitValidationException: Exception +public class CommitValidationException : Exception { public CommitValidationException(string message) : base(message) { } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony/CrdtConfig.cs b/src/SIL.Harmony/CrdtConfig.cs index 1d6dc8f..803f064 100644 --- a/src/SIL.Harmony/CrdtConfig.cs +++ b/src/SIL.Harmony/CrdtConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json; +using System.Text.Json; using System.Text.Json.Serialization.Metadata; using Microsoft.EntityFrameworkCore; using SIL.Harmony.Adapters; @@ -37,7 +37,7 @@ public CrdtConfig() TypeInfoResolver = MakeJsonTypeResolver() }); } - + public Action MakeJsonTypeModifier() { return JsonTypeModifier; @@ -173,7 +173,7 @@ internal void CheckFrozen() public DefaultAdapterProvider DefaultAdapter() { CheckFrozen(); - if (AdapterProviders.OfType().SingleOrDefault() is {} adapter) return adapter; + if (AdapterProviders.OfType().SingleOrDefault() is { } adapter) return adapter; adapter = new DefaultAdapterProvider(this); AdapterProviders.Add(adapter); return adapter; @@ -198,7 +198,7 @@ public CustomAdapterProvider CustomAdapter, IPolyType { CheckFrozen(); - if (AdapterProviders.OfType>().SingleOrDefault() is {} adapter) return adapter; + if (AdapterProviders.OfType>().SingleOrDefault() is { } adapter) return adapter; adapter = new CustomAdapterProvider(this); AdapterProviders.Add(adapter); return adapter; diff --git a/src/SIL.Harmony/CrdtKernel.cs b/src/SIL.Harmony/CrdtKernel.cs index aaa43f7..7e4d888 100644 --- a/src/SIL.Harmony/CrdtKernel.cs +++ b/src/SIL.Harmony/CrdtKernel.cs @@ -1,4 +1,4 @@ -using System.Text.Json; +using System.Text.Json; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/SIL.Harmony/DataModel.cs b/src/SIL.Harmony/DataModel.cs index 8707fcb..b572d95 100644 --- a/src/SIL.Harmony/DataModel.cs +++ b/src/SIL.Harmony/DataModel.cs @@ -127,7 +127,10 @@ private static ChangeEntity ToChangeEntity(IChange change, int index, G { return new ChangeEntity() { - Change = change, CommitId = commitId, EntityId = change.EntityId, Index = index + Change = change, + CommitId = commitId, + EntityId = change.EntityId, + Index = index }; } diff --git a/src/SIL.Harmony/Db/CrdtDbContextFactory.cs b/src/SIL.Harmony/Db/CrdtDbContextFactory.cs index e808eca..890b1ee 100644 --- a/src/SIL.Harmony/Db/CrdtDbContextFactory.cs +++ b/src/SIL.Harmony/Db/CrdtDbContextFactory.cs @@ -37,7 +37,7 @@ public ICrdtDbContext CreateDbContext() return new NoDisposeWrapper(dbContext); } - private class NoDisposeWrapper(ICrdtDbContext context): ICrdtDbContext + private class NoDisposeWrapper(ICrdtDbContext context) : ICrdtDbContext { public void Dispose() { diff --git a/src/SIL.Harmony/Db/CrdtDbContextOptionsExtensions.cs b/src/SIL.Harmony/Db/CrdtDbContextOptionsExtensions.cs index f2f26fa..dc402e8 100644 --- a/src/SIL.Harmony/Db/CrdtDbContextOptionsExtensions.cs +++ b/src/SIL.Harmony/Db/CrdtDbContextOptionsExtensions.cs @@ -17,4 +17,4 @@ public static ModelBuilder UseCrdt(this ModelBuilder modelBuilder, } return modelBuilder; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony/Db/CrdtRepository.cs b/src/SIL.Harmony/Db/CrdtRepository.cs index 6312044..fb23e53 100644 --- a/src/SIL.Harmony/Db/CrdtRepository.cs +++ b/src/SIL.Harmony/Db/CrdtRepository.cs @@ -271,13 +271,13 @@ public async Task GetObjectBySnapshotId(Guid snapshotId) .Select(s => s.Entity) .SingleOrDefaultAsync() ?? throw new ArgumentException($"unable to find snapshot with id {snapshotId}"); - return (T) entity; + return (T)entity; } - public async Task GetCurrent(Guid objectId) where T: class + public async Task GetCurrent(Guid objectId) where T : class { var snapshot = await GetCurrentSnapshotByObjectId(objectId); - return (T?) snapshot?.Entity.DbObject; + return (T?)snapshot?.Entity.DbObject; } public IQueryable GetCurrentObjects() where T : class diff --git a/src/SIL.Harmony/Entities/IPolyType.cs b/src/SIL.Harmony/Entities/IPolyType.cs index e7b2089..a68113e 100644 --- a/src/SIL.Harmony/Entities/IPolyType.cs +++ b/src/SIL.Harmony/Entities/IPolyType.cs @@ -1,4 +1,4 @@ -namespace SIL.Harmony.Entities; +namespace SIL.Harmony.Entities; /// /// used to denote a type with a name, used for polymorphic serialization (where there's a type property that discriminates between different types) @@ -8,7 +8,7 @@ public interface IPolyType static abstract string TypeName { get; } } -public interface ISelfNamedType: IPolyType where T : ISelfNamedType +public interface ISelfNamedType : IPolyType where T : ISelfNamedType { static string IPolyType.TypeName => typeof(T).Name; } diff --git a/src/SIL.Harmony/Helpers/DerivedTypeHelper.cs b/src/SIL.Harmony/Helpers/DerivedTypeHelper.cs index 599cf76..0968a69 100644 --- a/src/SIL.Harmony/Helpers/DerivedTypeHelper.cs +++ b/src/SIL.Harmony/Helpers/DerivedTypeHelper.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using System.Text.Json.Serialization.Metadata; using SIL.Harmony.Entities; @@ -29,7 +29,7 @@ private static IList LookupDerivedTypes() return LookupDerivedTypes().SingleOrDefault(dt => dt.TypeDiscriminator as string == discriminator).DerivedType; } - public static string GetEntityDiscriminator() where T: IPolyType + public static string GetEntityDiscriminator() where T : IPolyType { return T.TypeName; } diff --git a/src/SIL.Harmony/Helpers/LinqHelpers.cs b/src/SIL.Harmony/Helpers/LinqHelpers.cs index 10d23be..a217eac 100644 --- a/src/SIL.Harmony/Helpers/LinqHelpers.cs +++ b/src/SIL.Harmony/Helpers/LinqHelpers.cs @@ -20,10 +20,10 @@ internal static IEnumerable FullOuterJoin( keys.UnionWith(blookup.Select(p => p.Key)); var join = from key in keys - from xa in alookup[key].DefaultIfEmpty(defaultA) - from xb in blookup[key].DefaultIfEmpty(defaultB) - select projection(xa, xb, key); + from xa in alookup[key].DefaultIfEmpty(defaultA) + from xb in blookup[key].DefaultIfEmpty(defaultB) + select projection(xa, xb, key); return join; } -} \ No newline at end of file +} diff --git a/src/SIL.Harmony/Resource/CreateRemoteResourceChange.cs b/src/SIL.Harmony/Resource/CreateRemoteResourceChange.cs index 6338523..6653f31 100644 --- a/src/SIL.Harmony/Resource/CreateRemoteResourceChange.cs +++ b/src/SIL.Harmony/Resource/CreateRemoteResourceChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; namespace SIL.Harmony.Resource; diff --git a/src/SIL.Harmony/Resource/CreateRemoteResourcePendingUpload.cs b/src/SIL.Harmony/Resource/CreateRemoteResourcePendingUpload.cs index a4aaf5b..c4d3b95 100644 --- a/src/SIL.Harmony/Resource/CreateRemoteResourcePendingUpload.cs +++ b/src/SIL.Harmony/Resource/CreateRemoteResourcePendingUpload.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; namespace SIL.Harmony.Resource; diff --git a/src/SIL.Harmony/Resource/HarmonyResource.cs b/src/SIL.Harmony/Resource/HarmonyResource.cs index 5e66149..b2fba48 100644 --- a/src/SIL.Harmony/Resource/HarmonyResource.cs +++ b/src/SIL.Harmony/Resource/HarmonyResource.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace SIL.Harmony.Resource; @@ -7,7 +7,7 @@ public class HarmonyResource where TMetadata : class public HarmonyResource() { - + } [SetsRequiredMembers] diff --git a/src/SIL.Harmony/Resource/LocalResource.cs b/src/SIL.Harmony/Resource/LocalResource.cs index 0beaf4c..affbfde 100644 --- a/src/SIL.Harmony/Resource/LocalResource.cs +++ b/src/SIL.Harmony/Resource/LocalResource.cs @@ -1,4 +1,4 @@ -namespace SIL.Harmony.Resource; +namespace SIL.Harmony.Resource; /// /// a non CRDT object that tracks local resource files diff --git a/src/SIL.Harmony/Resource/RemoteResource.cs b/src/SIL.Harmony/Resource/RemoteResource.cs index da86401..70141e1 100644 --- a/src/SIL.Harmony/Resource/RemoteResource.cs +++ b/src/SIL.Harmony/Resource/RemoteResource.cs @@ -1,4 +1,4 @@ -using System.Text.Json; +using System.Text.Json; using SIL.Harmony.Entities; namespace SIL.Harmony.Resource; diff --git a/src/SIL.Harmony/Resource/RemoteResourceNotEnabledException.cs b/src/SIL.Harmony/Resource/RemoteResourceNotEnabledException.cs index 01b641d..757643e 100644 --- a/src/SIL.Harmony/Resource/RemoteResourceNotEnabledException.cs +++ b/src/SIL.Harmony/Resource/RemoteResourceNotEnabledException.cs @@ -1,4 +1,4 @@ -namespace SIL.Harmony.Resource; +namespace SIL.Harmony.Resource; public class RemoteResourceNotEnabledException() : Exception("remote resources were not enabled, to enable them call AddCrdtRemoteResources when adding the CRDT library"); diff --git a/src/SIL.Harmony/Resource/RemoteResourceUploadedChange.cs b/src/SIL.Harmony/Resource/RemoteResourceUploadedChange.cs index e796f13..166c576 100644 --- a/src/SIL.Harmony/Resource/RemoteResourceUploadedChange.cs +++ b/src/SIL.Harmony/Resource/RemoteResourceUploadedChange.cs @@ -1,4 +1,4 @@ -using SIL.Harmony.Changes; +using SIL.Harmony.Changes; using SIL.Harmony.Entities; namespace SIL.Harmony.Resource; diff --git a/src/SIL.Harmony/ResourceService.cs b/src/SIL.Harmony/ResourceService.cs index 67dd85a..a225788 100644 --- a/src/SIL.Harmony/ResourceService.cs +++ b/src/SIL.Harmony/ResourceService.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using SIL.Harmony.Changes; @@ -164,7 +164,7 @@ public async Task UploadPendingResource(HarmonyResource resource, Gui CommitMetadata? commitMetadata = null) { ValidateResourcesSetup(); - if (resource is not {Local: true, Remote: false}) throw new ArgumentException("Resource is not pending upload"); + if (resource is not { Local: true, Remote: false }) throw new ArgumentException("Resource is not pending upload"); var uploadResult = await remoteResourceService.UploadResource(resource.Id, resource.LocalPath, resource.Metadata); await _dataModel.AddChange(clientId, new RemoteResourceUploadedChange(resource.Id, uploadResult.RemoteId, uploadResult.Metadata), @@ -240,7 +240,7 @@ public async Task[]> AllResources() await using var repo = await _crdtRepositoryFactory.CreateRepository(); var remoteResource = await repo.GetCurrent>(resourceId); var localResource = await repo.GetLocalResource(resourceId); - if (remoteResource is {DeletedAt: not null}) remoteResource = null; + if (remoteResource is { DeletedAt: not null }) remoteResource = null; if (localResource is null && remoteResource is null) return null; return new HarmonyResource(localResource, remoteResource); } diff --git a/src/SIL.Harmony/SnapshotWorker.cs b/src/SIL.Harmony/SnapshotWorker.cs index c4fe70f..745ac57 100644 --- a/src/SIL.Harmony/SnapshotWorker.cs +++ b/src/SIL.Harmony/SnapshotWorker.cs @@ -13,7 +13,7 @@ internal class SnapshotWorker private readonly Dictionary _snapshotLookup; private readonly CrdtRepository _crdtRepository; private readonly CrdtConfig _crdtConfig; - private readonly Dictionary _pendingSnapshots = []; + private readonly Dictionary _pendingSnapshots = []; private readonly Dictionary _rootSnapshots = []; private readonly List _newIntermediateSnapshots = []; @@ -45,7 +45,7 @@ internal static async Task> ApplyCommitsToSnaps /// internal SnapshotWorker(Dictionary snapshotLookup, CrdtRepository crdtRepository, - CrdtConfig crdtConfig): this([], snapshotLookup, crdtRepository, crdtConfig) + CrdtConfig crdtConfig) : this([], snapshotLookup, crdtRepository, crdtConfig) { } diff --git a/src/SIL.Harmony/SyncHelper.cs b/src/SIL.Harmony/SyncHelper.cs index afd6e93..91daae6 100644 --- a/src/SIL.Harmony/SyncHelper.cs +++ b/src/SIL.Harmony/SyncHelper.cs @@ -1,5 +1,6 @@ -using System.Text.Json; +using System.Text.Json; namespace SIL.Harmony; + internal static class SyncHelper { public static async Task SyncWithResourceUpload(this DataModel localModel, @@ -73,7 +74,7 @@ private static T Clone(this T source, JsonSerializerOptions options) { ArgumentNullException.ThrowIfNull(source); var json = JsonSerializer.Serialize(source, options); - var clone = JsonSerializer.Deserialize(json,options); + var clone = JsonSerializer.Deserialize(json, options); return clone ?? throw new NullReferenceException("unable to clone object type " + typeof(T)); } } From cb541bc399f2de0614b5aa7538059d2c4bcfff71 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 16 Jul 2026 16:44:06 +0700 Subject: [PATCH 4/5] Consolidate src/.editorconfig into root Remove the redundant src/.editorconfig. Its two meaningful rules are migrated to the root config: - VSTHRD200 severity = none (don't require Async suffix on async methods) - Verify snapshot files (*.received/*.verified) excluded from reformatting The duplicate indent_size/charset rules are dropped (already set globally). Fixed the stray quotes on the Verify charset value (utf-8-bom). Co-Authored-By: Claude Opus 4.8 --- .editorconfig | 14 ++++++++++++++ src/.editorconfig | 16 ---------------- 2 files changed, 14 insertions(+), 16 deletions(-) delete mode 100644 src/.editorconfig diff --git a/.editorconfig b/.editorconfig index 12ab161..031ecd3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,16 @@ indent_size = 2 [*.{md,markdown}] trim_trailing_whitespace = false +# Verify snapshot files — must not be reformatted or snapshot tests break. +[*.{received,verified}.{txt,xml,json}] +charset = utf-8-bom +end_of_line = lf +indent_size = unset +indent_style = unset +insert_final_newline = false +tab_width = unset +trim_trailing_whitespace = false + # Vendored third-party code (C# port of Yjs) — excluded from formatting/analysis. # dotnet format skips files marked as generated. [src/Ycs/**.cs] @@ -79,3 +89,7 @@ csharp_space_after_cast = false csharp_space_after_keywords_in_control_flow_statements = true csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_method_call_parameter_list_parentheses = false + +# Analyzer diagnostics +# VSTHRD200: do not require the "Async" suffix on async methods +dotnet_diagnostic.VSTHRD200.severity = none diff --git a/src/.editorconfig b/src/.editorconfig deleted file mode 100644 index 26177b8..0000000 --- a/src/.editorconfig +++ /dev/null @@ -1,16 +0,0 @@ -[*.cs] -indent_size = 4 -charset = utf-8 - -# VSTHRD200: Use "Async" suffix for async methods -dotnet_diagnostic.VSTHRD200.severity = none - -# Verify settings -[*.{received,verified}.{txt,xml,json}] -charset = "utf-8-bom" -end_of_line = lf -indent_size = unset -indent_style = unset -insert_final_newline = false -tab_width = unset -trim_trailing_whitespace = false \ No newline at end of file From 11dab1fa3f98698debf8112a208c5900b839cdad Mon Sep 17 00:00:00 2001 From: Tim Haasdyk Date: Thu, 16 Jul 2026 13:53:48 +0200 Subject: [PATCH 5/5] Fix 'CodeQL / Workflow does not contain permissions' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/format.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index 7ef8ccd..62b1ea9 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -8,6 +8,9 @@ on: branches: - main +permissions: + contents: read + jobs: format: runs-on: ubuntu-latest