Skip to content

Commit 721ac32

Browse files
authored
use more collection expressions and mark as error for Rider and R# in editorconfig (#5377)
1 parent 43d1d16 commit 721ac32

File tree

191 files changed

+611
-666
lines changed

Some content is hidden

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

191 files changed

+611
-666
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ resharper_empty_constructor_highlighting = warning
689689
# Redundant empty argument list on object creation expression
690690
resharper_redundant_empty_object_creation_argument_list_highlighting = warning
691691

692-
# IDE0300: Simplify collection initialization
693-
dotnet_style_prefer_collection_expression = false
692+
# IDE0300-IDE0306: Simplify collection initialization
693+
dotnet_style_prefer_collection_expression = true
694694

695695
# IDE0065: using directive placement
696696
csharp_using_directive_placement = outside_namespace:warning

samples/Playground/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public static async Task<int> Main(string[] args)
5757
using TestingPlatformClient client = await TestingPlatformClientFactory.StartAsServerAndConnectToTheClientAsync(Environment.ProcessPath!);
5858

5959
await client.InitializeAsync();
60-
List<TestNodeUpdate> testNodeUpdates = new();
60+
List<TestNodeUpdate> testNodeUpdates = [];
6161
ResponseListener discoveryResponse = await client.DiscoverTestsAsync(Guid.NewGuid(), node =>
6262
{
6363
testNodeUpdates.AddRange(node);
6464
return Task.CompletedTask;
6565
});
6666
await discoveryResponse.WaitCompletionAsync();
6767

68-
ResponseListener runRequest = await client.RunTestsAsync(Guid.NewGuid(), testNodeUpdates.Select(x => x.Node).ToArray(), _ => Task.CompletedTask);
68+
ResponseListener runRequest = await client.RunTestsAsync(Guid.NewGuid(), [.. testNodeUpdates.Select(x => x.Node)], _ => Task.CompletedTask);
6969
await runRequest.WaitCompletionAsync();
7070

7171
await client.ExitAsync();
@@ -86,7 +86,7 @@ internal sealed class DummyAdapter : ITestFramework, IDataProducer
8686

8787
public string Description => string.Empty;
8888

89-
public Type[] DataTypesProduced => new[] { typeof(TestNodeUpdateMessage) };
89+
public Type[] DataTypesProduced => [typeof(TestNodeUpdateMessage)];
9090

9191
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult { IsSuccess = true });
9292

samples/Playground/ServerMode/TestNodeUpdateCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class TestNodeUpdateCollector
1010
private readonly TaskCompletionSource _taskCompletionSource = new();
1111
private readonly Func<TestNodeUpdate, bool>? _completeCollector;
1212

13-
public ConcurrentBag<TestNodeUpdate> TestNodeUpdates { get; } = new();
13+
public ConcurrentBag<TestNodeUpdate> TestNodeUpdates { get; } = [];
1414

1515
public TestNodeUpdateCollector(Func<TestNodeUpdate, bool>? completeCollectorWhen = null) => _completeCollector = completeCollectorWhen;
1616

samples/Playground/ServerMode/v1.0.0/TestingPlatformClient.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,9 @@ private sealed class TargetHandler
171171
private readonly ConcurrentDictionary<Guid, ResponseListener> _listeners
172172
= new();
173173

174-
private readonly ConcurrentBag<LogsCollector> _logListeners
175-
= new();
174+
private readonly ConcurrentBag<LogsCollector> _logListeners = [];
176175

177-
private readonly ConcurrentBag<TelemetryCollector> _telemetryPayloads
178-
= new();
176+
private readonly ConcurrentBag<TelemetryCollector> _telemetryPayloads = [];
179177

180178
public void RegisterTelemetryListener(TelemetryCollector listener)
181179
=> _telemetryPayloads.Add(listener);

src/Adapter/MSTest.Engine/Engine/BFSTestNodeVisitor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public BFSTestNodeVisitor(IEnumerable<TestNode> rootTestNodes, ITestExecutionFil
2929
_testArgumentsManager = testArgumentsManager;
3030
}
3131

32-
internal KeyValuePair<TestNodeUid, List<TestNode>>[] DuplicatedNodes { get; private set; } = Array.Empty<KeyValuePair<TestNodeUid, List<TestNode>>>();
32+
internal KeyValuePair<TestNodeUid, List<TestNode>>[] DuplicatedNodes { get; private set; } = [];
3333

