Skip to content

Commit

Permalink
Fix warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Feb 4, 2024
1 parent 48b57d2 commit 0ed99e5
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 25 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dotnet_diagnostic.SA1101.severity = none # Prefix local calls with this

# Ordering rules
dotnet_diagnostic.SA1200.severity = suggestion # Using directives should be placed correctly
dotnet_diagnostic.SA1201.severity = none # SA1201: Elements should appear in the correct order
dotnet_diagnostic.SA1202.severity = none # SA1202: Elements should be ordered by access
dotnet_diagnostic.SA1204.severity = suggestion # Static elements should appear before instance elements

# Maintainability rules
Expand All @@ -45,3 +47,8 @@ dotnet_diagnostic.SA1601.severity = suggestion # Partial elements should be docu
dotnet_diagnostic.SA1602.severity = suggestion # Enumeration items should be documented
dotnet_diagnostic.SA1633.severity = none # File should have header

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = none

# MA0055: Do not use finalizer
dotnet_diagnostic.MA0055.severity = none
4 changes: 2 additions & 2 deletions Tests/YDotNet.Tests.Unit/Maps/GetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ public void GetNewKeyReturnsNull()
var map = doc.Map("map");
var transaction = doc.WriteTransaction();

foreach (var value in values)
foreach (var (kez, value) in values)
{
map.Insert(transaction, value.Key, value.Value);
map.Insert(transaction, kez, value);
}

return (map, transaction);
Expand Down
2 changes: 1 addition & 1 deletion YDotNet.Extensions/InputFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Input FromJson(JsonElement json)

static Input ConvertObject(JsonElement element)
{
return Input.Object(element.EnumerateObject().ToDictionary(x => x.Name, x => ConvertValue(x.Value)));
return Input.Object(element.EnumerateObject().ToDictionary(x => x.Name, x => ConvertValue(x.Value), StringComparer.Ordinal));
}

static Input ConvertArray(JsonElement element)
Expand Down
2 changes: 1 addition & 1 deletion YDotNet.Server.Redis/Internal/LoggerTextWriter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Logging;
using System.Text;
using Microsoft.Extensions.Logging;

namespace YDotNet.Server.Redis.Internal;

Expand Down
3 changes: 1 addition & 2 deletions YDotNet.Server.Redis/RedisDocumentStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ private async Task InitializeAsync(RedisConnection redisConnection)
return item;
}

public async ValueTask StoreDocAsync(string name, byte[] doc,
CancellationToken ct = default)
public async ValueTask StoreDocAsync(string name, byte[] doc, CancellationToken ct = default)
{
if (database == null)
{
Expand Down
2 changes: 1 addition & 1 deletion YDotNet.Server.WebSockets/YDotNetSocketMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private async Task HandleAwarenessAsync(ClientState state, AwarenessMessage awar
}
}

private async Task SendPendingUpdatesAsync(WebSocketEncoder encoder, ClientState state, CancellationToken ct)
private static async Task SendPendingUpdatesAsync(WebSocketEncoder encoder, ClientState state, CancellationToken ct)
{
while (state.PendingUpdates.TryDequeue(out var pendingDiff))
{
Expand Down
12 changes: 4 additions & 8 deletions YDotNet.Server/DefaultDocumentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public async ValueTask<byte[]> GetStateVectorAsync(
}).ConfigureAwait(false);
}

public async ValueTask<byte[]> GetUpdateAsync(DocumentContext context, byte[] stateVector,
CancellationToken ct = default)
public async ValueTask<byte[]> GetUpdateAsync(DocumentContext context, byte[] stateVector, CancellationToken ct = default)
{
var container = cache.GetContext(context.DocumentName);

Expand All @@ -69,8 +68,7 @@ public async ValueTask<byte[]> GetUpdateAsync(DocumentContext context, byte[] st
}).ConfigureAwait(false);
}

