Skip to content

Commit

Permalink
Set dotnet_diagnostic.CA1852.severity as warning (#2289)
Browse files Browse the repository at this point in the history
Seal some internal types as if `dotnet_diagnostic.CA1852.severity = warning` was in effect.
  • Loading branch information
Henr1k80 authored Sep 17, 2024
1 parent 957444f commit 5b39448
Show file tree
Hide file tree
Showing 31 changed files with 39 additions and 38 deletions.
1 change: 1 addition & 0 deletions eng/analyzers/Library.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ dotnet_diagnostic.CA1851.severity = suggestion
# Help Link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852
# Tags : Telemetry, EnabledRuleInAggressiveMode, CompilationEnd
dotnet_diagnostic.CA1852.severity = warning
dotnet_code_quality.CA1852.ignore_internalsvisibleto = true

# Title : Unnecessary call to 'Dictionary.ContainsKey(key)'
# Category : Performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public async Task CloseAsync(CancellationToken cancellationToken = default)
}
}

private class RegistrationDisposable : IDisposable
private sealed class RegistrationDisposable : IDisposable
{
private readonly Action _disposeAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ private async Task StartProcessingAsync()
}
}

private record Entry(Func<Task> TaskFactory, bool ContinueOnCapturedContext, TaskCompletionSource<object> TaskCompletion);
private sealed record Entry(Func<Task> TaskFactory, bool ContinueOnCapturedContext, TaskCompletionSource<object> TaskCompletion);
}
4 changes: 2 additions & 2 deletions src/Polly.Core/Registry/RegistryPipelineComponentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Polly.Registry;
/// <summary>
/// Builds a <see cref="PipelineComponent"/> used by the registry.
/// </summary>
internal class RegistryPipelineComponentBuilder<TBuilder, TKey>
internal sealed class RegistryPipelineComponentBuilder<TBuilder, TKey>
where TBuilder : ResiliencePipelineBuilderBase
where TKey : notnull
{
Expand Down Expand Up @@ -75,7 +75,7 @@ private Builder CreateBuilder()
builder);
}

