Skip to content

Commit c6f1ace

Browse files
authored
[BEEEP] Fix all CA2254 occurrences (#6357)
* Fix all CA2254 occurrences * Fix tests
1 parent 43779cf commit c6f1ace

21 files changed

Lines changed: 45 additions & 35 deletions

File tree

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,12 @@ csharp_style_namespace_declarations = file_scoped:warning
123123
# Switch expression
124124
dotnet_diagnostic.CS8509.severity = error # missing switch case for named enum value
125125
dotnet_diagnostic.CS8524.severity = none # missing switch case for unnamed enum value
126+
127+
# CA2253: Named placeholders should nto be numeric values
128+
dotnet_diagnostic.CA2253.severity = suggestion
129+
130+
# CA2254: Template should be a static expression
131+
dotnet_diagnostic.CA2254.severity = warning
132+
133+
# CA1727: Use PascalCase for named placeholders
134+
dotnet_diagnostic.CA1727.severity = suggestion

bitwarden_license/src/Sso/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ public void Configure(
157157
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
158158

159159
// Log startup
160-
logger.LogInformation(Constants.BypassFiltersEventId, globalSettings.ProjectName + " started.");
160+
logger.LogInformation(Constants.BypassFiltersEventId, "{Project} started.", globalSettings.ProjectName);
161161
}
162162
}

bitwarden_license/test/Scim.Test/Groups/PatchGroupCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public async Task PatchGroup_InvalidOperation_Success(SutProvider<PatchGroupComm
436436
await sutProvider.GetDependency<IGroupService>().DidNotReceiveWithAnyArgs().DeleteUserAsync(default, default);
437437

438438
// Assert: logging
439-
sutProvider.GetDependency<ILogger<PatchGroupCommand>>().ReceivedWithAnyArgs().LogWarning(default);
439+
sutProvider.GetDependency<ILogger<PatchGroupCommand>>().ReceivedWithAnyArgs().LogWarning("");
440440
}
441441

442442
[Theory]

src/Admin/Controllers/HomeController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task<IActionResult> GetLatestVersion(ProjectType project, Cancellat
6161
}
6262
catch (HttpRequestException e)
6363
{
64-
_logger.LogError(e, $"Error encountered while sending GET request to {requestUri}");
64+
_logger.LogError(e, "Error encountered while sending GET request to {RequestUri}", requestUri);
6565
return new JsonResult("Unable to fetch latest version") { StatusCode = StatusCodes.Status500InternalServerError };
6666
}
6767

@@ -83,7 +83,7 @@ public async Task<IActionResult> GetInstalledWebVersion(CancellationToken cancel
8383
}
8484
catch (HttpRequestException e)
8585
{
86-
_logger.LogError(e, $"Error encountered while sending GET request to {requestUri}");
86+
_logger.LogError(e, "Error encountered while sending GET request to {RequestUri}", requestUri);
8787
return new JsonResult("Unable to fetch installed version") { StatusCode = StatusCodes.Status500InternalServerError };
8888
}
8989

src/Admin/Jobs/AliveJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected async override Task ExecuteJobAsync(IJobExecutionContext context)
2222
{
2323
_logger.LogInformation(Constants.BypassFiltersEventId, "Execute job task: Keep alive");
2424
var response = await _httpClient.GetAsync(_globalSettings.BaseServiceUri.Admin);
25-
_logger.LogInformation(Constants.BypassFiltersEventId, "Finished job task: Keep alive, " +
25+
_logger.LogInformation(Constants.BypassFiltersEventId, "Finished job task: Keep alive, {StatusCode}",
2626
response.StatusCode);
2727
}
2828
}

src/Api/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,6 @@ public void Configure(
326326
}
327327

328328
// Log startup
329-
logger.LogInformation(Constants.BypassFiltersEventId, globalSettings.ProjectName + " started.");
329+
logger.LogInformation(Constants.BypassFiltersEventId, "{Project} started.", globalSettings.ProjectName);
330330
}
331331
}

src/Api/Tools/Controllers/SendsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public async Task<ObjectResult> AzureValidateFile()
166166
}
167167
catch (Exception e)
168168
{
169-
_logger.LogError(e, $"Uncaught exception occurred while handling event grid event: {JsonSerializer.Serialize(eventGridEvent)}");
169+
_logger.LogError(e, "Uncaught exception occurred while handling event grid event: {Event}", JsonSerializer.Serialize(eventGridEvent));
170170
return;
171171
}
172172
}

src/Api/Utilities/ExceptionHandlerFilterAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public override void OnException(ExceptionContext context)
152152
else
153153
{
154154
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<ExceptionHandlerFilterAttribute>>();
155-
logger.LogError(0, exception, exception.Message);
155+
logger.LogError(0, exception, "Unhandled exception");
156156
errorMessage = "An unhandled server error has occurred.";
157157
context.HttpContext.Response.StatusCode = 500;
158158
}

src/Api/Vault/Controllers/CiphersController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ public async Task<ObjectResult> AzureValidateFile()
15931593
}
15941594
catch (Exception e)
15951595
{
1596-
_logger.LogError(e, $"Uncaught exception occurred while handling event grid event: {JsonSerializer.Serialize(eventGridEvent)}");
1596+
_logger.LogError(e, "Uncaught exception occurred while handling event grid event: {Event}", JsonSerializer.Serialize(eventGridEvent));
15971597
return;
15981598
}
15991599
}

src/Core/AdminConsole/OrganizationAuth/UpdateOrganizationAuthRequestCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public async Task UpdateAsync(Guid organizationId, IEnumerable<OrganizationAuthR
8989
AuthRequestExpiresAfter = _globalSettings.PasswordlessAuth.AdminRequestExpiration
9090
}
9191
);
92-
processor.Process((Exception e) => _logger.LogError(e.Message));
92+
processor.Process((Exception e) => _logger.LogError("Error processing organization auth request: {Message}", e.Message));
9393
await processor.Save((IEnumerable<OrganizationAdminAuthRequest> authRequests) => _authRequestRepository.UpdateManyAsync(authRequests));
9494
await processor.SendPushNotifications((ar) => _pushNotificationService.PushAuthRequestResponseAsync(ar));
9595
await processor.SendApprovalEmailsForProcessedRequests(SendApprovalEmail);
@@ -114,7 +114,7 @@ async Task SendApprovalEmail<T>(T authRequest, string identifier) where T : Auth
114114
// This should be impossible
115115
if (user == null)
116116
{
117-
_logger.LogError($"User {authRequest.UserId} not found. Trusted device admin approval email not sent.");
117+
_logger.LogError("User {UserId} not found. Trusted device admin approval email not sent.", authRequest.UserId);
118118
return;
119119
}
120120

0 commit comments

Comments
 (0)