3434
public async Task VisitAsync(Func<TestNode, TestNodeUid?, Task> onIncludedTestNodeAsync)
3535
{
3636
// This is case sensitive, and culture insensitive, to keep UIDs unique, and comparable between different system.
37-
Dictionary<TestNodeUid, List<TestNode>> testNodesByUid = new();
37+
Dictionary<TestNodeUid, List<TestNode>> testNodesByUid = [];
3838
Queue<(TestNode CurrentNode, TestNodeUid? ParentNodeUid, StringBuilder NodeFullPath)> queue = new();
3939
foreach (TestNode node in _rootTestNodes)
4040
{
@@ -47,7 +47,7 @@ public async Task VisitAsync(Func<TestNode, TestNodeUid?, Task> onIncludedTestNo
4747

4848
if (!testNodesByUid.TryGetValue(currentNode.StableUid, out List<TestNode>? testNodes))
4949
{
50-
testNodes = new();
50+
testNodes = [];
5151
testNodesByUid.Add(currentNode.StableUid, testNodes);
5252
}
5353

@@ -94,7 +94,7 @@ public async Task VisitAsync(Func<TestNode, TestNodeUid?, Task> onIncludedTestNo
9494
}
9595
}
9696

97-
DuplicatedNodes = testNodesByUid.Where(x => x.Value.Count > 1).ToArray();
97+
DuplicatedNodes = [.. testNodesByUid.Where(x => x.Value.Count > 1)];
9898
}
9999

100100
private static PropertyBag CreatePropertyBagForFilter(IProperty[] properties)

src/Adapter/MSTest.Engine/Engine/TestArgumentsManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.Testing.Framework;
77

88
internal sealed class TestArgumentsManager : ITestArgumentsManager
99
{
10-
private readonly Dictionary<TestNodeUid, Func<TestArgumentsContext, ITestArgumentsEntry>> _testArgumentsEntryProviders = new();
10+
private readonly Dictionary<TestNodeUid, Func<TestArgumentsContext, ITestArgumentsEntry>> _testArgumentsEntryProviders = [];
1111
private bool _isRegistrationFrozen;
1212

1313
public void RegisterTestArgumentsEntryProvider<TArguments>(
@@ -53,8 +53,8 @@ internal async Task<TestNode> ExpandTestNodeAsync(TestNode currentNode)
5353
};
5454
}
5555

56-
HashSet<TestNodeUid> expandedTestNodeUids = new();
57-
List<TestNode> expandedTestNodes = new(currentNode.Tests);
56+
HashSet<TestNodeUid> expandedTestNodeUids = [];
57+
List<TestNode> expandedTestNodes = [.. currentNode.Tests];
5858
switch (currentNode)
5959
{
6060
case IParameterizedTestNode parameterizedTestNode:
@@ -98,7 +98,7 @@ internal async Task<TestNode> ExpandTestNodeAsync(TestNode currentNode)
9898
DisplayName = currentNode.DisplayName,
9999
OverriddenEdgeName = currentNode.OverriddenEdgeName,
100100
Properties = currentNode.Properties,
101-
Tests = expandedTestNodes.ToArray(),
101+
Tests = [.. expandedTestNodes],
102102
};
103103

104104
return expandedNode;

src/Adapter/MSTest.Engine/Engine/TestFixtureManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ namespace Microsoft.Testing.Framework;
1010

1111
internal sealed class TestFixtureManager : ITestFixtureManager
1212
{
13-
private readonly Dictionary<FixtureId, Dictionary<Type, AsyncLazy<object>>> _fixtureInstancesByFixtureId = new();
14-
private readonly Dictionary<TestNode, FixtureId[]> _fixtureIdsUsedByTestNode = new();
13+
private readonly Dictionary<FixtureId, Dictionary<Type, AsyncLazy<object>>> _fixtureInstancesByFixtureId = [];
14+
private readonly Dictionary<TestNode, FixtureId[]> _fixtureIdsUsedByTestNode = [];
1515

1616
// We could improve this by doing some optimistic lock but we expect a rather low contention on this.
1717
// We use a dictionary as performance improvement because we know that when the registration is complete
1818
// we will only read the collection (so no need for concurrency handling).
19-
private readonly Dictionary<FixtureId, CountHolder> _fixtureUses = new();
19+
private readonly Dictionary<FixtureId, CountHolder> _fixtureUses = [];
2020
private readonly CancellationToken _cancellationToken;
2121
private bool _isRegistrationFrozen;
2222
private bool _isUsageRegistrationFrozen;
@@ -79,7 +79,7 @@ internal void RegisterFixtureUsage(TestNode testNode, string[] fixtureIds)
7979
return;
8080
}
8181

82-
_fixtureIdsUsedByTestNode.Add(testNode, fixtureIds.Select(x => new FixtureId(x)).ToArray());
82+
_fixtureIdsUsedByTestNode.Add(testNode, [.. fixtureIds.Select(x => new FixtureId(x))]);
8383
foreach (string fixtureId in fixtureIds)
8484
{
8585
if (!_fixtureUses.TryGetValue(fixtureId, out CountHolder? uses))

src/Adapter/MSTest.Engine/Engine/TestFrameworkEngine.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public TestFrameworkEngine(TestFrameworkConfiguration testFrameworkConfiguration
3838
_configuration = new(configuration);
3939
}
4040

41-
public Type[] DataTypesProduced { get; }
42-
= new Type[1] { typeof(TestNodeUpdateMessage) };
41+
public Type[] DataTypesProduced { get; } = [typeof(TestNodeUpdateMessage)];
4342

4443
public string Uid => _extension.Uid;
4544

@@ -62,7 +61,7 @@ public async Task<Result> ExecuteRequestAsync(TestExecutionRequest testExecution
6261
private async Task<Result> ExecuteTestNodeRunAsync(RunTestExecutionRequest request, IMessageBus messageBus,
6362
CancellationToken cancellationToken)
6463
{
65-
List<TestNode> allRootTestNodes = new();
64+
List<TestNode> allRootTestNodes = [];
6665
TestFixtureManager fixtureManager = new(cancellationToken);
6766
TestArgumentsManager argumentsManager = new();
6867
TestSessionContext testSessionContext = new(_configuration, fixtureManager, argumentsManager, request.Session.SessionUid,
@@ -96,7 +95,7 @@ await testNodesVisitor.VisitAsync((testNode, parentTestNodeUid) =>
9695
.OfType<FrameworkEngineMetadataProperty>()
9796
.SingleOrDefault()
9897
.UsedFixtureIds
99-
?? Array.Empty<string>();
98+
?? [];
10099
fixtureManager.RegisterFixtureUsage(testNode, fixtureIds);
101100

102101
return Task.CompletedTask;
@@ -142,7 +141,7 @@ Task PublishDataAsync(IData data)
142141
private async Task<Result> ExecuteTestNodeDiscoveryAsync(DiscoverTestExecutionRequest request, IMessageBus messageBus,
143142
CancellationToken cancellationToken)
144143
{
145-
List<TestNode> allRootTestNodes = new();
144+
List<TestNode> allRootTestNodes = [];
146145
TestFixtureManager fixtureManager = new(cancellationToken);
147146
TestArgumentsManager argumentsManager = new();
148147
TestSessionContext testSessionContext = new(_configuration, fixtureManager, argumentsManager, request.Session.SessionUid,

src/Adapter/MSTest.Engine/Engine/ThreadPoolTestNodeRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.Testing.Framework;
1616
internal sealed class ThreadPoolTestNodeRunner : IDisposable
1717
{
1818
private readonly SemaphoreSlim? _maxParallelTests;
19-
private readonly ConcurrentBag<Task<Result>> _runningTests = new();
19+
private readonly ConcurrentBag<Task<Result>> _runningTests = [];
2020
private readonly ConcurrentDictionary<TestNodeUid, int> _runningTestNodeUids = new();
2121
private readonly CountdownEvent _ensureTaskQueuedCountdownEvent = new(1);
2222
private readonly Func<IData, Task> _publishDataAsync;

src/Adapter/MSTest.Engine/Helpers/Result.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.Testing.Framework;
55

66
internal sealed class Result
77
{
8-
private readonly List<IReason> _reasons = new();
8+
private readonly List<IReason> _reasons = [];
99

1010
private Result()
1111
{

0 commit comments

Comments
 (0)