Skip to content

Commit

Permalink
Disable problematic analyzer CA1801 (#1134)
Browse files Browse the repository at this point in the history
* Disable "Review Unused Parameters" analyzer

See dotnet/roslyn#8884

* Remove suppressions for CA1801 false positives
  • Loading branch information
sharwell authored and mavasani committed Apr 10, 2017
1 parent fa235f0 commit 9baeaad
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 41 deletions.
6 changes: 6 additions & 0 deletions build/Rulesets/Analyzers.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
<!-- SpecifyIFormatProvider -->
<Rule Id="CA1305" Action="None" />
</Rules>

<!-- TODO: Remove the below suppression once https://github.com/dotnet/roslyn/issues/8884 has been fixed. -->
<Rules AnalyzerId="Microsoft.Maintainability.Analyzers" RuleNamespace="Microsoft.Maintainability.Analyzers">
<!-- ReviewUnusedParameters -->
<Rule Id="CA1801" Action="None" />
</Rules>
</RuleSet>
3 changes: 0 additions & 3 deletions src/Analyzer.Utilities/Extensions/ISymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,10 @@ private static bool IsImplementationOfInterfaceMember(ISymbol symbol, ISymbol in
return interfaceMember != null && symbol.Equals(symbol.ContainingType.FindImplementationForInterfaceMember(interfaceMember));
}

// TODO: Remove the below suppression once the following Roslyn bug is fixed: https://github.com/dotnet/roslyn/issues/8884
#pragma warning disable CA1801
/// <summary>
/// Checks if a given symbol implements an interface member explicitly
/// </summary>
public static bool IsImplementationOfAnyExplicitInterfaceMember(this ISymbol symbol)
#pragma warning restore CA1801
{
if (symbol is IMethodSymbol methodSymbol && methodSymbol.ExplicitInterfaceImplementations.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ public bool IsMatch(IMethodSymbol method, Compilation compilation)
}
}

// TODO: Remove the below suppression once the following Roslyn bug is fixed: https://github.com/dotnet/roslyn/issues/8884
#pragma warning disable CA1801
private static List<MethodCategory> GetMethodCategories(Compilation compilation)
#pragma warning disable CA1801
{
var methodCategories = new List<MethodCategory> {
new MethodCategory(IsPropertyGetter, true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,10 @@ private static void CheckIDisposableReimplementationRule(INamedTypeSymbol type,
}
}

// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Ensure that {0} is declared as public and sealed.
/// </summary>
private static void CheckDisposeSignatureRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (!method.IsPublic() ||
method.IsAbstract || method.IsVirtual || (method.IsOverride && !method.IsSealed))
Expand All @@ -315,29 +311,21 @@ private static void CheckDisposeSignatureRule(IMethodSymbol method, INamedTypeSy
}
}

// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Rename {0} to 'Dispose' and ensure that it is declared as public and sealed.
/// </summary>
private static void CheckRenameDisposeRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (method.Name != DisposeMethodName)
{
context.ReportDiagnostic(method.CreateDiagnostic(RenameDisposeRule, $"{type.Name}.{method.Name}"));
}
}

// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Remove {0}, override Dispose(bool disposing), and put the dispose logic in the code path where 'disposing' is true.
/// </summary>
private void CheckDisposeOverrideRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (method.MethodKind == MethodKind.Ordinary && method.IsOverride && method.ReturnsVoid && method.Parameters.Length == 0)
{
Expand Down Expand Up @@ -377,14 +365,10 @@ private static void CheckProvideDisposeBoolRule(INamedTypeSymbol type, SymbolAna
context.ReportDiagnostic(type.CreateDiagnostic(ProvideDisposeBoolRule, type.Name));
}

// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Ensure that {0} is declared as protected, virtual, and unsealed.
/// </summary>
private static void CheckDisposeBoolSignatureRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (method.DeclaredAccessibility != Accessibility.Protected ||
!(method.IsVirtual || method.IsAbstract || method.IsOverride) || method.IsSealed)
Expand All @@ -405,13 +389,10 @@ private void CheckDisposeImplementationRule(IMethodSymbol method, INamedTypeSymb
}
}

// CA1801: Remove unused parameters.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Modify {0} so that it calls Dispose(false) and then returns.
/// </summary>
private static void CheckFinalizeImplementationRule(IMethodSymbol method, INamedTypeSymbol type, ImmutableArray<IOperation> operationBlocks, OperationBlockAnalysisContext context)
#pragma warning restore CA1801
{
// TODO: Implement check of Finalize
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,7 @@ internal static bool IsPropertyExpected(string operatorName)
}
}

// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
internal static ExpectedAlternateMethodGroup GetExpectedAlternateMethodGroup(string operatorName, ITypeSymbol returnType)
#pragma warning restore CA1801
{
// list of operator alternate names: https://msdn.microsoft.com/en-us/library/ms182355.aspx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,7 @@ private void AnalyzeArgumentSyntax(SyntaxNodeAnalysisContext context)
}
}

// TODO: Remove the below suppression once the following Roslyn bug is fixed: https://github.com/dotnet/roslyn/issues/8884
#pragma warning disable CA1801
private void AnalyzerParameterSyntax(SyntaxNodeAnalysisContext context)
#pragma warning restore CA1801
{
if (context.SemanticModel.GetDeclaredSymbol(context.Node, context.CancellationToken) is IParameterSymbol parameter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ private string GetSiblingNamesToRemoveFromUnshippedText(ISymbol symbol)
}
}

// TODO: Remove the below suppression once the following Roslyn bug is fixed: https://github.com/dotnet/roslyn/issues/8884
#pragma warning disable CA1801
private string GetSiblingNamesToRemoveFromUnshippedTextCore(ISymbol symbol)
#pragma warning restore CA1801
{
// Compute all sibling names that must be removed from unshipped text, as they are no longer public or have been changed.
if (symbol.ContainingSymbol is INamespaceOrTypeSymbol containingSymbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ protected bool ShouldAnalyzeArrayCreationExpression(SyntaxNode expression, Seman
arrayType.Rank == 1;
}

// TODO: Remove the below suppression once the following Roslyn bug is fixed: https://github.com/dotnet/roslyn/issues/8884
#pragma warning disable CA1801
protected void AnalyzeMemberAccessName(SyntaxNode name, SemanticModel semanticModel, Action<Diagnostic> addDiagnostic)
#pragma warning restore CA1801
{
if (semanticModel.GetSymbolInfo(name).Symbol is IMethodSymbol methodSymbol &&
methodSymbol.OriginalDefinition == _genericEmptyEnumerableSymbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ private FixResolution TryGetFixResolution(SyntaxNode binaryExpressionSyntax, Sem
return null;
}

// TODO: Remove the below suppression once the following Roslyn bug is fixed: https://github.com/dotnet/roslyn/issues/8884
#pragma warning disable CA1801
private ITypeSymbol TryGetSystemTypeForNanConstantExpression(SyntaxNode expressionSyntax, SemanticModel model, INamedTypeSymbol systemSingleType, INamedTypeSymbol systemDoubleType)
#pragma warning restore CA1801
{
if (model.GetSymbolInfo(expressionSyntax).Symbol is IFieldSymbol fieldSymbol)
{
Expand Down

0 comments on commit 9baeaad

Please sign in to comment.