Skip to content

Commit 57e4c42

Browse files
authored
Prevent diagnostics on .NET SDK 8.0.100 (#2049)
Address collection expression diagnostics In most cases, we now just use the new (C# 12.0) collection expression syntax. However, we've disabled IDE0305 because it makes suggestions that aren't an obvious improvement. It wants to rewrite use of ToArray() to be a collection expression. E.g. something.ToArray() would become [.. something]. Perhaps that will seem natural once we've all got used to spreads in collection expressions, but to me (idg10) today that looks odd. Add comment explaining why we've disable IDE0290 Make UWP test runner use the same warning settings as everything else, except for CS0618, which a large number of tests appear to depend on.
1 parent bd4fb9e commit 57e4c42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+143
-148
lines changed

Rx.NET/Source/Directory.build.props

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<EnableNETAnalyzers>true</EnableNETAnalyzers>
6262

6363
<!--
64-
Disable diagnostics:
64+
Disabled diagnostics:
6565
CA1001 - types holding disposable fields should implement IDisposable. See next item.
6666
CA2213 - IDisposable types should Dispose any IDisposable fields. This rule finds over 600
6767
examples! These are all in subtle multithreaded or async code. Some of them appear
@@ -74,9 +74,21 @@
7474
7575
IDE0056 - Use of index/range syntax - relevant types not available on all targets, so we can't
7676
IDE0057 do this.
77+
78+
IDE0290 - Primary ctors. This diagnostic suggests them in a lot of places where we don't want
79+
them. E.g., in most types with multiple constructors I find I prefer not to have
80+
a primary ctor. Since this is all or nothing, we turn it off.
81+
IDE0305 - Suggests Collection expressions in place of .ToArray. E.g, wants to change this:
82+
_readyList.ToArray()
83+
to this:
84+
[.. readyList]
85+
This won't improve performance as far as we know (sometimes a reason for using that
86+
syntax), and it's not obviously an improvement in readability.
87+
88+
CA1510 - use ArgumentNullException.ThrowIf (not available on all targets)
89+
CA1513 - use ObjectDisposedException.ThrowIf (not available on all targets)
7790
-->
78-
<!-- Get diagnostics back to the level that the .NET 5.0 SDK had for now. Fix these properly before release. -->
79-
<NoWarn>$(NoWarn);CA1001;CA2213;IDE0056;IDE0057</NoWarn>
91+
<NoWarn>$(NoWarn);CA1001;CA2213;CA1510;CA1513;IDE0056;IDE0057;IDE0290;IDE0305</NoWarn>
8092
</PropertyGroup>
8193

8294
<ItemGroup>

Rx.NET/Source/src/Microsoft.Reactive.Testing/ColdObservable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class ColdObservable<T> : ITestableObservable<T>
1313
{
1414
private readonly TestScheduler _scheduler;
1515
private readonly Recorded<Notification<T>>[] _messages;
16-
private readonly List<Subscription> _subscriptions = new();
16+
private readonly List<Subscription> _subscriptions = [];
1717

1818
public ColdObservable(TestScheduler scheduler, params Recorded<Notification<T>>[] messages)
1919
{

Rx.NET/Source/src/Microsoft.Reactive.Testing/HotObservable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace Microsoft.Reactive.Testing
1212
internal class HotObservable<T> : ITestableObservable<T>
1313
{
1414
private readonly TestScheduler _scheduler;
15-
private readonly List<IObserver<T>> _observers = new();
16-
private readonly List<Subscription> _subscriptions = new();
15+
private readonly List<IObserver<T>> _observers = [];
16+
private readonly List<Subscription> _subscriptions = [];
1717
private readonly Recorded<Notification<T>>[] _messages;
1818

1919
public HotObservable(TestScheduler scheduler, params Recorded<Notification<T>>[] messages)

Rx.NET/Source/src/Microsoft.Reactive.Testing/MockObserver.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ namespace Microsoft.Reactive.Testing
1111
internal class MockObserver<T> : ITestableObserver<T>
1212
{
1313
private readonly TestScheduler _scheduler;
14-
private readonly List<Recorded<Notification<T>>> _messages;
14+
private readonly List<Recorded<Notification<T>>> _messages = [];
1515

1616
public MockObserver(TestScheduler scheduler)
1717
{
1818
_scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
19-
_messages = new List<Recorded<Notification<T>>>();
2019
}
2120

2221
public void OnNext(T value)

Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public partial class LocalScheduler
5555
/// Set of disposable handles to all of the current short term work Schedule calls,
5656
/// allowing those to be cancelled upon a system clock change.
5757
/// </summary>
58-
private readonly HashSet<IDisposable> _shortTermWork = new();
58+
private readonly HashSet<IDisposable> _shortTermWork = [];
5959

6060
/// <summary>
6161
/// Threshold where an item is considered to be short term work or gets moved from

Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,11 @@ private abstract class InvokeRecBaseState : IDisposable
175175
{
176176
protected readonly IScheduler Scheduler;
177177

178-
protected readonly CompositeDisposable Group;
178+
protected readonly CompositeDisposable Group = [];
179179

180180
protected InvokeRecBaseState(IScheduler scheduler)
181181
{
182182
Scheduler = scheduler;
183-
Group = new CompositeDisposable();
184183
}
185184

186185
public void Dispose()

Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ namespace System.Reactive.Concurrency
1010
//
1111
public static partial class Scheduler
1212
{
13-
internal static Type[] Optimizations = {
13+
internal static Type[] Optimizations =
14+
[
1415
typeof(ISchedulerLongRunning),
1516
typeof(IStopwatchProvider),
1617
typeof(ISchedulerPeriodic)
1718
/* update this list if new interface-based optimizations are added */
18-
};
19+
];
1920

2021
/// <summary>
2122
/// Returns the <see cref="ISchedulerLongRunning"/> implementation of the specified scheduler, or <c>null</c> if no such implementation is available.

Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerWrapper.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ namespace System.Reactive.Concurrency
99
internal abstract class SchedulerWrapper : IScheduler, IServiceProvider
1010
{
1111
protected readonly IScheduler _scheduler;
12-
private readonly ConditionalWeakTable<IScheduler, IScheduler> _cache;
12+
private readonly ConditionalWeakTable<IScheduler, IScheduler> _cache =
13+
#if NET472_OR_GREATER || NETSTANDARD2_0_OR_GREATER
14+
new();
15+
#else
16+
[];
17+
#endif
1318

1419
protected SchedulerWrapper(IScheduler scheduler)
1520
{
1621
_scheduler = scheduler;
17-
_cache = new ConditionalWeakTable<IScheduler, IScheduler>();
1822
}
1923

2024
protected SchedulerWrapper(IScheduler scheduler, ConditionalWeakTable<IScheduler, IScheduler> cache)

Rx.NET/Source/src/System.Reactive/Diagnostics/CodeAnalysis/NullableAttributes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal sealed class MemberNotNullAttribute : Attribute
9696
/// The field or property member that is promised to be not-null.
9797
/// </param>
9898
#pragma warning disable CA1019 // Define accessors for attribute arguments - this needs to be identical to the real type
99-
public MemberNotNullAttribute(string member) => Members = new[] { member };
99+
public MemberNotNullAttribute(string member) => Members = [member];
100100
#pragma warning restore CA1019
101101

102102
/// <summary>Initializes the attribute with the list of field and property members.</summary>
@@ -125,7 +125,7 @@ public MemberNotNullWhenAttribute(bool returnValue, string member)
125125
#pragma warning restore CA1019
126126
{
127127
ReturnValue = returnValue;
128-
Members = new[] { member };
128+
Members = [member];
129129
}
130130

131131
/// <summary>Initializes the attribute with the specified return value condition and list of field and property members.</summary>

Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class CompositeDisposable : ICollection<IDisposable>, ICancelable
2929
/// </summary>
3030
public CompositeDisposable()
3131
{
32-
_disposables = new List<IDisposable?>();
32+
_disposables = [];
3333
}
3434

3535
/// <summary>
@@ -387,7 +387,7 @@ public IEnumerator<IDisposable> GetEnumerator()
387387
/// method to avoid allocation on disposed or empty composites.
388388
/// </summary>
389389
private static readonly CompositeEnumerator EmptyEnumerator =
390-
new(Array.Empty<IDisposable?>());
390+
new([]);
391391

392392
/// <summary>
393393
/// An enumerator for an array of disposables.

0 commit comments

Comments
 (0)