From 9e79a26af5bf84a63255b8962ef438b0db1e9aaa Mon Sep 17 00:00:00 2001 From: Henrik Gedionsen Date: Thu, 21 Aug 2025 09:23:42 +0200 Subject: [PATCH] Enable CA1852 and fix warnings for it --- .editorconfig | 3 +++ tests/BasicTest/Program.cs | 2 +- tests/StackExchange.Redis.Benchmarks/SlowConfig.cs | 2 +- tests/StackExchange.Redis.Tests/ConfigTests.cs | 2 +- tests/StackExchange.Redis.Tests/LoggerTests.cs | 4 ++-- tests/StackExchange.Redis.Tests/ParseTests.cs | 2 +- tests/StackExchange.Redis.Tests/ProfilingTests.cs | 4 ++-- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.editorconfig b/.editorconfig index a00642936..eb05866a0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -138,6 +138,9 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false csharp_preserve_single_line_statements = true csharp_preserve_single_line_blocks = true +# Help Link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852 +# Tags : Telemetry, EnabledRuleInAggressiveMode, CompilationEnd +dotnet_diagnostic.CA1852.severity = warning # IDE preferences dotnet_diagnostic.IDE0090.severity = silent # IDE0090: Use 'new(...)' diff --git a/tests/BasicTest/Program.cs b/tests/BasicTest/Program.cs index faff1b7d7..2977c42c2 100644 --- a/tests/BasicTest/Program.cs +++ b/tests/BasicTest/Program.cs @@ -34,7 +34,7 @@ public CustomConfig() AddJob(Configure(Job.Default.WithRuntime(CoreRuntime.Core50))); } } - internal class SlowConfig : CustomConfig + internal sealed class SlowConfig : CustomConfig { protected override Job Configure(Job j) => j.WithLaunchCount(1) diff --git a/tests/StackExchange.Redis.Benchmarks/SlowConfig.cs b/tests/StackExchange.Redis.Benchmarks/SlowConfig.cs index 0c3546006..fc1ab6f71 100644 --- a/tests/StackExchange.Redis.Benchmarks/SlowConfig.cs +++ b/tests/StackExchange.Redis.Benchmarks/SlowConfig.cs @@ -2,7 +2,7 @@ namespace StackExchange.Redis.Benchmarks { - internal class SlowConfig : CustomConfig + internal sealed class SlowConfig : CustomConfig { protected override Job Configure(Job j) => j.WithLaunchCount(1) diff --git a/tests/StackExchange.Redis.Tests/ConfigTests.cs b/tests/StackExchange.Redis.Tests/ConfigTests.cs index 995b66a5a..801565a83 100644 --- a/tests/StackExchange.Redis.Tests/ConfigTests.cs +++ b/tests/StackExchange.Redis.Tests/ConfigTests.cs @@ -713,7 +713,7 @@ public void HttpTunnelCanRoundtrip(string input, string expected) Assert.Equal($"127.0.0.1:6380,tunnel={expected}", cs); } - private class CustomTunnel : Tunnel { } + private sealed class CustomTunnel : Tunnel { } [Fact] public void CustomTunnelCanRoundtripMinusTunnel() diff --git a/tests/StackExchange.Redis.Tests/LoggerTests.cs b/tests/StackExchange.Redis.Tests/LoggerTests.cs index e001250b0..682856baa 100644 --- a/tests/StackExchange.Redis.Tests/LoggerTests.cs +++ b/tests/StackExchange.Redis.Tests/LoggerTests.cs @@ -78,7 +78,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except /// /// To save on test time, no reason to spin up n connections just to test n logging implementations... /// - private class TestMultiLogger(params ILogger[] loggers) : ILogger + private sealed class TestMultiLogger(params ILogger[] loggers) : ILogger { #if NET8_0_OR_GREATER public IDisposable? BeginScope(TState state) where TState : notnull => null; @@ -95,7 +95,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except } } - private class TestLogger : ILogger + private sealed class TestLogger : ILogger { private readonly StringBuilder sb = new StringBuilder(); private long _callCount; diff --git a/tests/StackExchange.Redis.Tests/ParseTests.cs b/tests/StackExchange.Redis.Tests/ParseTests.cs index 51c17fbf3..2621ddab9 100644 --- a/tests/StackExchange.Redis.Tests/ParseTests.cs +++ b/tests/StackExchange.Redis.Tests/ParseTests.cs @@ -79,7 +79,7 @@ private void ProcessMessages(Arena arena, ReadOnlySequence buff Assert.Equal(expected, found); } - private class FragmentedSegment : ReadOnlySequenceSegment + private sealed class FragmentedSegment : ReadOnlySequenceSegment { public FragmentedSegment(long runningIndex, ReadOnlyMemory memory) { diff --git a/tests/StackExchange.Redis.Tests/ProfilingTests.cs b/tests/StackExchange.Redis.Tests/ProfilingTests.cs index f374788db..366abd395 100644 --- a/tests/StackExchange.Redis.Tests/ProfilingTests.cs +++ b/tests/StackExchange.Redis.Tests/ProfilingTests.cs @@ -204,14 +204,14 @@ public async Task ManyContexts() } } - internal class PerThreadProfiler + internal sealed class PerThreadProfiler { private readonly ThreadLocal perThreadSession = new ThreadLocal(() => new ProfilingSession()); public ProfilingSession GetSession() => perThreadSession.Value!; } - internal class AsyncLocalProfiler + internal sealed class AsyncLocalProfiler { private readonly AsyncLocal perThreadSession = new AsyncLocal();