Skip to content

Commit

Permalink
Enable IDE0060 (#40461)
Browse files Browse the repository at this point in the history
* Enable IDE0060

Contributes to #24055
  • Loading branch information
pranavkm authored Mar 2, 2022
1 parent 6378cda commit e059629
Show file tree
Hide file tree
Showing 52 changed files with 121 additions and 159 deletions.
10 changes: 9 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ dotnet_diagnostic.IDE0055.severity = suggestion
# IDE0059: Unnecessary assignment to a value
dotnet_diagnostic.IDE0059.severity = warning

# IDE0060: Remove unused parameter
dotnet_code_quality_unused_parameters = non_public
dotnet_diagnostic.IDE0060.severity = warning

# IDE0062: Make local function static
dotnet_diagnostic.IDE0062.severity = warning

Expand All @@ -259,7 +263,7 @@ dotnet_diagnostic.IDE0161.severity = warning
dotnet_style_allow_multiple_blank_lines_experimental = false
dotnet_diagnostic.IDE2000.severity = warning

[{eng/tools/**.cs,**/{test,samples,perf}/**.cs}]
[{eng/tools/**.cs,**/{test,testassets,samples,Samples,perf}/**.cs}]
# CA1018: Mark attributes with AttributeUsageAttribute
dotnet_diagnostic.CA1018.severity = suggestion
# CA1507: Use nameof to express symbol names
Expand Down Expand Up @@ -312,6 +316,8 @@ dotnet_diagnostic.IDE0044.severity = suggestion
dotnet_diagnostic.IDE0051.severity = suggestion
# IDE0059: Unnecessary assignment to a value
dotnet_diagnostic.IDE0059.severity = suggestion
# IDE0060: Remove unused parameters
dotnet_diagnostic.IDE0060.severity = suggestion
# IDE0062: Make local function static
dotnet_diagnostic.IDE0062.severity = suggestion

Expand All @@ -327,6 +333,8 @@ dotnet_diagnostic.CA1822.severity = silent
dotnet_diagnostic.IDE0011.severity = silent
# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = silent
# IDE0060: Remove unused parameters
dotnet_diagnostic.IDE0060.severity = silent
# IDE0062: Make local function static
dotnet_diagnostic.IDE0062.severity = silent
# IDE0161: Convert to file-scoped namespace
Expand Down
12 changes: 6 additions & 6 deletions src/Components/Components/src/BindConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class BindConverter
[SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "Required to maintain compatibility")]
public static string? FormatValue(string? value, CultureInfo? culture = null) => FormatStringValueCore(value, culture);

private static string? FormatStringValueCore(string? value, CultureInfo? culture)
private static string? FormatStringValueCore(string? value, CultureInfo? _)
{
return value;
}
Expand All @@ -61,7 +61,7 @@ public static bool FormatValue(bool value, CultureInfo? culture = null)
}

// Used with generics
private static object FormatBoolValueCore(bool value, CultureInfo? culture)
private static object FormatBoolValueCore(bool value, CultureInfo? _)
{
// Formatting for bool is special-cased. We need to produce a boolean value for conditional attributes
// to work.
Expand All @@ -85,7 +85,7 @@ private static object FormatBoolValueCore(bool value, CultureInfo? culture)
}

// Used with generics
private static object? FormatNullableBoolValueCore(bool? value, CultureInfo? culture)
private static object? FormatNullableBoolValueCore(bool? value, CultureInfo? _)
{
// Formatting for bool is special-cased. We need to produce a boolean value for conditional attributes
// to work.
Expand Down Expand Up @@ -662,7 +662,7 @@ private static string FormatTimeOnlyValueCore(TimeOnly value, CultureInfo? cultu
return value.Value.ToString(culture ?? CultureInfo.CurrentCulture);
}

private static string? FormatEnumValueCore<T>(T value, CultureInfo? culture)
private static string? FormatEnumValueCore<T>(T value, CultureInfo? _)
{
if (value == null)
{
Expand Down Expand Up @@ -1600,7 +1600,7 @@ private static bool ConvertToNullableGuidCore(object? obj, CultureInfo? culture,
return true;
}

private static bool ConvertToEnum<T>(object? obj, CultureInfo? culture, out T value) where T : struct, Enum
private static bool ConvertToEnum<T>(object? obj, CultureInfo? _, out T value) where T : struct, Enum
{
var text = (string?)obj;
if (string.IsNullOrEmpty(text))
Expand All @@ -1625,7 +1625,7 @@ private static bool ConvertToEnum<T>(object? obj, CultureInfo? culture, out T va
return true;
}

private static bool ConvertToNullableEnum<T>(object? obj, CultureInfo? culture, out T? value) where T : struct, Enum
private static bool ConvertToNullableEnum<T>(object? obj, CultureInfo? _, out T? value) where T : struct, Enum
{
var text = (string?)obj;
if (string.IsNullOrEmpty(text))
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Server/src/BlazorPack/Requires.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static void NotNull(object arg, string paramName)
{
if (arg == null)
{
throw new ArgumentNullException(nameof(paramName));
throw new ArgumentNullException(paramName);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Web/src/Forms/InputFile/BrowserFileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
return 0;
}

var bytesRead = await CopyFileDataIntoBuffer(_position, buffer.Slice(0, maxBytesToRead), cancellationToken);
var bytesRead = await CopyFileDataIntoBuffer(buffer.Slice(0, maxBytesToRead), cancellationToken);

_position += bytesRead;

Expand All @@ -98,7 +98,7 @@ private async Task<Stream> OpenReadStreamAsync(CancellationToken cancellationTok
cancellationToken: cancellationToken);
}

private async ValueTask<int> CopyFileDataIntoBuffer(long sourceOffset, Memory<byte> destination, CancellationToken cancellationToken)
private async ValueTask<int> CopyFileDataIntoBuffer(Memory<byte> destination, CancellationToken cancellationToken)
{
var stream = await OpenReadStreamTask;
_copyFileDataCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
Expand Down
6 changes: 3 additions & 3 deletions src/Components/WebAssembly/Server/src/TargetPickerUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Ensure your browser is running with debugging enabled.
if (matchingTabs.Count == 1)
{
// We know uniquely which tab to debug, so just redirect
var devToolsUrlWithProxy = GetDevToolsUrlWithProxy(request, matchingTabs.Single());
var devToolsUrlWithProxy = GetDevToolsUrlWithProxy(matchingTabs.Single());
context.Response.Redirect(devToolsUrlWithProxy);
}
else if (matchingTabs.Count == 0)
Expand Down Expand Up @@ -134,7 +134,7 @@ await context.Response.WriteAsync(@"

foreach (var tab in matchingTabs)
{
var devToolsUrlWithProxy = GetDevToolsUrlWithProxy(request, tab);
var devToolsUrlWithProxy = GetDevToolsUrlWithProxy(tab);
await context.Response.WriteAsync(
$"<a class='inspectable-page' href='{WebUtility.HtmlEncode(devToolsUrlWithProxy)}'>"
+ $"<h3>{WebUtility.HtmlEncode(tab.Title)}</h3>{WebUtility.HtmlEncode(tab.Url)}"
Expand All @@ -143,7 +143,7 @@ await context.Response.WriteAsync(
}
}

private string GetDevToolsUrlWithProxy(HttpRequest request, BrowserTab tabToDebug)
private string GetDevToolsUrlWithProxy(BrowserTab tabToDebug)
{
var underlyingV8Endpoint = new Uri(tabToDebug.WebSocketDebuggerUrl);
var proxyEndpoint = new Uri(_debugProxyUrl);
Expand Down
4 changes: 2 additions & 2 deletions src/Components/WebView/WebView/src/IpcReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task OnMessageReceivedAsync(PageContext pageContext, string message
BeginInvokeDotNet(pageContext, args[0].GetString(), args[1].GetString(), args[2].GetString(), args[3].GetInt64(), args[4].GetString());
break;
case IpcCommon.IncomingMessageType.EndInvokeJS:
EndInvokeJS(pageContext, args[0].GetInt64(), args[1].GetBoolean(), args[2].GetString());
EndInvokeJS(pageContext, args[2].GetString());
break;
case IpcCommon.IncomingMessageType.ReceiveByteArrayFromJS:
ReceiveByteArrayFromJS(pageContext, args[0].GetInt32(), args[1].GetBytesFromBase64());
Expand All @@ -77,7 +77,7 @@ private static void BeginInvokeDotNet(PageContext pageContext, string callId, st
argsJson);
}

private static void EndInvokeJS(PageContext pageContext, long asyncHandle, bool succeeded, string argumentsOrError)
private static void EndInvokeJS(PageContext pageContext, string argumentsOrError)
{
DotNetDispatcher.EndInvokeJS(pageContext.JSRuntime, argumentsOrError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ internal sealed class DefaultKeyResolver : IDefaultKeyResolver
/// </remarks>
private readonly TimeSpan _maxServerToServerClockSkew;

public DefaultKeyResolver(IOptions<KeyManagementOptions> keyManagementOptions)
: this(keyManagementOptions, NullLoggerFactory.Instance)
public DefaultKeyResolver()
: this(NullLoggerFactory.Instance)
{ }

public DefaultKeyResolver(IOptions<KeyManagementOptions> keyManagementOptions, ILoggerFactory loggerFactory)
public DefaultKeyResolver(ILoggerFactory loggerFactory)
{
_keyPropagationWindow = KeyManagementOptions.KeyPropagationWindow;
_maxServerToServerClockSkew = KeyManagementOptions.MaxServerClockSkew;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ public void ResolveDefaultKeyPolicy_FallbackKey_NoNonRevokedKeysBeforePriorPropa

private static IDefaultKeyResolver CreateDefaultKeyResolver()
{
var options = Options.Create(new KeyManagementOptions());
return new DefaultKeyResolver(options, NullLoggerFactory.Instance);
return new DefaultKeyResolver(NullLoggerFactory.Instance);
}

private static IKey CreateKey(string activationDate, string expirationDate, string creationDate = null, bool isRevoked = false, bool createEncryptorThrows = false)
Expand Down
1 change: 0 additions & 1 deletion src/Http/Routing/src/DefaultLinkGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ internal sealed partial class DefaultLinkGenerator : LinkGenerator, IDisposable
private readonly Func<RouteEndpoint, TemplateBinder> _createTemplateBinder;

public DefaultLinkGenerator(
ParameterPolicyFactory parameterPolicyFactory,
TemplateBinderFactory binderFactory,
EndpointDataSource dataSource,
IOptions<RouteOptions> routeOptions,
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Routing/src/Matching/ILEmitTrieFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public static Func<string, int, int, int> Create(
typeof(int),
new[] { typeof(string), typeof(int), typeof(int), });

GenerateMethodBody(method.GetILGenerator(), defaultDestination, exitDestination, entries, vectorize);
GenerateMethodBody(method.GetILGenerator(), defaultDestination, entries, vectorize);

#if IL_EMIT_SAVE_ASSEMBLY
SaveAssembly(method.GetILGenerator(), defaultDestination, exitDestination, entries, vectorize);
SaveAssembly(method.GetILGenerator(), defaultDestination, entries, vectorize);
#endif

return (Func<string, int, int, int>)method.CreateDelegate(typeof(Func<string, int, int, int>));
Expand All @@ -59,7 +59,6 @@ internal static bool ShouldVectorize((string text, int destination)[] entries)
private static void GenerateMethodBody(
ILGenerator il,
int defaultDestination,
int exitDestination,
(string text, int destination)[] entries,
bool? vectorize)
{
Expand Down
6 changes: 2 additions & 4 deletions src/Http/Routing/src/Template/TemplateBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,9 @@ private bool TryBindValuesCore(UriBuildingContext context, RouteValueDictionary
// for format, so we remove '.' and generate 5.
if (!context.Accept(converted, parameterPart.EncodeSlashes))
{
RoutePatternSeparatorPart? nullablePart;
if (j != 0 && parameterPart.IsOptional && (nullablePart = parts[j - 1] as RoutePatternSeparatorPart) != null)
if (j != 0 && parameterPart.IsOptional && parts[j - 1] is RoutePatternSeparatorPart)
{
separatorPart = nullablePart;
context.Remove(separatorPart.Content);
context.Remove();
}
else
{
Expand Down
7 changes: 2 additions & 5 deletions src/Http/Routing/src/Tree/LinkGenerationDecisionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public IList<OutboundMatchResult> GetMatches(RouteValueDictionary values, RouteV
{
var results = new List<OutboundMatchResult>();
Walk(results, values, ambientValues ?? EmptyAmbientValues, _root, isFallbackPath: false);
ProcessConventionalEntries(results, values, ambientValues ?? EmptyAmbientValues);
ProcessConventionalEntries(results);
results.Sort(OutboundMatchResultComparer.Instance);
return results;
}
Expand Down Expand Up @@ -159,10 +159,7 @@ private void Walk(
}
}

private void ProcessConventionalEntries(
List<OutboundMatchResult> results,
RouteValueDictionary values,
RouteValueDictionary ambientvalues)
private void ProcessConventionalEntries(List<OutboundMatchResult> results)
{
for (var i = 0; i < _conventionalEntries.Count; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Routing/src/UriBuildingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Microsoft.AspNetCore.Routing;

[DebuggerDisplay("{DebuggerToString(),nq}")]
internal class UriBuildingContext
internal sealed class UriBuildingContext
{
// Holds the 'accepted' parts of the path.
private readonly StringBuilder _path;
Expand Down Expand Up @@ -133,7 +133,7 @@ public bool Accept(string? value, bool encodeSlashes)
return true;
}

public void Remove(string literal)
public void Remove()
{
Debug.Assert(_lastValueOffset != -1, "Cannot invoke Remove more than once.");
_path.Length = _lastValueOffset;
Expand Down
1 change: 0 additions & 1 deletion src/Http/Routing/test/UnitTests/LinkGeneratorTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private protected DefaultLinkGenerator CreateLinkGenerator(
var routeOptions = serviceProvider.GetRequiredService<IOptions<RouteOptions>>();

return new DefaultLinkGenerator(
new DefaultParameterPolicyFactory(routeOptions, serviceProvider),
serviceProvider.GetRequiredService<TemplateBinderFactory>(),
new CompositeEndpointDataSource(routeOptions.Value.EndpointDataSources),
routeOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal IEnumerable<Client> GetClients()
yield return GetLocalSPA(name, definition);
break;
case ApplicationProfiles.NativeApp:
yield return GetNativeApp(name, definition);
yield return GetNativeApp(name);
break;
default:
throw new InvalidOperationException($"Type '{definition.Profile}' is not supported.");
Expand Down Expand Up @@ -97,7 +97,7 @@ private static Client GetSPA(string name, ClientDefinition definition)
return client.Build();
}

private static Client GetNativeApp(string name, ClientDefinition definition)
private static Client GetNativeApp(string name)
{
var client = ClientBuilder.NativeApp(name)
.FromConfiguration();
Expand Down
2 changes: 1 addition & 1 deletion src/Logging.AzureAppServices/src/BatchingLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public bool IsEnabled(LogLevel logLevel)
return _provider.IsEnabled;
}

public void Log<TState>(DateTimeOffset timestamp, LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
public void Log<TState>(DateTimeOffset timestamp, LogLevel logLevel, EventId _, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (!IsEnabled(logLevel))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/Spa/SpaProxy/src/SpaProxyLaunchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private void LaunchStopScriptMacOS(int spaProcessId)
}
}

public Task StopAsync(CancellationToken cancellationToken)
public Task StopAsync()
{
Dispose(true);
return Task.CompletedTask;
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/WebSockets/src/HandshakeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static bool ParseDeflateOptions(ReadOnlySpan<char> extension, bool server
}

hasClientMaxWindowBits = true;
if (!ParseWindowBits(value, WebSocketDeflateConstants.ClientMaxWindowBits, out var clientMaxWindowBits))
if (!ParseWindowBits(value, out var clientMaxWindowBits))
{
return false;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public static bool ParseDeflateOptions(ReadOnlySpan<char> extension, bool server
}

hasServerMaxWindowBits = true;
if (!ParseWindowBits(value, WebSocketDeflateConstants.ServerMaxWindowBits, out var parsedServerMaxWindowBits))
if (!ParseWindowBits(value, out var parsedServerMaxWindowBits))
{
return false;
}
Expand All @@ -211,7 +211,7 @@ public static bool ParseDeflateOptions(ReadOnlySpan<char> extension, bool server
parsedOptions.ServerMaxWindowBits = Math.Min(parsedServerMaxWindowBits ?? 15, serverMaxWindowBits);
}

static bool ParseWindowBits(ReadOnlySpan<char> value, string propertyName, out int? parsedValue)
static bool ParseWindowBits(ReadOnlySpan<char> value, out int? parsedValue)
{
var startIndex = value.IndexOf('=');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public static class ActualApiResponseMetadataFactory
internal static bool TryGetActualResponseMetadata(
in ApiControllerSymbolCache symbolCache,
IMethodBodyBaseOperation methodBody,
CancellationToken cancellationToken,
out IList<ActualApiResponseMetadata> actualResponseMetadata)
{
var localActualResponseMetadata = new List<ActualApiResponseMetadata>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static Dictionary<int, string> GetStatusCodeConstants(INamedTypeSymbol s
{
var operation = (IMethodBodyBaseOperation)context.SemanticModel.GetOperation(context.MethodSyntax, context.CancellationToken);

if (!ActualApiResponseMetadataFactory.TryGetActualResponseMetadata(context.SymbolCache, operation, context.CancellationToken, out var actualResponseMetadata))
if (!ActualApiResponseMetadataFactory.TryGetActualResponseMetadata(context.SymbolCache, operation, out var actualResponseMetadata))
{
// If we cannot parse metadata correctly, don't offer fixes.
return Array.Empty<(int, ITypeSymbol?)>();
Expand Down
2 changes: 1 addition & 1 deletion src/Mvc/Mvc.Api.Analyzers/src/ApiConventionAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void InitializeWorker(CompilationStartAnalysisContext compilation
}
var declaredResponseMetadata = SymbolApiResponseMetadataProvider.GetDeclaredResponseMetadata(symbolCache, method);
var hasUnreadableStatusCodes = !ActualApiResponseMetadataFactory.TryGetActualResponseMetadata(symbolCache, (IMethodBodyOperation)operationStartContext.Operation, operationStartContext.CancellationToken, out var actualResponseMetadata);
var hasUnreadableStatusCodes = !ActualApiResponseMetadataFactory.TryGetActualResponseMetadata(symbolCache, (IMethodBodyOperation)operationStartContext.Operation, out var actualResponseMetadata);
var hasUndocumentedStatusCodes = false;
foreach (var actualMetadata in actualResponseMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public async Task TryGetActualResponseMetadata_ActionWithActionResultOfTReturnin
var methodSyntax = (MethodDeclarationSyntax)syntaxTree.GetRoot().FindNode(method.Locations[0].SourceSpan);
var methodOperation = (IMethodBodyBaseOperation)compilation.GetSemanticModel(syntaxTree).GetOperation(methodSyntax);

var result = ActualApiResponseMetadataFactory.TryGetActualResponseMetadata(symbolCache, methodOperation, CancellationToken.None, out var responseMetadatas);
var result = ActualApiResponseMetadataFactory.TryGetActualResponseMetadata(symbolCache, methodOperation, out var responseMetadatas);

return (result, responseMetadatas, testSource);
}
Expand Down
Loading

0 comments on commit e059629

Please sign in to comment.