private record Builder(
private sealed record Builder(
Func<PipelineComponent> ComponentFactory,
List<CancellationToken> ReloadTokens,
ResilienceStrategyTelemetry Telemetry,
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Simmy/Fault/ChaosFaultStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Polly.Simmy.Fault;

internal class ChaosFaultStrategy : ChaosStrategy
internal sealed class ChaosFaultStrategy : ChaosStrategy
{
private readonly ResilienceStrategyTelemetry _telemetry;

Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Simmy/Outcomes/ChaosOutcomeStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Polly.Simmy.Outcomes;

internal class ChaosOutcomeStrategy<T> : ChaosStrategy<T>
internal sealed class ChaosOutcomeStrategy<T> : ChaosStrategy<T>
{
private readonly ResilienceStrategyTelemetry _telemetry;
private readonly Func<OnOutcomeInjectedArguments<T>, ValueTask>? _onOutcomeInjected;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Polly.Utils.Pipeline;

internal class ComponentWithDisposeCallbacks : PipelineComponent
internal sealed class ComponentWithDisposeCallbacks : PipelineComponent
{
private readonly List<Action> _callbacks;

Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Utils/Pipeline/ExternalComponent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Polly.Utils.Pipeline;

[DebuggerDisplay("{Component}")]
internal class ExternalComponent : PipelineComponent
internal sealed class ExternalComponent : PipelineComponent
{
public ExternalComponent(PipelineComponent component) => Component = component;

Expand Down
8 changes: 4 additions & 4 deletions src/Polly.Core/Utils/Pipeline/ReloadableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ private void DisposeRegistration()
_tokenSource.Dispose();
}

internal record ReloadFailedArguments(Exception Exception);
internal sealed record ReloadFailedArguments(Exception Exception);

internal record DisposedFailedArguments(Exception Exception);
internal sealed record DisposedFailedArguments(Exception Exception);

#pragma warning disable S2094 // Classes should not be empty
#pragma warning disable S3253 // Constructor and destructor declarations should not be redundant
internal record OnReloadArguments();
internal sealed record OnReloadArguments();
#pragma warning restore S3253 // Constructor and destructor declarations should not be redundant
#pragma warning restore S2094 // Classes should not be empty

internal record Entry(PipelineComponent Component, List<CancellationToken> ReloadTokens, ResilienceStrategyTelemetry Telemetry);
internal sealed record Entry(PipelineComponent Component, List<CancellationToken> ReloadTokens, ResilienceStrategyTelemetry Telemetry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private static void AddResiliencePipelineBuilder(this IServiceCollection service
});
}

private class RegistryMarker<TKey>
private sealed class RegistryMarker<TKey>
{
public static readonly ServiceDescriptor ServiceDescriptor = ServiceDescriptor.Singleton(new RegistryMarker<TKey>());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Extensions/Telemetry/ResilienceTelemetryTags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Polly.Telemetry;

internal class ResilienceTelemetryTags
internal static class ResilienceTelemetryTags
{
public const string EventName = "event.name";

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Caching/AsyncGenericCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Polly.Caching;
/// Provides a strongly-typed wrapper over a non-generic CacheProviderAsync.
/// </summary>
/// <typeparam name="TCacheFormat">The type of the objects in the cache.</typeparam>
internal class AsyncGenericCacheProvider<TCacheFormat> : IAsyncCacheProvider<TCacheFormat>
internal sealed class AsyncGenericCacheProvider<TCacheFormat> : IAsyncCacheProvider<TCacheFormat>
{
private readonly IAsyncCacheProvider _wrappedCacheProvider;

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Caching/GenericCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Polly.Caching;
/// Provides a strongly-typed wrapper over a non-generic CacheProvider.
/// </summary>
/// <typeparam name="TCacheFormat">The type of the objects in the cache.</typeparam>
internal class GenericCacheProvider<TCacheFormat> : ISyncCacheProvider<TCacheFormat>
internal sealed class GenericCacheProvider<TCacheFormat> : ISyncCacheProvider<TCacheFormat>
{
private readonly ISyncCacheProvider _wrappedCacheProvider;

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Caching/GenericTtlStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Polly.Caching;
/// <summary>
/// Represents a strongly-typed <see cref="ITtlStrategy"/> wrapper of a non-generic strategy.
/// </summary>
internal class GenericTtlStrategy<TResult> : ITtlStrategy<TResult>
internal sealed class GenericTtlStrategy<TResult> : ITtlStrategy<TResult>
{
private readonly ITtlStrategy _wrappedTtlStrategy;

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/AdvancedCircuitController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Polly.CircuitBreaker;

internal class AdvancedCircuitController<TResult> : CircuitStateController<TResult>
internal sealed class AdvancedCircuitController<TResult> : CircuitStateController<TResult>
{
private const short NumberOfWindows = 10;
internal static readonly long ResolutionOfCircuitTimer = TimeSpan.FromMilliseconds(20).Ticks;
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Polly.CircuitBreaker;

internal class AsyncCircuitBreakerEngine
internal static class AsyncCircuitBreakerEngine
{
internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, CancellationToken, Task<TResult>> action,
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/CircuitBreakerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Polly.CircuitBreaker;

internal class CircuitBreakerEngine
internal static class CircuitBreakerEngine
{
internal static TResult Implementation<TResult>(
Func<Context, CancellationToken, TResult> action,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Polly.CircuitBreaker;

internal class ConsecutiveCountCircuitController<TResult> : CircuitStateController<TResult>
internal sealed class ConsecutiveCountCircuitController<TResult> : CircuitStateController<TResult>
{
private readonly int _exceptionsAllowedBeforeBreaking;
private int _consecutiveFailureCount;
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/HealthCount.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Polly.CircuitBreaker;

internal class HealthCount
internal sealed class HealthCount
{
public int Successes { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/RollingHealthMetrics.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#nullable enable
namespace Polly.CircuitBreaker;

internal class RollingHealthMetrics : IHealthMetrics
internal sealed class RollingHealthMetrics : IHealthMetrics
{
private readonly long _samplingDuration;
private readonly long _windowDuration;
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/CircuitBreaker/SingleHealthMetrics.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#nullable enable
namespace Polly.CircuitBreaker;

internal class SingleHealthMetrics : IHealthMetrics
internal sealed class SingleHealthMetrics : IHealthMetrics
{
private readonly long _samplingDuration;

Expand Down
2 changes: 1 addition & 1 deletion src/Polly/Fallback/AsyncFallbackEngine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#nullable enable
namespace Polly.Fallback;

internal class AsyncFallbackEngine
internal static class AsyncFallbackEngine
{
internal static async Task<TResult> ImplementationAsync<TResult>(
Func<Context, CancellationToken, Task<TResult>> action,
Expand Down
4 changes: 2 additions & 2 deletions src/Polly/Utilities/TimedLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Dispose()
#if DEBUG
// (In Debug mode, we make it a class so that we can add a finalizer
// in order to detect when the object is not freed.)
private class Sentinel
private sealed class Sentinel
{
#if NETSTANDARD2_0
~Sentinel()
Expand All @@ -85,7 +85,7 @@ private class Sentinel
#endif
}

internal class LockTimeoutException : Exception
internal sealed class LockTimeoutException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="LockTimeoutException"/> class.
Expand Down
2 changes: 1 addition & 1 deletion src/Snippets/Docs/Chaos.Behavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void Pattern_InjectDelay()
}
}

internal class RedisConnectionException : Exception
internal sealed class RedisConnectionException : Exception
{
public RedisConnectionException()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Snippets/Docs/Chaos.Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static void CentralPipelineIntegration(IServiceCollection services)
#region chaos-extension

// Options that represent the chaos pipeline
public class MyChaosOptions
public sealed class MyChaosOptions
{
public ChaosFaultStrategyOptions Fault { get; set; } = new()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Snippets/Docs/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static async Task KeyedServicesDefine(IServiceCollection services)

#region di-keyed-services-use

public class MyApi
public sealed class MyApi
{
private readonly ResiliencePipeline _pipeline;
private readonly ResiliencePipeline<HttpResponseMessage> _genericPipeline;
Expand Down
4 changes: 2 additions & 2 deletions src/Snippets/Docs/Fallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public static void Usage()
#endregion
}

public class UserAvatar
public sealed class UserAvatar
{
public static readonly UserAvatar Blank = new();

public static UserAvatar GetRandomAvatar() => new();
}

private class CustomNetworkException : Exception
private sealed class CustomNetworkException : Exception
{
public CustomNetworkException()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Snippets/Docs/Hedging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal static class ResilienceKeys

#region hedging-handler

internal class HedgingHandler : DelegatingHandler
internal sealed class HedgingHandler : DelegatingHandler
{
private readonly ResiliencePipeline<HttpResponseMessage> _pipeline;

Expand Down
4 changes: 2 additions & 2 deletions src/Snippets/Docs/Performance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ static async (context, state) =>

private static ValueTask<Member> GetMemberAsync(string id, CancellationToken token) => default;

public class Member
public sealed class Member
{
}

#region perf-reuse-pipelines

public class MyApi
public sealed class MyApi
{
private readonly ResiliencePipelineRegistry<string> _registry;

Expand Down
4 changes: 2 additions & 2 deletions src/Snippets/Docs/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public static void AddResiliencePipelineWithTelemetry()

#region telemetry-listeners

internal class MyTelemetryListener : TelemetryListener
internal sealed class MyTelemetryListener : TelemetryListener
{
public override void Write<TResult, TArgs>(in TelemetryEventArguments<TResult, TArgs> args)
{
Console.WriteLine($"Telemetry event occurred: {args.Event.EventName}");
}
}

internal class MyMeteringEnricher : MeteringEnricher
internal sealed class MyMeteringEnricher : MeteringEnricher
{
public override void Enrich<TResult, TArgs>(in EnrichmentContext<TResult, TArgs> context)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Snippets/Docs/Utils/SomeExceptionType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Snippets.Docs.Utils;

internal class SomeExceptionType : Exception
internal sealed class SomeExceptionType : Exception
{
public SomeExceptionType(string message)
: base(message)
Expand Down

0 comments on commit 5b39448

Please sign in to comment.