diff --git a/.editorconfig b/.editorconfig index d4088b6adfd4..4682cf58b9d9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -233,6 +233,9 @@ dotnet_diagnostic.IDE0055.severity = warning # IDE0059: Unnecessary assignment to a value dotnet_diagnostic.IDE0059.severity = warning +# IDE0062: Make local function static +dotnet_diagnostic.IDE0062.severity = warning + # IDE0073: File header dotnet_diagnostic.IDE0073.severity = warning file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license. @@ -285,6 +288,8 @@ dotnet_diagnostic.IDE0044.severity = suggestion dotnet_diagnostic.IDE0051.severity = suggestion # IDE0059: Unnecessary assignment to a value dotnet_diagnostic.IDE0059.severity = suggestion +# IDE0062: Make local function static +dotnet_diagnostic.IDE0062.severity = suggestion # CA2016: Forward the 'CancellationToken' parameter to methods that take one dotnet_diagnostic.CA2016.severity = suggestion @@ -298,6 +303,8 @@ dotnet_diagnostic.CA1822.severity = silent dotnet_diagnostic.IDE0011.severity = silent # IDE0055: Fix formatting dotnet_diagnostic.IDE0055.severity = silent +# IDE0062: Make local function static +dotnet_diagnostic.IDE0062.severity = silent # IDE0161: Convert to file-scoped namespace dotnet_diagnostic.IDE0161.severity = silent diff --git a/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/AzureAdB2CAuthenticationBuilderExtensions.cs b/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/AzureAdB2CAuthenticationBuilderExtensions.cs index 3778a3ed1f10..75768be52809 100644 --- a/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/AzureAdB2CAuthenticationBuilderExtensions.cs +++ b/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/AzureAdB2CAuthenticationBuilderExtensions.cs @@ -207,7 +207,7 @@ private static void AddAdditionalMvcApplicationParts(IServiceCollection services apm.FeatureProviders.Add(new AzureADB2CAccountControllerFeatureProvider()); }); - bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal); + static bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal); } private static IEnumerable GetAdditionalParts() diff --git a/src/Hosting/Hosting/src/WebHostBuilder.cs b/src/Hosting/Hosting/src/WebHostBuilder.cs index 439390721a29..0fb6538653aa 100644 --- a/src/Hosting/Hosting/src/WebHostBuilder.cs +++ b/src/Hosting/Hosting/src/WebHostBuilder.cs @@ -198,12 +198,12 @@ public IWebHost Build() throw; } - IServiceProvider GetProviderFromFactory(IServiceCollection collection) + static IServiceProvider GetProviderFromFactory(IServiceCollection collection) { var provider = collection.BuildServiceProvider(); var factory = provider.GetService>(); - if (factory != null && !(factory is DefaultServiceProviderFactory)) + if (factory != null && factory is not DefaultServiceProviderFactory) { using (provider) { diff --git a/src/Http/Routing/src/CompositeEndpointDataSource.cs b/src/Http/Routing/src/CompositeEndpointDataSource.cs index 56af7bbdf44f..96a4121f150f 100644 --- a/src/Http/Routing/src/CompositeEndpointDataSource.cs +++ b/src/Http/Routing/src/CompositeEndpointDataSource.cs @@ -205,7 +205,7 @@ private string DebuggerDisplayString } return sb.ToString(); - IEnumerable FormatValues(IEnumerable> values) + static IEnumerable FormatValues(IEnumerable> values) { return values.Select( kvp => diff --git a/src/Http/Routing/src/EndpointNameAddressScheme.cs b/src/Http/Routing/src/EndpointNameAddressScheme.cs index 25af62ef65bc..6cfa2fa40f8e 100644 --- a/src/Http/Routing/src/EndpointNameAddressScheme.cs +++ b/src/Http/Routing/src/EndpointNameAddressScheme.cs @@ -89,7 +89,7 @@ private static Dictionary Initialize(IReadOnlyList throw new InvalidOperationException(builder.ToString()); - string? GetEndpointName(Endpoint endpoint) + static string? GetEndpointName(Endpoint endpoint) { if (endpoint.Metadata.GetMetadata()?.SuppressLinkGeneration == true) { diff --git a/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs b/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs index 47e98cf065fa..423003064502 100644 --- a/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs +++ b/src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs @@ -308,7 +308,7 @@ public IReadOnlyList GetEdges(IReadOnlyList endpoints) return policyNodeEdges; - (IReadOnlyList httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e) + static (IReadOnlyList httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e) { var metadata = e.Metadata.GetMetadata(); return metadata == null ? (Array.Empty(), false) : (metadata.HttpMethods, metadata.AcceptCorsPreflight); diff --git a/src/Identity/ApiAuthorization.IdentityServer/src/Authentication/AuthenticationBuilderExtensions.cs b/src/Identity/ApiAuthorization.IdentityServer/src/Authentication/AuthenticationBuilderExtensions.cs index 1d2f1b256425..0647f9ae27b3 100644 --- a/src/Identity/ApiAuthorization.IdentityServer/src/Authentication/AuthenticationBuilderExtensions.cs +++ b/src/Identity/ApiAuthorization.IdentityServer/src/Authentication/AuthenticationBuilderExtensions.cs @@ -47,7 +47,7 @@ public static AuthenticationBuilder AddIdentityServerJwt(this AuthenticationBuil return builder; - IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProvider sp) + static IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProvider sp) { var schemeName = IdentityServerJwtConstants.IdentityServerJwtBearerScheme; @@ -58,5 +58,4 @@ IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProv return new IdentityServerJwtBearerOptionsConfiguration(schemeName, apiName, localApiDescriptor); } } - } diff --git a/src/Middleware/Rewrite/src/ApacheModRewrite/FileParser.cs b/src/Middleware/Rewrite/src/ApacheModRewrite/FileParser.cs index 3fbadb2bc692..5eade69cdb6e 100644 --- a/src/Middleware/Rewrite/src/ApacheModRewrite/FileParser.cs +++ b/src/Middleware/Rewrite/src/ApacheModRewrite/FileParser.cs @@ -13,11 +13,7 @@ public static IList Parse(TextReader input) var lineNum = 0; // parsers - var testStringParser = new TestStringParser(); - var conditionParser = new ConditionPatternParser(); - var regexParser = new RuleRegexParser(); var flagsParser = new FlagParser(); - var tokenizer = new Tokenizer(); while ((line = input.ReadLine()) != null) { diff --git a/src/Middleware/Spa/SpaProxy/src/SpaProxyMiddleware.cs b/src/Middleware/Spa/SpaProxy/src/SpaProxyMiddleware.cs index 5110875bb176..8be0e72dcdac 100644 --- a/src/Middleware/Spa/SpaProxy/src/SpaProxyMiddleware.cs +++ b/src/Middleware/Spa/SpaProxy/src/SpaProxyMiddleware.cs @@ -68,7 +68,7 @@ private async Task InvokeCore(HttpContext context) context.Response.Redirect(_options.Value.ServerUrl); } - string GenerateSpaLaunchPage(SpaDevelopmentServerOptions options) + static string GenerateSpaLaunchPage(SpaDevelopmentServerOptions options) { return $@" diff --git a/src/Mvc/Mvc.Core/src/ApplicationModels/ApiBehaviorApplicationModelProvider.cs b/src/Mvc/Mvc.Core/src/ApplicationModels/ApiBehaviorApplicationModelProvider.cs index 6c5791dfca21..496187323817 100644 --- a/src/Mvc/Mvc.Core/src/ApplicationModels/ApiBehaviorApplicationModelProvider.cs +++ b/src/Mvc/Mvc.Core/src/ApplicationModels/ApiBehaviorApplicationModelProvider.cs @@ -97,7 +97,7 @@ private static void EnsureActionIsAttributeRouted(ActionModel actionModel) throw new InvalidOperationException(message); } - bool IsAttributeRouted(IList selectorModel) + static bool IsAttributeRouted(IList selectorModel) { for (var i = 0; i < selectorModel.Count; i++) { diff --git a/src/Mvc/Mvc.Core/src/Routing/ActionConstraintMatcherPolicy.cs b/src/Mvc/Mvc.Core/src/Routing/ActionConstraintMatcherPolicy.cs index c7a215c752d4..502a04031615 100644 --- a/src/Mvc/Mvc.Core/src/Routing/ActionConstraintMatcherPolicy.cs +++ b/src/Mvc/Mvc.Core/src/Routing/ActionConstraintMatcherPolicy.cs @@ -54,7 +54,7 @@ public bool AppliesToEndpoints(IReadOnlyList endpoints) return false; - bool HasSignificantActionConstraint(IList constraints) + static bool HasSignificantActionConstraint(IList constraints) { for (var i = 0; i < constraints.Count; i++) { diff --git a/src/Mvc/Mvc.RazorPages/src/ApplicationModels/CompiledPageRouteModelProvider.cs b/src/Mvc/Mvc.RazorPages/src/ApplicationModels/CompiledPageRouteModelProvider.cs index b34c92abfb9c..808b4216283a 100644 --- a/src/Mvc/Mvc.RazorPages/src/ApplicationModels/CompiledPageRouteModelProvider.cs +++ b/src/Mvc/Mvc.RazorPages/src/ApplicationModels/CompiledPageRouteModelProvider.cs @@ -73,7 +73,7 @@ private IEnumerable GetViewDescriptors(ApplicationPartMa } } - bool IsRazorPage(CompiledViewDescriptor viewDescriptor) + static bool IsRazorPage(CompiledViewDescriptor viewDescriptor) { if (viewDescriptor.Item != null) { diff --git a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs index f56f3bae6365..f5171c2c32fb 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs @@ -71,7 +71,7 @@ private Task InitializeStandardComponentServicesAsync(HttpContext httpContext) return _initialized; - async Task InitializeCore(HttpContext httpContext) + static async Task InitializeCore(HttpContext httpContext) { var navigationManager = (IHostEnvironmentNavigationManager)httpContext.RequestServices.GetRequiredService(); navigationManager?.Initialize(GetContextBaseUri(httpContext.Request), GetFullUri(httpContext.Request)); diff --git a/src/Servers/Kestrel/shared/KnownHeaders.cs b/src/Servers/Kestrel/shared/KnownHeaders.cs index ed3f1bd18898..0f104f305672 100644 --- a/src/Servers/Kestrel/shared/KnownHeaders.cs +++ b/src/Servers/Kestrel/shared/KnownHeaders.cs @@ -380,7 +380,7 @@ static string AppendSwitchSection(int length, IList values) firstTermVar = ""; } - string GenerateIfBody(KnownHeader header, string extraIndent = "") + static string GenerateIfBody(KnownHeader header, string extraIndent = "") { if (header.Name == HeaderNames.ContentLength) { diff --git a/src/Servers/Kestrel/stress/Program.cs b/src/Servers/Kestrel/stress/Program.cs index e0a44a25356c..b0b9f02d6366 100644 --- a/src/Servers/Kestrel/stress/Program.cs +++ b/src/Servers/Kestrel/stress/Program.cs @@ -620,7 +620,7 @@ public ClientContext(HttpClient httpClient, int taskNum, int seed) HttpClient = httpClient; // deterministic hashing copied from System.Runtime.Hashing - int Combine(int h1, int h2) + static int Combine(int h1, int h2) { uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); return ((int)rol5 + h1) ^ h2; diff --git a/src/Shared/BrowserTesting/src/PageInformation.cs b/src/Shared/BrowserTesting/src/PageInformation.cs index 7cd9a2c68e21..b993dd92d29e 100644 --- a/src/Shared/BrowserTesting/src/PageInformation.cs +++ b/src/Shared/BrowserTesting/src/PageInformation.cs @@ -98,11 +98,7 @@ private void RecordConsoleMessage(object sender, IConsoleMessage message) var logMessage = $"[{_page.Url}]{Environment.NewLine} {messageText}{Environment.NewLine} ({location})"; - _logger.Log(MapLogLevel(message.Type), logMessage); - - BrowserConsoleLogs.Add(new LogEntry(messageText, message.Type)); - - LogLevel MapLogLevel(string messageType) => messageType switch + var logLevel = message.Type switch { "info" => LogLevel.Information, "verbose" => LogLevel.Debug, @@ -110,6 +106,9 @@ private void RecordConsoleMessage(object sender, IConsoleMessage message) "error" => LogLevel.Error, _ => LogLevel.Information }; + _logger.Log(logLevel, logMessage); + + BrowserConsoleLogs.Add(new LogEntry(messageText, message.Type)); } catch { diff --git a/src/SignalR/common/Shared/PipeWriterStream.cs b/src/SignalR/common/Shared/PipeWriterStream.cs index 6f65beabfee8..ee37bec55657 100644 --- a/src/SignalR/common/Shared/PipeWriterStream.cs +++ b/src/SignalR/common/Shared/PipeWriterStream.cs @@ -89,7 +89,7 @@ private ValueTask WriteCoreAsync(ReadOnlyMemory source, CancellationToken return default; - async ValueTask WriteSlowAsync(ValueTask flushTask) + static async ValueTask WriteSlowAsync(ValueTask flushTask) { var flushResult = await flushTask;