public async ValueTask<UpdateResult> ApplyUpdateAsync(DocumentContext context, byte[] stateDiff,
CancellationToken ct = default)
public async ValueTask<UpdateResult> ApplyUpdateAsync(DocumentContext context, byte[] stateDiff, CancellationToken ct = default)
{
var container = cache.GetContext(context.DocumentName);

Expand Down Expand Up @@ -103,8 +101,7 @@ await callback.OnDocumentChangedAsync(new DocumentChangedEvent
return result;
}

public async ValueTask UpdateDocAsync(DocumentContext context, Action<Doc> action,
CancellationToken ct = default)
public async ValueTask UpdateDocAsync(DocumentContext context, Action<Doc> action, CancellationToken ct = default)
{
var container = cache.GetContext(context.DocumentName);

Expand All @@ -129,8 +126,7 @@ await callback.OnDocumentChangedAsync(new DocumentChangedEvent
}
}

public async ValueTask PingAsync(DocumentContext context, ulong clock, string? state = null,
CancellationToken ct = default)
public async ValueTask PingAsync(DocumentContext context, ulong clock, string? state = null, CancellationToken ct = default)
{
if (users.AddOrUpdate(context.DocumentName, context.ClientId, clock, state, out var newState))
{
Expand Down
1 change: 1 addition & 0 deletions YDotNet.Server/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma warning disable MA0048 // File name must match type name
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1649 // File name should match first type name

namespace YDotNet.Server;

Expand Down
4 changes: 2 additions & 2 deletions YDotNet.Server/Internal/ConnectedUsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace YDotNet.Server.Internal;

public sealed class ConnectedUsers
{
private readonly ConcurrentDictionary<string, Dictionary<ulong, ConnectedUser>> users = new();
private readonly ConcurrentDictionary<string, Dictionary<ulong, ConnectedUser>> users = new(StringComparer.Ordinal);

public Func<DateTime> Clock = () => DateTime.UtcNow;
public Func<DateTime> Clock { get; set; } = () => DateTime.UtcNow;

public IReadOnlyDictionary<ulong, ConnectedUser> GetUsers(string documentName)
{
Expand Down
2 changes: 1 addition & 1 deletion YDotNet.Server/Internal/DelayedWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public DelayedWriter(TimeSpan delay, TimeSpan delayMax, Func<Task> action)
writeTimer = new Timer(_ => Write(), null, Timeout.Infinite, Timeout.Infinite);
}

public Func<DateTime> Clock = () => DateTime.UtcNow;
public Func<DateTime> Clock { get; set; } = () => DateTime.UtcNow;

public async Task FlushAsync()
{
Expand Down
8 changes: 4 additions & 4 deletions YDotNet.Server/Internal/DocumentContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ public async Task<T> ApplyUpdateReturnAsync<T>(Func<Doc, T> action)

private async Task WriteAsync()
{
var doc = this.doc;
var curentDoc = this.doc;

if (doc == null)
if (curentDoc == null)
{
return;
}

byte[] state;

slimLock.Wait();
await slimLock.WaitAsync().ConfigureAwait(false);
try
{
using var transaction = doc.ReadTransactionOrThrow();
using var transaction = curentDoc.ReadTransactionOrThrow();

var snapshot = transaction!.Snapshot()!;

Expand Down
3 changes: 2 additions & 1 deletion YDotNet.Server/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static YDotnetRegistration AddYDotNet(this IServiceCollection services)
};
}

public static YDotnetRegistration AddCallback<T>(this YDotnetRegistration registration) where T : class, IDocumentCallback
public static YDotnetRegistration AddCallback<T>(this YDotnetRegistration registration)
where T : class, IDocumentCallback
{
registration.Services.AddSingleton<IDocumentCallback, T>();
return registration;
Expand Down
2 changes: 1 addition & 1 deletion YDotNet.Server/Storage/InMemoryDocumentStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace YDotNet.Server.Storage;

public sealed class InMemoryDocumentStorage : IDocumentStorage
{
private readonly ConcurrentDictionary<string, byte[]> docs = new();
private readonly ConcurrentDictionary<string, byte[]> docs = new(StringComparer.Ordinal);

public ValueTask<byte[]?> GetDocAsync(string name, CancellationToken ct = default)
{
Expand Down
2 changes: 1 addition & 1 deletion YDotNet/Infrastructure/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace YDotNet.Infrastructure;
/// </summary>
public abstract class Resource : IDisposable
{
internal Resource(bool isDisposed = false)
protected internal Resource(bool isDisposed = false)
{
IsDisposed = isDisposed;
}
Expand Down

0 comments on commit 0ed99e5

Please sign in to comment.