Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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

# 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]
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

# Analyzer diagnostics
# VSTHRD200: do not require the "Async" suffix on async methods
dotnet_diagnostic.VSTHRD200.severity = none
29 changes: 29 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Format

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

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
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
16 changes: 0 additions & 16 deletions src/.editorconfig

This file was deleted.

2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/ChangeEntity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace SIL.Harmony.Core;

Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/CommitBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO.Hashing;
using System.IO.Hashing;
using System.Text.Json.Serialization;

namespace SIL.Harmony.Core;
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/CommitMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SIL.Harmony.Core;
namespace SIL.Harmony.Core;

public class CommitMetadata
{
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/CrdtConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SIL.Harmony.Core;
namespace SIL.Harmony.Core;

public static class CrdtConstants
{
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/EntityNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace SIL.Harmony.Core;
namespace SIL.Harmony.Core;

public class EntityNotFoundException(string message) : Exception(message);
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/HybridDateTime.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


namespace SIL.Harmony.Core;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/IChangeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> IsObjectDeleted(Guid entityId) => (await GetSnapshot(entityId))?.EntityIsDeleted ?? true;
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/IObjectBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace SIL.Harmony.Core;

Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/IRemoteResourceService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SIL.Harmony.Core;
namespace SIL.Harmony.Core;

/// <summary>
/// interface to facilitate downloading of resources, typically implemented in application code
Expand Down
6 changes: 3 additions & 3 deletions src/SIL.Harmony.Core/QueryHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,23 @@ private static IEnumerable<TCommit> GetMissingCommitsForClient<TCommit>(
}
}

public static IQueryable<T> DefaultOrder<T>(this IQueryable<T> queryable) where T: CommitBase
public static IQueryable<T> DefaultOrder<T>(this IQueryable<T> queryable) where T : CommitBase
{
return queryable
.OrderBy(c => c.HybridDateTime.DateTime)
.ThenBy(c => c.HybridDateTime.Counter)
.ThenBy(c => c.Id);
}

public static IEnumerable<T> DefaultOrder<T>(this IEnumerable<T> queryable) where T: CommitBase
public static IEnumerable<T> DefaultOrder<T>(this IEnumerable<T> queryable) where T : CommitBase
{
return queryable
.OrderBy(c => c.HybridDateTime.DateTime)
.ThenBy(c => c.HybridDateTime.Counter)
.ThenBy(c => c.Id);
}

public static IQueryable<T> DefaultOrderDescending<T>(this IQueryable<T> queryable) where T: CommitBase
public static IQueryable<T> DefaultOrderDescending<T>(this IQueryable<T> queryable) where T : CommitBase
{
return queryable
.OrderByDescending(c => c.HybridDateTime.DateTime)
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Core/ServerCommit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down
4 changes: 2 additions & 2 deletions src/SIL.Harmony.Core/SyncState.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace SIL.Harmony.Core;
namespace SIL.Harmony.Core;

public record SyncState(Dictionary<Guid, long> ClientHeads);
public interface IChangesResult
{
IEnumerable<CommitBase> MissingFromClient { get; }
SyncState ServerSyncState { get; }
}
public record ChangesResult<TCommit>(TCommit[] MissingFromClient, SyncState ServerSyncState): IChangesResult where TCommit : CommitBase
public record ChangesResult<TCommit>(TCommit[] MissingFromClient, SyncState ServerSyncState) : IChangesResult where TCommit : CommitBase
{
IEnumerable<CommitBase> IChangesResult.MissingFromClient => MissingFromClient;
public static ChangesResult<TCommit> Empty => new([], new SyncState([]));
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Linq2db/Linq2dbKernel.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Changes/AddWordImageChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public override async ValueTask ApplyChange(Word entity, IChangeContext context)
{
if (!await context.IsObjectDeleted(ImageId)) entity.ImageResourceId = ImageId;
}
}
}
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Changes/EditExampleChange.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Changes/NewDefinitionChange.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Harmony.Changes;
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;
using SIL.Harmony.Sample.Models;

Expand Down
4 changes: 2 additions & 2 deletions src/SIL.Harmony.Sample/Changes/NewExampleChange.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,7 +41,7 @@ public override async ValueTask<Example> 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
};
}
}
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Changes/NewWordChange.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Harmony.Changes;
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;
using SIL.Harmony.Sample.Models;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Harmony.Changes;
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;
using SIL.Harmony.Sample.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public override ValueTask ApplyChange(Definition entity, IChangeContext context)
entity.PartOfSpeech = PartOfSpeech;
return ValueTask.CompletedTask;
}
}
}
4 changes: 2 additions & 2 deletions src/SIL.Harmony.Sample/Changes/SetTagChange.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Harmony.Changes;
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;
using SIL.Harmony.Sample.Models;

Expand All @@ -15,7 +15,7 @@ public override async ValueTask<Tag> NewEntity(Commit commit, IChangeContext con
{
Id = EntityId,
Text = Text,
DeletedAt = tagExists ? commit.DateTime : null
DeletedAt = tagExists ? commit.DateTime : null
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Changes/SetWordNoteChange.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Harmony.Changes;
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;
using SIL.Harmony.Sample.Models;

Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Changes/SetWordTextChange.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Harmony.Changes;
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;
using SIL.Harmony.Sample.Models;

Expand Down
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Changes/TagWordChange.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/SIL.Harmony.Sample/CrdtSampleKernel.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/SIL.Harmony.Sample/Models/Definition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Harmony.Changes;
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;

namespace SIL.Harmony.Sample.Models;
Expand Down Expand Up @@ -39,4 +39,4 @@ public IObjectBase Copy()
DeletedAt = DeletedAt
};
}
}
}
6 changes: 3 additions & 3 deletions src/SIL.Harmony.Sample/Models/Example.cs
Original file line number Diff line number Diff line change
@@ -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<Example>
public class Example : IObjectBase<Example>
{
public Guid Id { get; init; }
public DateTimeOffset? DeletedAt { get; set; }
Expand Down Expand Up @@ -49,4 +49,4 @@ public IObjectBase Copy()
YTextBlob = YTextBlob
};
}
}
}
2 changes: 1 addition & 1 deletion src/SIL.Harmony.Sample/Models/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public IObjectBase Copy()
DeletedAt = DeletedAt
};
}
}
}
Loading
Loading