Skip to content

Commit 07d728b

Browse files
authored
Enable warnings for IDE0062 (#39463)
Contributes to #24055
1 parent d5557cd commit 07d728b

File tree

17 files changed

+26
-25
lines changed

17 files changed

+26
-25
lines changed

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ dotnet_diagnostic.IDE0055.severity = warning
233233
# IDE0059: Unnecessary assignment to a value
234234
dotnet_diagnostic.IDE0059.severity = warning
235235

236+
# IDE0062: Make local function static
237+
dotnet_diagnostic.IDE0062.severity = warning
238+
236239
# IDE0073: File header
237240
dotnet_diagnostic.IDE0073.severity = warning
238241
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
285288
dotnet_diagnostic.IDE0051.severity = suggestion
286289
# IDE0059: Unnecessary assignment to a value
287290
dotnet_diagnostic.IDE0059.severity = suggestion
291+
# IDE0062: Make local function static
292+
dotnet_diagnostic.IDE0062.severity = suggestion
288293

289294
# CA2016: Forward the 'CancellationToken' parameter to methods that take one
290295
dotnet_diagnostic.CA2016.severity = suggestion
@@ -298,6 +303,8 @@ dotnet_diagnostic.CA1822.severity = silent
298303
dotnet_diagnostic.IDE0011.severity = silent
299304
# IDE0055: Fix formatting
300305
dotnet_diagnostic.IDE0055.severity = silent
306+
# IDE0062: Make local function static
307+
dotnet_diagnostic.IDE0062.severity = silent
301308
# IDE0161: Convert to file-scoped namespace
302309
dotnet_diagnostic.IDE0161.severity = silent
303310

src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/AzureAdB2CAuthenticationBuilderExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static void AddAdditionalMvcApplicationParts(IServiceCollection services
207207
apm.FeatureProviders.Add(new AzureADB2CAccountControllerFeatureProvider());
208208
});
209209

210-
bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal);
210+
static bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal);
211211
}
212212

213213
private static IEnumerable<ApplicationPart> GetAdditionalParts()

src/Hosting/Hosting/src/WebHostBuilder.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ public IWebHost Build()
198198
throw;
199199
}
200200

