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 8 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
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,33 @@ dotnet_naming_symbols.everything_else.applicable_accessibilities = *
dotnet_diagnostic.CA1812.severity = none
dotnet_diagnostic.CA1724.severity = none
dotnet_diagnostic.CA1515.severity = none
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.CA1707.severity = none
dotnet_diagnostic.CA1062.severity = none
dotnet_diagnostic.CA1816.severity = none
dotnet_diagnostic.CA1303.severity = none
dotnet_diagnostic.CA1002.severity = none
dotnet_diagnostic.CA1032.severity = none
dotnet_diagnostic.CA1034.severity = none
dotnet_diagnostic.CA1019.severity = none
dotnet_diagnostic.CA1308.severity = none
dotnet_diagnostic.IDE0058.severity = none

# Disable temporarily
dotnet_diagnostic.xUnit1051.severity = none

# Rider
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
Expand Up @@ -40,9 +40,9 @@ public class CQRSPipelineBuilder
{
public Func<CQRSObjectMetadata, bool> ObjectsFilter { get; set; } = _ => true;

public Action<ICQRSApplicationBuilder> Commands { get; set; } = app => { };
public Action<ICQRSApplicationBuilder> Queries { get; set; } = app => { };
public Action<ICQRSApplicationBuilder> Operations { get; set; } = app => { };
public Action<ICQRSApplicationBuilder> Commands { get; set; } = _ => { };
public Action<ICQRSApplicationBuilder> Queries { get; set; } = _ => { };
public Action<ICQRSApplicationBuilder> Operations { get; set; } = _ => { };

private readonly IEndpointRouteBuilder routeBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ internal class LocalCallContext : HttpContext, IDisposable

public override IFeatureCollection Features => features;

public override ClaimsPrincipal User { get; set; }
wojtek2288 marked this conversation as resolved.
Show resolved Hide resolved
public override string TraceIdentifier { get; set; }
public sealed override ClaimsPrincipal User { get; set; }
public sealed override string TraceIdentifier { get; set; }
public override HttpRequest Request { get; }
public override HttpResponse Response { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Metrics;
using LeanCode.CQRS.AspNetCore.Serialization;
using LeanCode.CQRS.Execution;
using Microsoft.AspNetCore.Http;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using LeanCode.Contracts;
using LeanCode.CQRS.Execution;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ModelBinding;
Expand Down Expand Up @@ -213,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 @@ -222,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 @@ -44,9 +44,9 @@ public void AddCQRSObjects(TypesCatalog contractsCatalog, TypesCatalog handlersC
continue;
}

var handlerCandidates = handlers[contract];
var handlerCandidates = handlers[contract].ToList();
wojtek2288 marked this conversation as resolved.
Show resolved Hide resolved

if (handlerCandidates.Count() != 1)
if (handlerCandidates.Count != 1)
{
// TODO: shouldn't we throw here?
continue;
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()
wojtek2288 marked this conversation as resolved.
Show resolved Hide resolved
{
return obj.ObjectKind switch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json;
using LeanCode.Serialization;
using Microsoft.AspNetCore.Http.Json;
using Microsoft.Extensions.Options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

namespace LeanCode.CQRS.AspNetCore;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace LeanCode.CQRS.Execution;

public class CommandHandlerNotFoundException : Exception
Expand Down
1 change: 0 additions & 1 deletion src/CQRS/LeanCode.CQRS.Execution/ICommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading.Tasks;
using LeanCode.Contracts;
using Microsoft.AspNetCore.Http;

Expand Down
3 changes: 1 addition & 2 deletions src/CQRS/LeanCode.CQRS.Execution/IOperationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading.Tasks;
using LeanCode.Contracts;
using Microsoft.AspNetCore.Http;

Expand All @@ -7,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);
}
1 change: 0 additions & 1 deletion src/CQRS/LeanCode.CQRS.Execution/IQueryHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading.Tasks;
using LeanCode.Contracts;
using Microsoft.AspNetCore.Http;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace LeanCode.CQRS.Execution;

public class OperationHandlerNotFoundException : Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace LeanCode.CQRS.Execution;

public class QueryHandlerNotFoundException : Exception
Expand Down
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();
wojtek2288 marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 0 additions & 1 deletion src/CQRS/LeanCode.CQRS.RemoteHttp.Client/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Net;

namespace LeanCode.CQRS.RemoteHttp.Client;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
using LeanCode.Contracts;
using LeanCode.Contracts.Validation;

Expand All @@ -30,7 +25,7 @@ public virtual async Task<CommandResult> RunAsync(ICommand command, Cancellation
{
using var content = JsonContent.Create(command, command.GetType(), options: serializerOptions);
using var response = await client.PostAsync(
"command/" + command.GetType().FullName,
new Uri("command/" + command.GetType().FullName, UriKind.Relative),
content,
cancellationToken
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public virtual async Task<TResult> GetAsync<TResult>(
{
using var content = JsonContent.Create(operation, operation.GetType(), options: serializerOptions);
using var response = await client.PostAsync(
"operation/" + operation.GetType().FullName,
new Uri("operation/" + operation.GetType().FullName, UriKind.Relative),
content,
cancellationToken
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
using LeanCode.Contracts;

namespace LeanCode.CQRS.RemoteHttp.Client;
Expand All @@ -27,7 +24,11 @@ public virtual async Task<TResult> GetAsync<TResult>(
)
{
using var content = JsonContent.Create(query, query.GetType(), options: serializerOptions);
using var response = await client.PostAsync("query/" + query.GetType().FullName, content, cancellationToken);
using var response = await client.PostAsync(
new Uri("query/" + query.GetType().FullName, UriKind.Relative),
content,
cancellationToken
);

response.HandleCommonCQRSErrors<QueryNotFoundException, InvalidQueryException>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Net.Http;
using static System.Net.HttpStatusCode;

namespace LeanCode.CQRS.RemoteHttp.Client;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Linq;
using System.Security.Claims;

namespace LeanCode.CQRS.Security;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace LeanCode.CQRS.Security;

public class CustomAuthorizerNotFoundException : Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Security.Claims;
using System.Threading.Tasks;
using LeanCode.Contracts.Security;
using Microsoft.AspNetCore.Http;

namespace LeanCode.CQRS.Security;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace LeanCode.CQRS.Security.Exceptions;

public class InsufficientPermissionException : Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace LeanCode.CQRS.Security.Exceptions;

public class UnauthenticatedException : Exception
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: 0 additions & 2 deletions src/CQRS/LeanCode.CQRS.Security/IRoleRegistration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;

namespace LeanCode.CQRS.Security;

public interface IRoleRegistration
Expand Down
2 changes: 0 additions & 2 deletions src/CQRS/LeanCode.CQRS.Security/Role.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;

namespace LeanCode.CQRS.Security;
Expand Down
2 changes: 0 additions & 2 deletions src/CQRS/LeanCode.CQRS.Security/RoleRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

namespace LeanCode.CQRS.Security;

Expand Down
1 change: 0 additions & 1 deletion src/CQRS/LeanCode.CQRS.Validation/ICommandValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading.Tasks;
using LeanCode.Contracts;
using LeanCode.Contracts.Validation;
using Microsoft.AspNetCore.Http;
Expand Down
2 changes: 0 additions & 2 deletions src/Core/LeanCode.Components/TypesCatalog.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

namespace LeanCode.Components;
Expand Down
3 changes: 1 addition & 2 deletions src/Core/LeanCode.Startup.Autofac/LeanProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.IO;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand All @@ -16,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
Loading
Loading