Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORELIB-182] Fix dotnet and rider warnings, remove StyleCop leftovers #750

Merged
merged 21 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 14 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,17 @@ dotnet_diagnostic.IDE0058.severity = none
dotnet_diagnostic.xUnit1051.severity = none

# Rider
resharper_inconsistent_naming_highlighting=hint

[test-bed/**/*.cs]
resharper_not_null_or_required_member_is_not_initialized_highlighting = none
resharper_class_never_instantiated_global_highlighting = none
resharper_inconsistent_naming_highlighting = hint
resharper_static_member_in_generic_type_highlighting = hint
resharper_check_namespace_highlighting = hint
resharper_variable_hides_outer_variable_highlighting = hint
resharper_parameter_hides_member_highlighting = hint
resharper_not_null_or_required_member_is_not_initialized_highlighting = hint

resharper_convert_type_check_pattern_to_null_check_highlighting = none
resharper_convert_type_check_to_null_check_highlighting = none

[test/**]
resharper_equal_expression_comparison_highlighting = none
resharper_entity_framework_model_validation_unlimited_string_length_highlighting = none
resharper_unused_auto_property_accessor_local_highlighting = none
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using LeanCode.Contracts;
using LeanCode.CQRS.Execution;
Expand Down Expand Up @@ -212,6 +213,7 @@ private static void AddCommonResponses(ApiDescription apiDescription)
private static CQRSBodyModelMetadata CreateModelMetadata(Type type) => new(ModelMetadataIdentity.ForType(type));
}

[SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
internal sealed class CQRSBodyModelMetadata : ModelMetadata
{
public CQRSBodyModelMetadata(ModelMetadataIdentity identity)
Expand All @@ -221,7 +223,7 @@ public CQRSBodyModelMetadata(ModelMetadataIdentity identity)
ImmutableDictionary<object, object>.Empty;
public override string? BinderModelName { get; }
public override Type? BinderType { get; }
public override BindingSource? BindingSource => BindingSource.Body;
public override BindingSource BindingSource => BindingSource.Body;
public override bool ConvertEmptyStringToNull { get; }
public override string? DataTypeName { get; }
public override string? Description { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public static void AddCQRSHandler(this IServiceCollection serviceCollection, CQR
{
serviceCollection.Add(new(obj.HandlerType, obj.HandlerType, ServiceLifetime.Scoped));
serviceCollection.Add(
new(MakeHandlerInterfaceType(obj), sp => sp.GetRequiredService(obj.HandlerType), ServiceLifetime.Scoped)
new(MakeHandlerInterfaceType(), sp => sp.GetRequiredService(obj.HandlerType), ServiceLifetime.Scoped)
);

Type MakeHandlerInterfaceType(CQRSObjectMetadata obj)
Type MakeHandlerInterfaceType()
{
return obj.ObjectKind switch
{
Expand Down
2 changes: 1 addition & 1 deletion src/CQRS/LeanCode.CQRS.Execution/IOperationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace LeanCode.CQRS.Execution;
public interface IOperationHandler<in TOperation, TResult>
where TOperation : IOperation<TResult>
{
public Task<TResult> ExecuteAsync(HttpContext context, TOperation operation);
Task<TResult> ExecuteAsync(HttpContext context, TOperation operation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Type defaultDefinition
)
{
var outer = types.Where(RegistrationMetadata.IsConsumer);
var inner = types.Where((Type x) => x.HasInterface(typeof(IConsumerDefinition<>)));
var inner = types.Where(x => x.HasInterface(typeof(IConsumerDefinition<>)));
var enumerable =
from c in outer
join d in inner on c equals d.GetClosingArgument(typeof(IConsumerDefinition<>)) into dc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class ResettableBusActivityMonitor
{
private readonly object mutex = new object();
private readonly AsyncManualResetEvent inactive = new(true);
private readonly RollingTimer timer;
private readonly RollingTimer rollingTimer;

private volatile int consumersInFlight;
private volatile int receiversInFlight;
Expand All @@ -27,7 +27,7 @@ public sealed class ResettableBusActivityMonitor

public ResettableBusActivityMonitor(TimeSpan inactivityWaitTime)
{
timer = new RollingTimer(OnTimer, inactivityWaitTime);
rollingTimer = new RollingTimer(OnTimer, inactivityWaitTime);
}

public static ResettableBusActivityMonitor CreateFor(IBusControl bus, TimeSpan inactivityWaitTime)
Expand Down Expand Up @@ -83,15 +83,15 @@ Task IPublishObserver.PublishFault<T>(PublishContext<T> context, Exception excep
Decrement(ref publishInFlight);

[System.Diagnostics.CodeAnalysis.SuppressMessage("?", "CA1063", Justification = "We want clean API.")]
void IDisposable.Dispose() => timer.Dispose();
void IDisposable.Dispose() => rollingTimer.Dispose();

private Task Increment(ref int counter)
{
lock (mutex)
{
Interlocked.Increment(ref counter);
inactive.Reset();
timer.Stop();
rollingTimer.Stop();
}

return Task.CompletedTask;
Expand All @@ -105,7 +105,7 @@ private Task Decrement(ref int counter)

if (HasStabilized)
{
timer.Restart();
rollingTimer.Restart();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/CQRS/LeanCode.CQRS.Security/IAuthorizerResolver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace LeanCode.CQRS.Security;

public interface IAuthorizerResolver<TAppContext>
public interface IAuthorizerResolver
{
ICustomAuthorizerWrapper? FindAuthorizer(Type authorizerType, Type objectType);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/LeanCode.Startup.Autofac/LeanProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static IHostBuilder BuildMinimalHost<TStartup>()
return new HostBuilder()
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureAppConfiguration(
(hostingContext, config) =>
(_, config) =>
{
config.AddEnvironmentVariables();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/LeanCode.Startup.MicrosoftDI/LeanProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static IHostBuilder BuildMinimalHost<TStartup>()
{
return new HostBuilder()
.ConfigureAppConfiguration(
(hostingContext, config) =>
(_, config) =>
{
config.AddEnvironmentVariables();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/LeanCode.DomainModels.EF/CachingEFRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected CachingEFRepository(TContext dbContext)
{
// Safety: aggregates are bound to have Id as a primary key by design.
var primaryKey = DbContext.Model.FindEntityType(typeof(TEntity))!.FindPrimaryKey()!;
return ((IDbContextDependencies)DbContext).StateManager!.TryGetEntryTyped(primaryKey, id)?.Entity as TEntity;
return ((IDbContextDependencies)DbContext).StateManager.TryGetEntryTyped(primaryKey, id)?.Entity as TEntity;
}

[SuppressMessage(
Expand All @@ -47,7 +47,7 @@ protected CachingEFRepository(TContext dbContext)
{
// Safety: aggregates are bound to have Id as a primary key by design.
var primaryKey = DbContext.Model.FindEntityType(typeof(TEntity))!.FindPrimaryKey()!;
return ((IDbContextDependencies)DbContext).StateManager!.TryGetEntryTyped(primaryKey, id)?.Entity as TEntity;
return ((IDbContextDependencies)DbContext).StateManager.TryGetEntryTyped(primaryKey, id)?.Entity as TEntity;
}

protected ValueTask<TEntity?> FindTrackedOrLoadNewAsync(TIdentity id, Func<DbSet<TEntity>, Task<TEntity?>> query)
Expand Down
6 changes: 4 additions & 2 deletions src/Domain/LeanCode.DomainModels.EF/EFRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public virtual void Delete(TEntity entity)

public virtual void DeleteRange(IEnumerable<TEntity> entities)
{
foreach (var oc in entities.OfType<IOptimisticConcurrency>())
var entitiesList = entities.ToList();

foreach (var oc in entitiesList.OfType<IOptimisticConcurrency>())
{
oc.DateModified = Time.UtcNow;
}

DbSet.RemoveRange(entities);
DbSet.RemoveRange(entitiesList);
}

public virtual void Update(TEntity entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void EnableOptimisticConcurrency<TEntity, TRowVersion>(
)
where TEntity : class, IOptimisticConcurrency
{
builder.Entity<TEntity>().IsOptimisticConcurrent(useExplicitBackingFields, addRowVersion);
builder.Entity<TEntity>().IsOptimisticConcurrent<TEntity, TRowVersion>(useExplicitBackingFields, addRowVersion);
}

private static string GetBackingFieldFor<TEntity>(string fieldName)
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/LeanCode.DomainModels.EF/SimpleEFRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace LeanCode.DomainModels.EF;

public sealed class SimpleEFRepository<TEntity, TIdentity, TContext> : EFRepository<TEntity, TIdentity, TContext>
where TEntity : class, IAggregateRoot<TIdentity>
where TIdentity : notnull, IEquatable<TIdentity>
where TContext : notnull, DbContext
where TIdentity : IEquatable<TIdentity>
where TContext : DbContext
{
public SimpleEFRepository(TContext dbContext)
: base(dbContext) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace LeanCode.DomainModels.Generators;

public enum TypedIdFormat : int
public enum TypedIdFormat
{
RawInt = 0,
RawLong = 1,
Expand Down
16 changes: 8 additions & 8 deletions src/Domain/LeanCode.DomainModels/Ids/ITypedId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public interface IPrefixedTypedId<TSelf>
where TSelf : struct, IPrefixedTypedId<TSelf>
{
string Value { get; }
public static abstract int RawLength { get; }
public static abstract TSelf Parse(string v);
public static abstract bool IsValid(string? v);
static abstract int RawLength { get; }
static abstract TSelf Parse(string v);
static abstract bool IsValid(string? v);

[EditorBrowsable(EditorBrowsableState.Never)]
public static abstract Expression<Func<string, TSelf>> FromDatabase { get; }
static abstract Expression<Func<string, TSelf>> FromDatabase { get; }

[EditorBrowsable(EditorBrowsableState.Never)]
public static abstract Expression<Func<TSelf, TSelf, bool>> DatabaseEquals { get; }
static abstract Expression<Func<TSelf, TSelf, bool>> DatabaseEquals { get; }
}

[SuppressMessage("?", "CA1000", Justification = "Roslyn bug.")]
Expand All @@ -39,11 +39,11 @@ public interface IRawTypedId<TBacking, TSelf>
where TSelf : struct, IRawTypedId<TBacking, TSelf>
{
TBacking Value { get; }
public static abstract TSelf Parse(TBacking v);
static abstract TSelf Parse(TBacking v);

[EditorBrowsable(EditorBrowsableState.Never)]
public static abstract Expression<Func<TBacking, TSelf>> FromDatabase { get; }
static abstract Expression<Func<TBacking, TSelf>> FromDatabase { get; }

[EditorBrowsable(EditorBrowsableState.Never)]
public static abstract Expression<Func<TSelf, TSelf, bool>> DatabaseEquals { get; }
static abstract Expression<Func<TSelf, TSelf, bool>> DatabaseEquals { get; }
}
2 changes: 1 addition & 1 deletion src/Domain/LeanCode.DomainModels/Ids/TypedIdAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LeanCode.DomainModels.Ids;
/// <remarks>
/// See <see href="../../../../docs/domain/ids.md">documentation</see> for more details.
/// </remarks>
public enum TypedIdFormat : int
public enum TypedIdFormat
{
/// <summary>
/// Raw <see cref="int" />, without prefix. It's backing type is <see cref="int" />.
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/LeanCode.DomainModels/Ids/TypedIdConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ public override void WriteAsPropertyName(Utf8JsonWriter writer, TId value, JsonS

private bool TryGetGuidCore(ref Utf8JsonReader reader, out Guid value)
{
#pragma warning disable RedundantAssignment
ReadOnlySpan<byte> span = stackalloc byte[0];
#pragma warning restore RedundantAssignment

if (reader.HasValueSequence)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Domain/LeanCode.DomainModels/Model/Id.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace LeanCode.DomainModels.Model;
public readonly struct Id<TEntity> : IEquatable<Id<TEntity>>, IComparable<Id<TEntity>>
where TEntity : class, IEntity<Id<TEntity>>
{
#pragma warning disable UnassignedReadonlyField
public static readonly Id<TEntity> Empty;
#pragma warning restore UnassignedReadonlyField

public Guid Value { get; }

Expand Down Expand Up @@ -63,7 +65,9 @@ public Id(Guid value)
public readonly struct IId<TEntity> : IEquatable<IId<TEntity>>, IComparable<IId<TEntity>>
where TEntity : class, IEntity<IId<TEntity>>
{
#pragma warning disable UnassignedReadonlyField
public static readonly IId<TEntity> Empty;
#pragma warning restore UnassignedReadonlyField

public int Value { get; }

Expand Down
4 changes: 2 additions & 2 deletions src/Domain/LeanCode.DomainModels/Model/SId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SId(Guid v)
public static SId<TEntity> New() => new(Guid.NewGuid());

[return: NotNullIfNotNull("id")]
public static SId<TEntity>? FromNullable(string? id) => id is string v ? From(v) : (SId<TEntity>?)null;
public static SId<TEntity>? FromNullable(string? id) => id is string v ? From(v) : null;

public static bool TryParse(string? v, out SId<TEntity> id)
{
Expand Down Expand Up @@ -88,7 +88,7 @@ public static bool TryParseFromGuidOrSId([NotNullWhen(true)] string? v, out SId<
{
if (IsValid(v))
{
id = new SId<TEntity>(v!);
id = new SId<TEntity>(v);
return true;
}
else if (Guid.TryParse(v, out var guid))
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/LeanCode.DomainModels/Model/TimestampTz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LeanCode.DomainModels.Model;
/// This type is intended to be used with PostgreSQL which supports AT TIME ZONE operator
/// with IANA time zone IDs but cannot store both timestamp and offset in a single column.
/// </remarks>
public sealed record class TimestampTz : ValueObject
public sealed record TimestampTz : ValueObject
{
[JsonIgnore]
public TimeZoneInfo TimeZoneInfo => TimeZoneInfo.FindSystemTimeZoneById(TimeZoneId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public override void WriteAsPropertyName(Utf8JsonWriter writer, Id<T> value, Jso

private bool TryGetGuidCore(ref Utf8JsonReader reader, out Guid value)
{
#pragma warning disable RedundantAssignment
ReadOnlySpan<byte> span = stackalloc byte[0];
#pragma warning restore RedundantAssignment

if (reader.HasValueSequence)
{
Expand Down
14 changes: 5 additions & 9 deletions src/Domain/LeanCode.DomainModels/Ulids/Ulid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ namespace LeanCode.DomainModels.Ulids;
[DebuggerDisplay("{ToString(),nq}")]
[System.Text.Json.Serialization.JsonConverter(typeof(UlidJsonConverter))]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public readonly record struct Ulid
: IEquatable<Ulid>,
IComparable<Ulid>,
ISpanFormattable,
ISpanParsable<Ulid>,
IUtf8SpanFormattable
public readonly record struct Ulid : IComparable<Ulid>, ISpanFormattable, ISpanParsable<Ulid>, IUtf8SpanFormattable
{
public const int LengthInTextElements = 26;

Expand Down Expand Up @@ -193,7 +188,9 @@ public readonly record struct Ulid
new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }
);

#pragma warning disable UnassignedReadonlyField
public static readonly Ulid Empty;
#pragma warning restore UnassignedReadonlyField

// Core

Expand Down Expand Up @@ -250,8 +247,7 @@ public readonly record struct Ulid
[IgnoreDataMember]
[SuppressMessage("?", "CA1819", Justification = "Fresh array is allocated per call")]
public byte[] Random =>
new byte[]
{
[
randomness0,
randomness1,
randomness2,
Expand All @@ -262,7 +258,7 @@ public readonly record struct Ulid
randomness7,
randomness8,
randomness9,
};
];

[IgnoreDataMember]
public DateTimeOffset Time
Expand Down
Loading