Browse Source

Enable warnings for IDE0062 (#39463)

Contributes to https://github.com/dotnet/aspnetcore/issues/24055
Pranav K 4 years ago
parent
commit
07d728b517

+ 7 - 0
.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
 

+ 1 - 1
src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/AzureAdB2CAuthenticationBuilderExtensions.cs

@@ -207,7 +207,7 @@ public static class AzureADB2CAuthenticationBuilderExtensions
                 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<ApplicationPart> GetAdditionalParts()

+ 2 - 2
src/Hosting/Hosting/src/WebHostBuilder.cs

@@ -198,12 +198,12 @@ public class WebHostBuilder : IWebHostBuilder
             throw;
         }
 
-        IServiceProvider GetProviderFromFactory(IServiceCollection collection)
+        static IServiceProvider GetProviderFromFactory(IServiceCollection collection)
         {
             var provider = collection.BuildServiceProvider();
             var factory = provider.GetService<IServiceProviderFactory<IServiceCollection>>();
 
-            if (factory != null && !(factory is DefaultServiceProviderFactory))
+            if (factory != null && factory is not DefaultServiceProviderFactory)
             {
                 using (provider)
                 {

+ 1 - 1
src/Http/Routing/src/CompositeEndpointDataSource.cs

@@ -205,7 +205,7 @@ public sealed class CompositeEndpointDataSource : EndpointDataSource
             }
             return sb.ToString();
 
-            IEnumerable<string> FormatValues(IEnumerable<KeyValuePair<string, object?>> values)
+            static IEnumerable<string> FormatValues(IEnumerable<KeyValuePair<string, object?>> values)
             {
                 return values.Select(
                     kvp =>

+ 1 - 1
src/Http/Routing/src/EndpointNameAddressScheme.cs

@@ -89,7 +89,7 @@ internal sealed class EndpointNameAddressScheme : IEndpointAddressScheme<string>
 
         throw new InvalidOperationException(builder.ToString());
 
-        string? GetEndpointName(Endpoint endpoint)
+        static string? GetEndpointName(Endpoint endpoint)
         {
             if (endpoint.Metadata.GetMetadata<ISuppressLinkGenerationMetadata>()?.SuppressLinkGeneration == true)
             {

+ 1 - 1
src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs

@@ -308,7 +308,7 @@ public sealed class HttpMethodMatcherPolicy : MatcherPolicy, IEndpointComparerPo
 
         return policyNodeEdges;
 
-        (IReadOnlyList<string> httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e)
+        static (IReadOnlyList<string> httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e)
         {
             var metadata = e.Metadata.GetMetadata<IHttpMethodMetadata>();
             return metadata == null ? (Array.Empty<string>(), false) : (metadata.HttpMethods, metadata.AcceptCorsPreflight);

+ 1 - 2
src/Identity/ApiAuthorization.IdentityServer/src/Authentication/AuthenticationBuilderExtensions.cs

@@ -47,7 +47,7 @@ public static class AuthenticationBuilderExtensions
 
         return builder;
 
-        IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProvider sp)
+        static IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProvider sp)
         {
             var schemeName = IdentityServerJwtConstants.IdentityServerJwtBearerScheme;
 
@@ -58,5 +58,4 @@ public static class AuthenticationBuilderExtensions
             return new IdentityServerJwtBearerOptionsConfiguration(schemeName, apiName, localApiDescriptor);
         }
     }
-
 }

+ 0 - 4
src/Middleware/Rewrite/src/ApacheModRewrite/FileParser.cs

@@ -13,11 +13,7 @@ internal class FileParser
         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)
         {

+ 1 - 1
src/Middleware/Spa/SpaProxy/src/SpaProxyMiddleware.cs

@@ -68,7 +68,7 @@ internal class SpaProxyMiddleware
             context.Response.Redirect(_options.Value.ServerUrl);
         }
 
-        string GenerateSpaLaunchPage(SpaDevelopmentServerOptions options)
+        static string GenerateSpaLaunchPage(SpaDevelopmentServerOptions options)
         {
             return $@"
 <!DOCTYPE html>

+ 1 - 1
src/Mvc/Mvc.Core/src/ApplicationModels/ApiBehaviorApplicationModelProvider.cs

@@ -97,7 +97,7 @@ internal class ApiBehaviorApplicationModelProvider : IApplicationModelProvider
             throw new InvalidOperationException(message);
         }
 
-        bool IsAttributeRouted(IList<SelectorModel> selectorModel)
+        static bool IsAttributeRouted(IList<SelectorModel> selectorModel)
         {
             for (var i = 0; i < selectorModel.Count; i++)
             {

+ 1 - 1
src/Mvc/Mvc.Core/src/Routing/ActionConstraintMatcherPolicy.cs

@@ -54,7 +54,7 @@ internal class ActionConstraintMatcherPolicy : MatcherPolicy, IEndpointSelectorP
 
         return false;
 
-        bool HasSignificantActionConstraint(IList<IActionConstraintMetadata> constraints)
+        static bool HasSignificantActionConstraint(IList<IActionConstraintMetadata> constraints)
         {
             for (var i = 0; i < constraints.Count; i++)
             {

+ 1 - 1
src/Mvc/Mvc.RazorPages/src/ApplicationModels/CompiledPageRouteModelProvider.cs

@@ -73,7 +73,7 @@ internal class CompiledPageRouteModelProvider : IPageRouteModelProvider
             }
         }
 
-        bool IsRazorPage(CompiledViewDescriptor viewDescriptor)
+        static bool IsRazorPage(CompiledViewDescriptor viewDescriptor)
         {
             if (viewDescriptor.Item != null)
             {

+ 1 - 1
src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs

@@ -71,7 +71,7 @@ internal class StaticComponentRenderer
 
         return _initialized;
 
-        async Task InitializeCore(HttpContext httpContext)
+        static async Task InitializeCore(HttpContext httpContext)
         {
             var navigationManager = (IHostEnvironmentNavigationManager)httpContext.RequestServices.GetRequiredService<NavigationManager>();
             navigationManager?.Initialize(GetContextBaseUri(httpContext.Request), GetFullUri(httpContext.Request));

+ 1 - 1
src/Servers/Kestrel/shared/KnownHeaders.cs

@@ -380,7 +380,7 @@ public class KnownHeaders
             firstTermVar = "";
         }
 
-        string GenerateIfBody(KnownHeader header, string extraIndent = "")
+        static string GenerateIfBody(KnownHeader header, string extraIndent = "")
         {
             if (header.Name == HeaderNames.ContentLength)
             {

+ 1 - 1
src/Servers/Kestrel/stress/Program.cs

@@ -620,7 +620,7 @@ public class Program
             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;

+ 4 - 5
src/Shared/BrowserTesting/src/PageInformation.cs

@@ -98,11 +98,7 @@ public class PageInformation : IDisposable
 
             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 @@ public class PageInformation : IDisposable
                 "error" => LogLevel.Error,
                 _ => LogLevel.Information
             };
+            _logger.Log(logLevel, logMessage);
+
+            BrowserConsoleLogs.Add(new LogEntry(messageText, message.Type));
         }
         catch
         {

+ 1 - 1
src/SignalR/common/Shared/PipeWriterStream.cs

@@ -89,7 +89,7 @@ internal class PipeWriterStream : Stream
 
         return default;
 
-        async ValueTask WriteSlowAsync(ValueTask<FlushResult> flushTask)
+        static async ValueTask WriteSlowAsync(ValueTask<FlushResult> flushTask)
         {
             var flushResult = await flushTask;