Skip to content

Commit

Permalink
Re-enable CA1305
Browse files Browse the repository at this point in the history
Fixes #34361
  • Loading branch information
pranavkm committed Aug 27, 2021
1 parent ff8358e commit 8644b58
Show file tree
Hide file tree
Showing 26 changed files with 66 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ dotnet_diagnostic.CA1018.severity = warning
dotnet_diagnostic.CA1047.severity = warning

# CA1305: Specify IFormatProvider
dotnet_diagnostic.CA1305.severity = suggestion
dotnet_diagnostic.CA1305.severity = warning

# CA1507: Use nameof to express symbol names
dotnet_diagnostic.CA1507.severity = warning
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Components/Web.JS/dist/Release/blazor.webview.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/Components/test/E2ETest/Tests/RoutingTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Runtime.InteropServices;
using BasicTestApp;
using BasicTestApp.RouterTest;
Expand Down Expand Up @@ -810,9 +811,9 @@ public void CanArriveAtQueryStringPageWithDateTimeQuery()
var app = Browser.MountTestComponent<TestRouter>();
Assert.Equal("Hello Abc .", app.FindElement(By.Id("test-info")).Text);
Assert.Equal("0", app.FindElement(By.Id("value-QueryInt")).Text);
Assert.Equal(dateTime.ToString("hh:mm:ss on yyyy-MM-dd"), app.FindElement(By.Id("value-NullableDateTimeValue")).Text);
Assert.Equal(dateOnly.ToString("yyyy-MM-dd"), app.FindElement(By.Id("value-NullableDateOnlyValue")).Text);
Assert.Equal(timeOnly.ToString("hh:mm:ss"), app.FindElement(By.Id("value-NullableTimeOnlyValue")).Text);
Assert.Equal(dateTime.ToString("hh:mm:ss on yyyy-MM-dd", CultureInfo.InvariantCulture), app.FindElement(By.Id("value-NullableDateTimeValue")).Text);
Assert.Equal(dateOnly.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), app.FindElement(By.Id("value-NullableDateOnlyValue")).Text);
Assert.Equal(timeOnly.ToString("hh:mm:ss", CultureInfo.InvariantCulture), app.FindElement(By.Id("value-NullableTimeOnlyValue")).Text);
Assert.Equal(string.Empty, app.FindElement(By.Id("value-StringValue")).Text);
Assert.Equal("0 values ()", app.FindElement(By.Id("value-LongValues")).Text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public string Delete()
var result = new StringBuilder();
foreach (var header in Request.Headers)
{
result.AppendLine($"{header.Key}: {string.Join(",", header.Value.ToArray())}");
result.AppendLine(FormattableString.Invariant($"{header.Key}: {string.Join(",", header.Value.ToArray())}"));
}
return "REQUEST HEADERS:\n" + result.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public override string ToString()
if (_formatted == null)
{
var builder = new StringBuilder();
builder.AppendLine($"Health check data for {_name}:");
builder.AppendLine(FormattableString.Invariant($"Health check data for {_name}:"));

var values = _values;
for (var i = 0; i < values.Count; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,29 @@ private async Task RunScriptAsync(string serverAction)
}

var parameterBuilder = new StringBuilder();
parameterBuilder.Append($"\"{remotePSSessionHelperScript}\"");
parameterBuilder.Append($" -serverName {_deploymentParameters.ServerName}");
parameterBuilder.Append($" -accountName {_deploymentParameters.ServerAccountName}");
parameterBuilder.Append($" -accountPassword {_deploymentParameters.ServerAccountPassword}");
parameterBuilder.Append($" -deployedFolderPath {_deployedFolderPathInFileShare}");
parameterBuilder.Append(FormattableString.Invariant($"\"{remotePSSessionHelperScript}\""));
parameterBuilder.Append(FormattableString.Invariant($" -serverName {_deploymentParameters.ServerName}"));
parameterBuilder.Append(FormattableString.Invariant($" -accountName {_deploymentParameters.ServerAccountName}"));
parameterBuilder.Append(FormattableString.Invariant($" -accountPassword {_deploymentParameters.ServerAccountPassword}"));
parameterBuilder.Append(FormattableString.Invariant($" -deployedFolderPath {_deployedFolderPathInFileShare}"));

if (!string.IsNullOrEmpty(_deploymentParameters.DotnetRuntimePath))
{
parameterBuilder.Append($" -dotnetRuntimePath \"{_deploymentParameters.DotnetRuntimePath}\"");
parameterBuilder.Append(FormattableString.Invariant($" -dotnetRuntimePath \"{_deploymentParameters.DotnetRuntimePath}\""));
}

parameterBuilder.Append($" -executablePath \"{executablePath}\"");
parameterBuilder.Append(FormattableString.Invariant($" -executablePath \"{executablePath}\""));

if (!string.IsNullOrEmpty(executableParameters))
{
parameterBuilder.Append($" -executableParameters \"{executableParameters}\"");
parameterBuilder.Append(FormattableString.Invariant($" -executableParameters \"{executableParameters}\""));
}

parameterBuilder.Append($" -serverType {_deploymentParameters.ServerType}");
parameterBuilder.Append($" -serverAction {serverAction}");
parameterBuilder.Append($" -applicationBaseUrl {_deploymentParameters.ApplicationBaseUriHint}");
parameterBuilder.Append(FormattableString.Invariant($" -serverType {_deploymentParameters.ServerType}"));
parameterBuilder.Append(FormattableString.Invariant($" -serverAction {serverAction}"));
parameterBuilder.Append(FormattableString.Invariant($" -applicationBaseUrl {_deploymentParameters.ApplicationBaseUriHint}"));
var environmentVariables = string.Join("`,", _deploymentParameters.EnvironmentVariables.Select(envVariable => $"{envVariable.Key}={envVariable.Value}"));
parameterBuilder.Append($" -environmentVariables \"{environmentVariables}\"");
parameterBuilder.Append(FormattableString.Invariant($" -environmentVariables \"{environmentVariables}\""));

var startInfo = new ProcessStartInfo
{
Expand Down
16 changes: 9 additions & 7 deletions src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,17 +1211,19 @@ private static void SetPlaintextContentType(HttpContext httpContext)
private static string BuildErrorMessageForMultipleBodyParameters(FactoryContext factoryContext)
{
var errorMessage = new StringBuilder();
errorMessage.Append($"Failure to infer one or more parameters.\n");
errorMessage.Append("Below is the list of parameters that we found: \n\n");
errorMessage.Append($"{"Parameter",-20}|{"Source",-30} \n");
errorMessage.Append("---------------------------------------------------------------------------------\n");
errorMessage.AppendLine("Failure to infer one or more parameters.");
errorMessage.AppendLine("Below is the list of parameters that we found: ");
errorMessage.AppendLine();
errorMessage.AppendLine(FormattableString.Invariant($"{"Parameter",-20}|{"Source",-30}"));
errorMessage.AppendLine("---------------------------------------------------------------------------------\n");

foreach (var kv in factoryContext.TrackedParameters)
{
errorMessage.Append($"{kv.Key,-19} | {kv.Value,-15}\n");
errorMessage.AppendLine(FormattableString.Invariant($"{kv.Key,-19} | {kv.Value,-15}"));
}
errorMessage.Append("\n\n");
errorMessage.Append("Did you mean to register the \"UNKNOWN\" parameters as a Service?\n\n");
errorMessage.AppendLine().AppendLine();
errorMessage.AppendLine("Did you mean to register the \"UNKNOWN\" parameters as a Service?")
.AppendLine();
return errorMessage.ToString();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ public async Task BindAsyncWithBodyArgument()
httpContext.Request.Body = stream;

httpContext.Request.Headers["Content-Type"] = "application/json";
httpContext.Request.Headers["Content-Length"] = stream.Length.ToString();
httpContext.Request.Headers["Content-Length"] = stream.Length.ToString(CultureInfo.InvariantCulture);
httpContext.Features.Set<IHttpRequestBodyDetectionFeature>(new RequestBodyDetectionFeature(true));

var jsonOptions = new JsonOptions();
Expand Down Expand Up @@ -974,7 +974,7 @@ public async Task BindAsyncRunsBeforeBodyBinding()
httpContext.Request.Body = stream;

httpContext.Request.Headers["Content-Type"] = "application/json";
httpContext.Request.Headers["Content-Length"] = stream.Length.ToString();
httpContext.Request.Headers["Content-Length"] = stream.Length.ToString(CultureInfo.InvariantCulture);
httpContext.Features.Set<IHttpRequestBodyDetectionFeature>(new RequestBodyDetectionFeature(true));

var jsonOptions = new JsonOptions();
Expand Down Expand Up @@ -1118,7 +1118,7 @@ public async Task RequestDelegatePopulatesFromBodyParameter(Delegate action)
httpContext.Request.Body = stream;

httpContext.Request.Headers["Content-Type"] = "application/json";
httpContext.Request.Headers["Content-Length"] = stream.Length.ToString();
httpContext.Request.Headers["Content-Length"] = stream.Length.ToString(CultureInfo.InvariantCulture);
httpContext.Features.Set<IHttpRequestBodyDetectionFeature>(new RequestBodyDetectionFeature(true));

var jsonOptions = new JsonOptions();
Expand Down Expand Up @@ -2558,7 +2558,7 @@ internal static class TestExtensionResults
{
public static IResult TestResult(this IResultExtensions resultExtensions, string name)
{
return Results.Ok($"Hello {name}. This is from an extension method.");
return Results.Ok(FormattableString.Invariant($"Hello {name}. This is from an extension method."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ private protected void Validate(HttpContext httpContext, Endpoint expected, Endp
if (!object.ReferenceEquals(expected, actual))
{
var message = new StringBuilder();
message.AppendLine($"Validation failed for request {Array.IndexOf(Requests, httpContext)}");
message.AppendLine($"{httpContext.Request.Method} {httpContext.Request.Path}");
message.AppendLine($"expected: '{((RouteEndpoint)expected)?.DisplayName ?? "null"}'");
message.AppendLine($"actual: '{((RouteEndpoint)actual)?.DisplayName ?? "null"}'");
message.AppendLine(FormattableString.Invariant($"Validation failed for request {Array.IndexOf(Requests, httpContext)}"));
message.AppendLine(FormattableString.Invariant($"{httpContext.Request.Method} {httpContext.Request.Path}"));
message.AppendLine(FormattableString.Invariant($"expected: '{((RouteEndpoint)expected)?.DisplayName ?? "null"}'"));
message.AppendLine(FormattableString.Invariant($"actual: '{((RouteEndpoint)actual)?.DisplayName ?? "null"}'"));
throw new InvalidOperationException(message.ToString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Configure(IApplicationBuilder app)
sb.AppendLine("Endpoints:");
foreach (var endpoint in dataSource.Endpoints.OfType<RouteEndpoint>().OrderBy(e => e.RoutePattern.RawText, StringComparer.OrdinalIgnoreCase))
{
sb.AppendLine($"- {endpoint.RoutePattern.RawText}");
sb.AppendLine(FormattableString.Invariant($"- {endpoint.RoutePattern.RawText}"));
foreach (var metadata in endpoint.Metadata)
{
sb.AppendLine(" " + metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Configure(IApplicationBuilder app)
sb.AppendLine("Endpoints:");
foreach (var endpoint in dataSource.Endpoints.OfType<RouteEndpoint>().OrderBy(e => e.RoutePattern.RawText, StringComparer.OrdinalIgnoreCase))
{
sb.AppendLine($"- {endpoint.RoutePattern.RawText}");
sb.AppendLine(FormattableString.Invariant($"- {endpoint.RoutePattern.RawText}"));
}
var response = httpContext.Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private Task DisplayException(ErrorContext errorContext)
sb.AppendLine("=======");
foreach (var pair in httpContext.Request.Headers)
{
sb.AppendLine($"{pair.Key}: {pair.Value}");
sb.AppendLine(FormattableString.Invariant($"{pair.Key}: {pair.Value}"));
}

return httpContext.Response.WriteAsync(sb.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ private Socket SendSocketRequestAsync(string address, string path, string method
{
var uri = new Uri(address);
var builder = new StringBuilder();
builder.Append($"{method} {path} HTTP/1.1\r\n");
builder.Append($"HOST: {uri.Authority}\r\n\r\n");
builder.Append(FormattableString.Invariant($"{method} {path} HTTP/1.1\r\n"));
builder.Append(FormattableString.Invariant($"HOST: {uri.Authority}\r\n\r\n"));

byte[] request = Encoding.ASCII.GetBytes(builder.ToString());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -53,25 +53,25 @@ internal void Verify(AutobahnServerResult serverResult, StringBuilder failures)
case Expectation.Fail:
if (!caseResult.BehaviorIs("FAILED"))
{
failures.AppendLine($"Case {serverResult.Name}:{caseResult.Name}. Expected 'FAILED', but got '{caseResult.ActualBehavior}'");
failures.AppendLine(FormattableString.Invariant($"Case {serverResult.Name}:{caseResult.Name}. Expected 'FAILED', but got '{caseResult.ActualBehavior}'"));
}
break;
case Expectation.NonStrict:
if (!caseResult.BehaviorIs("NON-STRICT"))
{
failures.AppendLine($"Case {serverResult.Name}:{caseResult.Name}. Expected 'NON-STRICT', but got '{caseResult.ActualBehavior}'");
failures.AppendLine(FormattableString.Invariant($"Case {serverResult.Name}:{caseResult.Name}. Expected 'NON-STRICT', but got '{caseResult.ActualBehavior}'"));
}
break;
case Expectation.Ok:
if (!caseResult.BehaviorIs("NON-STRICT") && !caseResult.BehaviorIs("OK"))
{
failures.AppendLine($"Case {serverResult.Name}:{caseResult.Name}. Expected 'NON-STRICT' or 'OK', but got '{caseResult.ActualBehavior}'");
failures.AppendLine(FormattableString.Invariant($"Case {serverResult.Name}:{caseResult.Name}. Expected 'NON-STRICT' or 'OK', but got '{caseResult.ActualBehavior}'"));
}
break;
case Expectation.OkOrFail:
if (!caseResult.BehaviorIs("NON-STRICT") && !caseResult.BehaviorIs("FAILED") && !caseResult.BehaviorIs("OK"))
{
failures.AppendLine($"Case {serverResult.Name}:{caseResult.Name}. Expected 'FAILED', 'NON-STRICT' or 'OK', but got '{caseResult.ActualBehavior}'");
failures.AppendLine(FormattableString.Invariant($"Case {serverResult.Name}:{caseResult.Name}. Expected 'FAILED', 'NON-STRICT' or 'OK', but got '{caseResult.ActualBehavior}'"));
}
break;
default:
Expand All @@ -81,4 +81,4 @@ internal void Verify(AutobahnServerResult serverResult, StringBuilder failures)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void Verify(AutobahnResult result)
var serverExpectation = _expectations.FirstOrDefault(e => e.Server == serverResult.Server && e.Ssl == serverResult.Ssl);
if (serverExpectation == null)
{
failures.AppendLine($"Expected no results for server: {serverResult.Name} but found results!");
failures.AppendLine(FormattableString.Invariant($"Expected no results for server: {serverResult.Name} but found results!"));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mvc/Mvc.Core/src/MvcCoreLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,11 @@ public static void ExecutingAction(this ILogger logger, ActionDescriptor action)
{
if (i == routeValues.Length - 1)
{
stringBuilder.Append($"{routeKeys[i]} = \"{routeValues[i]}\"");
stringBuilder.Append(FormattableString.Invariant($"{routeKeys[i]} = \"{routeValues[i]}\""));
}
else
{
stringBuilder.Append($"{routeKeys[i]} = \"{routeValues[i]}\", ");
stringBuilder.Append(FormattableString.Invariant($"{routeKeys[i]} = \"{routeValues[i]}\", "));
}
}
stringBuilder.Append('}');
Expand Down
2 changes: 1 addition & 1 deletion src/Security/Authentication/Twitter/src/TwitterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private async Task EnsureTwitterRequestSuccess(HttpResponseMessage response)
foreach (var error in errorResponse.Errors)
{
errorMessageStringBuilder.Append(Environment.NewLine);
errorMessageStringBuilder.Append($"Code: {error.Code}, Message: '{error.Message}'");
errorMessageStringBuilder.Append(FormattableString.Invariant($"Code: {error.Code}, Message: '{error.Message}'"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private async Task<string> SendSocketRequestAsync(string address, string path, s
{
var uri = new Uri(address);
StringBuilder builder = new StringBuilder();
builder.AppendLine($"{method} {path} HTTP/1.1");
builder.AppendLine(FormattableString.Invariant($"{method} {path} HTTP/1.1"));
builder.AppendLine("Connection: close");
builder.Append("HOST: ");
builder.AppendLine(uri.Authority);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -329,7 +330,7 @@ public async Task LogsContainTimestampAndPID()
var processIdPattern = new Regex("Process Id: (\\d+)\\.", RegexOptions.Singleline);
var processIdMatch = processIdPattern.Match(aspnetcorev2Log.Message);
Assert.True(processIdMatch.Success, $"'{processIdPattern}' did not match '{aspnetcorev2Log}'");
var processId = int.Parse(processIdMatch.Groups[1].Value);
var processId = int.Parse(processIdMatch.Groups[1].Value, CultureInfo.InvariantCulture);

if (DeployerSelector.HasNewShim)
{
Expand Down Expand Up @@ -365,8 +366,8 @@ private static void AssertTimestampAndPIDPrefix(int processId, string log)
var prefixMatch = prefixPattern.Match(log);
Assert.True(prefixMatch.Success, $"'{prefixPattern}' did not match '{log}'");

var time = DateTime.Parse(prefixMatch.Groups[1].Value).ToUniversalTime();
var prefixProcessId = int.Parse(prefixMatch.Groups[2].Value);
var time = DateTime.Parse(prefixMatch.Groups[1].Value, CultureInfo.InvariantCulture).ToUniversalTime();
var prefixProcessId = int.Parse(prefixMatch.Groups[2].Value, CultureInfo.InvariantCulture);

Assert.Equal(processId, prefixProcessId);

Expand Down
Loading

0 comments on commit 8644b58

Please sign in to comment.