Skip to content

Commit a1e4853

Browse files
authored
Enable CA1852 and fix warnings for it (#2942)
1 parent d48af3e commit a1e4853

File tree

7 files changed

+11
-8
lines changed

7 files changed

+11
-8
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
138138
csharp_preserve_single_line_statements = true
139139
csharp_preserve_single_line_blocks = true
140140

141+
# Help Link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852
142+
# Tags : Telemetry, EnabledRuleInAggressiveMode, CompilationEnd
143+
dotnet_diagnostic.CA1852.severity = warning
141144

142145
# IDE preferences
143146
dotnet_diagnostic.IDE0090.severity = silent # IDE0090: Use 'new(...)'

tests/BasicTest/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public CustomConfig()
3434
AddJob(Configure(Job.Default.WithRuntime(CoreRuntime.Core50)));
3535
}
3636
}
37-
internal class SlowConfig : CustomConfig
37+
internal sealed class SlowConfig : CustomConfig
3838
{
3939
protected override Job Configure(Job j)
4040
=> j.WithLaunchCount(1)

tests/StackExchange.Redis.Benchmarks/SlowConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace StackExchange.Redis.Benchmarks
44
{
5-
internal class SlowConfig : CustomConfig
5+
internal sealed class SlowConfig : CustomConfig
66
{
77
protected override Job Configure(Job j)
88
=> j.WithLaunchCount(1)

tests/StackExchange.Redis.Tests/ConfigTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public void HttpTunnelCanRoundtrip(string input, string expected)
713713
Assert.Equal($"127.0.0.1:6380,tunnel={expected}", cs);
714714
}
715715

716-
private class CustomTunnel : Tunnel { }
716+
private sealed class CustomTunnel : Tunnel { }
717717

718718
[Fact]
719719
public void CustomTunnelCanRoundtripMinusTunnel()

tests/StackExchange.Redis.Tests/LoggerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
7878
/// <summary>
7979
/// To save on test time, no reason to spin up n connections just to test n logging implementations...
8080
/// </summary>
81-
private class TestMultiLogger(params ILogger[] loggers) : ILogger
81+
private sealed class TestMultiLogger(params ILogger[] loggers) : ILogger
8282
{
8383
#if NET8_0_OR_GREATER
8484
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
@@ -95,7 +95,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
9595
}
9696
}
9797

98-
private class TestLogger : ILogger
98+
private sealed class TestLogger : ILogger
9999
{
100100
private readonly StringBuilder sb = new StringBuilder();
101101
private long _callCount;

tests/StackExchange.Redis.Tests/ParseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void ProcessMessages(Arena<RawResult> arena, ReadOnlySequence<byte> buff
7979
Assert.Equal(expected, found);
8080
}
8181

82-
private class FragmentedSegment<T> : ReadOnlySequenceSegment<T>
82+
private sealed class FragmentedSegment<T> : ReadOnlySequenceSegment<T>
8383
{
8484
public FragmentedSegment(long runningIndex, ReadOnlyMemory<T> memory)
8585
{

tests/StackExchange.Redis.Tests/ProfilingTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,14 @@ public async Task ManyContexts()
204204
}
205205
}
206206

207-
internal class PerThreadProfiler
207+
internal sealed class PerThreadProfiler
208208
{
209209
private readonly ThreadLocal<ProfilingSession> perThreadSession = new ThreadLocal<ProfilingSession>(() => new ProfilingSession());
210210

211211
public ProfilingSession GetSession() => perThreadSession.Value!;
212212
}
213213

214-
internal class AsyncLocalProfiler
214+
internal sealed class AsyncLocalProfiler
215215
{
216216
private readonly AsyncLocal<ProfilingSession> perThreadSession = new AsyncLocal<ProfilingSession>();
217217

0 commit comments

Comments
 (0)