Skip to content

Commit 98fdce6

Browse files
authored
style: enforce braces on all control flow blocks (IDE0011) (#263)
Add csharp_prefer_braces rule to src/.editorconfig since root=true was blocking inheritance from the repo-root config. Run dotnet format to auto-fix all 52 files with braceless if/else/for/foreach/while blocks.
1 parent d033b19 commit 98fdce6

52 files changed

Lines changed: 448 additions & 7 deletions

File tree

Some content is hidden

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

src/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ trim_trailing_whitespace = true
1212
insert_final_newline = true
1313

1414
[*.cs]
15+
# Require braces on all control flow blocks
16+
csharp_prefer_braces = true : error
17+
1518
# Meziantou.Analyzer rules - downgrade to suggestions for existing code
1619
# These can be gradually fixed over time
1720

src/AzureEventGridSimulator.ServiceDefaults/Extensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builde
9696
);
9797

9898
if (useOtlpExporter)
99+
{
99100
builder.Services.AddOpenTelemetry().UseOtlpExporter();
101+
}
100102

101103
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
102104
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))

src/AzureEventGridSimulator.Tests/ActualSimulatorTests/ActualSimulatorFixture.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private static async Task WaitForSimulatorToBeReady()
6868
var stopwatch = Stopwatch.StartNew();
6969

7070
while (stopwatch.ElapsedMilliseconds < MaxStartupWaitTimeMs)
71+
{
7172
try
7273
{
7374
// Try to connect to the simulator's endpoint
@@ -87,6 +88,7 @@ private static async Task WaitForSimulatorToBeReady()
8788
// Timeout, wait and retry
8889
await Task.Delay(PollingIntervalMs);
8990
}
91+
}
9092

9193
throw new InvalidOperationException(
9294
$"Simulator did not start within {MaxStartupWaitTimeMs}ms"
@@ -96,7 +98,9 @@ private static async Task WaitForSimulatorToBeReady()
9698
private void KillExistingSimulators()
9799
{
98100
if (_simulatorExePath == null)
101+
{
99102
return;
103+
}
100104

101105
try
102106
{
@@ -115,7 +119,9 @@ private void KillExistingSimulators()
115119
.ToArray();
116120

117121
foreach (var process in simulatorProcesses)
122+
{
118123
process.Kill();
124+
}
119125
}
120126
catch
121127
{

src/AzureEventGridSimulator.Tests/Domain/Services/Dashboard/EventHistoryStoreTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public void Add_ExceedsMaxCapacity_EvictsOldestEvents()
4444
{
4545
// Add more than max capacity
4646
for (var i = 0; i < EventHistoryStore.MaxCapacityPerTopic + 10; i++)
47+
{
4748
_store.Add(CreateTestRecord($"event-{i}"));
49+
}
4850

4951
_store.Count.ShouldBe(EventHistoryStore.MaxCapacityPerTopic);
5052
_store.TotalEventsReceived.ShouldBe(EventHistoryStore.MaxCapacityPerTopic + 10);
@@ -54,7 +56,9 @@ public void Add_ExceedsMaxCapacity_EvictsOldestEvents()
5456
public void Add_ExceedsMaxCapacity_OldestEventsAreRemoved()
5557
{
5658
for (var i = 0; i < EventHistoryStore.MaxCapacityPerTopic + 5; i++)
59+
{
5760
_store.Add(CreateTestRecord($"event-{i}"));
61+
}
5862

5963
// First 5 events should be evicted
6064
_store.Get("event-0").ShouldBeNull();

src/AzureEventGridSimulator.Tests/UnitTests/CloudEvents/CloudEventSchemaParserTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,24 @@ private static DefaultHttpContext CreateBinaryModeContext(
407407
};
408408

409409
if (time != null)
410+
{
410411
context.Request.Headers[Constants.CeTimeHeader] = time;
412+
}
411413

412414
if (subject != null)
415+
{
413416
context.Request.Headers[Constants.CeSubjectHeader] = subject;
417+
}
414418

415419
if (dataContentType != null)
420+
{
416421
context.Request.Headers[Constants.CeDataContentTypeHeader] = dataContentType;
422+
}
417423

418424
if (dataSchema != null)
425+
{
419426
context.Request.Headers[Constants.CeDataSchemaHeader] = dataSchema;
427+
}
420428

421429
return context;
422430
}
@@ -463,7 +471,9 @@ private static DefaultHttpContext CreateBinaryModeContextWithRawHeaders(
463471
};
464472

465473
if (subject != null)
474+
{
466475
context.Request.Headers[Constants.CeSubjectHeader] = subject;
476+
}
467477

468478
return context;
469479
}

src/AzureEventGridSimulator.Tests/UnitTests/Common/TestHelpers.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,24 @@ public static HttpContext CreateCloudEventsBinaryModeContext(
6666
};
6767

6868
if (time != null)
69+
{
6970
context.Request.Headers[Constants.CeTimeHeader] = time;
71+
}
7072

7173
if (subject != null)
74+
{
7275
context.Request.Headers[Constants.CeSubjectHeader] = subject;
76+
}
7377

7478
if (dataContentType != null)
79+
{
7580
context.Request.Headers[Constants.CeDataContentTypeHeader] = dataContentType;
81+
}
7682

7783
if (dataSchema != null)
84+
{
7885
context.Request.Headers[Constants.CeDataSchemaHeader] = dataSchema;
86+
}
7987

8088
return context;
8189
}

src/AzureEventGridSimulator.Tests/UnitTests/Filtering/FilterSettingsValidationTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public void TestFilterSettingsValidationWithValidNumberOfAdvancedFilterSettings(
6060
AdvancedFilters = new List<AdvancedFilterSetting>(),
6161
};
6262
for (byte i = 0; i < n; i++)
63+
{
6364
filterConfig.AdvancedFilters.Add(GetValidAdvancedFilter());
65+
}
6466

6567
GetValidSimulatorSettings(filterConfig).Validate();
6668
});
@@ -75,7 +77,9 @@ public void TestFilterSettingsValidationWithTooManyAdvancedFilters()
7577
};
7678
// Azure Event Grid allows up to 25 filters, so 26 should fail
7779
for (var i = 0; i < 26; i++)
80+
{
7881
filterConfig.AdvancedFilters.Add(GetValidAdvancedFilter());
82+
}
7983