201-
IServiceProvider GetProviderFromFactory(IServiceCollection collection)
201+
static IServiceProvider GetProviderFromFactory(IServiceCollection collection)
202202
{
203203
var provider = collection.BuildServiceProvider();
204204
var factory = provider.GetService<IServiceProviderFactory<IServiceCollection>>();
205205

206-
if (factory != null && !(factory is DefaultServiceProviderFactory))
206+
if (factory != null && factory is not DefaultServiceProviderFactory)
207207
{
208208
using (provider)
209209
{

src/Http/Routing/src/CompositeEndpointDataSource.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private string DebuggerDisplayString
205205
}
206206
return sb.ToString();
207207

208-
IEnumerable<string> FormatValues(IEnumerable<KeyValuePair<string, object?>> values)
208+
static IEnumerable<string> FormatValues(IEnumerable<KeyValuePair<string, object?>> values)
209209
{
210210
return values.Select(
211211
kvp =>

src/Http/Routing/src/EndpointNameAddressScheme.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static Dictionary<string, Endpoint[]> Initialize(IReadOnlyList<Endpoint>
8989

9090
throw new InvalidOperationException(builder.ToString());
9191

92-
string? GetEndpointName(Endpoint endpoint)
92+
static string? GetEndpointName(Endpoint endpoint)
9393
{
9494
if (endpoint.Metadata.GetMetadata<ISuppressLinkGenerationMetadata>()?.SuppressLinkGeneration == true)
9595
{

src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public IReadOnlyList<PolicyNodeEdge> GetEdges(IReadOnlyList<Endpoint> endpoints)
308308

309309
return policyNodeEdges;
310310

311-
(IReadOnlyList<string> httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e)
311+
static (IReadOnlyList<string> httpMethods, bool acceptCorsPreflight) GetHttpMethods(Endpoint e)
312312
{
313313
var metadata = e.Metadata.GetMetadata<IHttpMethodMetadata>();
314314
return metadata == null ? (Array.Empty<string>(), false) : (metadata.HttpMethods, metadata.AcceptCorsPreflight);

src/Identity/ApiAuthorization.IdentityServer/src/Authentication/AuthenticationBuilderExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static AuthenticationBuilder AddIdentityServerJwt(this AuthenticationBuil
4747

4848
return builder;
4949

50-
IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProvider sp)
50+
static IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProvider sp)
5151
{
5252
var schemeName = IdentityServerJwtConstants.IdentityServerJwtBearerScheme;
5353

@@ -58,5 +58,4 @@ IdentityServerJwtBearerOptionsConfiguration JwtBearerOptionsFactory(IServiceProv
5858
return new IdentityServerJwtBearerOptionsConfiguration(schemeName, apiName, localApiDescriptor);
5959
}
6060
}
61-
6261
}

src/Middleware/Rewrite/src/ApacheModRewrite/FileParser.cs

-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ public static IList<IRule> Parse(TextReader input)
1313
var lineNum = 0;
1414

1515
// parsers
16-
var testStringParser = new TestStringParser();
17-
var conditionParser = new ConditionPatternParser();
18-
var regexParser = new RuleRegexParser();
1916
var flagsParser = new FlagParser();
20-
var tokenizer = new Tokenizer();
2117

2218
while ((line = input.ReadLine()) != null)
2319
{

src/Middleware/Spa/SpaProxy/src/SpaProxyMiddleware.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private async Task InvokeCore(HttpContext context)
6868
context.Response.Redirect(_options.Value.ServerUrl);
6969
}
7070

71-
string GenerateSpaLaunchPage(SpaDevelopmentServerOptions options)
71+
static string GenerateSpaLaunchPage(SpaDevelopmentServerOptions options)
7272
{
7373
return $@"
7474
<!DOCTYPE html>

src/Mvc/Mvc.Core/src/ApplicationModels/ApiBehaviorApplicationModelProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static void EnsureActionIsAttributeRouted(ActionModel actionModel)
9797
throw new InvalidOperationException(message);
9898
}
9999

100-
bool IsAttributeRouted(IList<SelectorModel> selectorModel)
100+
static bool IsAttributeRouted(IList<SelectorModel> selectorModel)
101101
{
102102
for (var i = 0; i < selectorModel.Count; i++)
103103
{

src/Mvc/Mvc.Core/src/Routing/ActionConstraintMatcherPolicy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public bool AppliesToEndpoints(IReadOnlyList<Endpoint> endpoints)
5454

5555
return false;
5656

57-
bool HasSignificantActionConstraint(IList<IActionConstraintMetadata> constraints)
57+
static bool HasSignificantActionConstraint(IList<IActionConstraintMetadata> constraints)
5858
{
5959
for (var i = 0; i < constraints.Count; i++)
6060
{

src/Mvc/Mvc.RazorPages/src/ApplicationModels/CompiledPageRouteModelProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private IEnumerable<CompiledViewDescriptor> GetViewDescriptors(ApplicationPartMa
7373
}
7474
}
7575

76-
bool IsRazorPage(CompiledViewDescriptor viewDescriptor)
76+
static bool IsRazorPage(CompiledViewDescriptor viewDescriptor)
7777
{
7878
if (viewDescriptor.Item != null)
7979
{

src/Mvc/Mvc.ViewFeatures/src/RazorComponents/StaticComponentRenderer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private Task InitializeStandardComponentServicesAsync(HttpContext httpContext)
7171

7272
return _initialized;
7373

74-
async Task InitializeCore(HttpContext httpContext)
74+
static async Task InitializeCore(HttpContext httpContext)
7575
{
7676
var navigationManager = (IHostEnvironmentNavigationManager)httpContext.RequestServices.GetRequiredService<NavigationManager>();
7777
navigationManager?.Initialize(GetContextBaseUri(httpContext.Request), GetFullUri(httpContext.Request));

src/Servers/Kestrel/shared/KnownHeaders.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static string AppendSwitchSection(int length, IList<KnownHeader> values)
380380
firstTermVar = "";
381381
}
382382

383-
string GenerateIfBody(KnownHeader header, string extraIndent = "")
383+
static string GenerateIfBody(KnownHeader header, string extraIndent = "")
384384
{
385385
if (header.Name == HeaderNames.ContentLength)
386386
{

src/Servers/Kestrel/stress/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public ClientContext(HttpClient httpClient, int taskNum, int seed)
620620
HttpClient = httpClient;
621621

622622
// deterministic hashing copied from System.Runtime.Hashing
623-
int Combine(int h1, int h2)
623+
static int Combine(int h1, int h2)
624624
{
625625
uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27);
626626
return ((int)rol5 + h1) ^ h2;

src/Shared/BrowserTesting/src/PageInformation.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,17 @@ private void RecordConsoleMessage(object sender, IConsoleMessage message)
9898

9999
var logMessage = $"[{_page.Url}]{Environment.NewLine} {messageText}{Environment.NewLine} ({location})";
100100

101-
_logger.Log(MapLogLevel(message.Type), logMessage);
102-
103-
BrowserConsoleLogs.Add(new LogEntry(messageText, message.Type));
104-
105-
LogLevel MapLogLevel(string messageType) => messageType switch
101+
var logLevel = message.Type switch
106102
{
107103
"info" => LogLevel.Information,
108104
"verbose" => LogLevel.Debug,
109105
"warning" => LogLevel.Warning,
110106
"error" => LogLevel.Error,
111107
_ => LogLevel.Information
112108
};
109+
_logger.Log(logLevel, logMessage);
110+
111+
BrowserConsoleLogs.Add(new LogEntry(messageText, message.Type));
113112
}
114113
catch
115114
{

src/SignalR/common/Shared/PipeWriterStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private ValueTask WriteCoreAsync(ReadOnlyMemory<byte> source, CancellationToken
8989

9090
return default;
9191

92-
async ValueTask WriteSlowAsync(ValueTask<FlushResult> flushTask)
92+
static async ValueTask WriteSlowAsync(ValueTask<FlushResult> flushTask)
9393
{
9494
var flushResult = await flushTask;
9595

0 commit comments

Comments
 (0)