8084
var exception = Should.Throw<ArgumentException>(() =>
8185
GetValidSimulatorSettings(filterConfig).Validate()

src/AzureEventGridSimulator.Tests/UnitTests/Retry/DeadLetterServiceTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public void Dispose()
2727
{
2828
// Clean up temp folder
2929
if (Directory.Exists(_tempFolder))
30+
{
3031
Directory.Delete(_tempFolder, true);
32+
}
3133
}
3234

3335
private static PendingDelivery CreatePendingDelivery(

src/AzureEventGridSimulator.Tests/UnitTests/Retry/HttpEventDeliveryServiceTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public HttpEventDeliveryServiceTests()
3232
public void Dispose()
3333
{
3434
foreach (var client in _httpClients)
35+
{
3536
client.Dispose();
37+
}
3638

3739
_httpClients.Clear();
3840
}
@@ -158,7 +160,9 @@ public async Task GivenMultipleAttempts_WhenDelivering_ThenIncludesDeliveryCount
158160
var httpClientFactory = CreateMockHttpClientFactory(captureHeaders: headers =>
159161
{
160162
if (headers.TryGetValues(Constants.AegDeliveryCountHeader, out var values))
163+
{
161164
capturedDeliveryCount = values.FirstOrDefault();
165+
}
162166
});
163167
var service = new HttpEventDeliveryService(httpClientFactory, _formatterFactory, _logger);
164168
var delivery = CreatePendingDelivery();
@@ -298,7 +302,9 @@ CancellationToken cancellationToken
298302
_responseAction?.Invoke();
299303

300304
if (_exception != null)
305+
{
301306
throw _exception;
307+
}
302308

303309
var response = new HttpResponseMessage(_statusCode)
304310
{
@@ -315,7 +321,9 @@ protected override void Dispose(bool disposing)
315321
if (disposing)
316322
{
317323
foreach (var response in _responses)
324+
{
318325
response.Dispose();
326+
}
319327

320328
_responses.Clear();
321329
}

src/AzureEventGridSimulator.Tests/UnitTests/Retry/PendingDeliveryTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ private static PendingDelivery CreatePendingDelivery(
2121
RetryPolicySettings? retryPolicy = null;
2222

2323
if (retryEnabled.HasValue || ttlMinutes.HasValue || maxAttempts.HasValue)
24+
{
2425
retryPolicy = new RetryPolicySettings
2526
{
2627
Enabled = retryEnabled ?? true,
2728
EventTimeToLiveInMinutes = ttlMinutes ?? 1440,
2829
MaxDeliveryAttempts = maxAttempts ?? 30,
2930
};
31+
}
3032

3133
var subscriber = new HttpSubscriberSettings
3234
{

0 commit comments

Comments
 (0)