Fix warnings in analyzer packages (#24837)

This commit is contained in:
Youssef Victor 2020-08-13 23:49:47 +02:00 committed by GitHub
parent aab95eadc9
commit 60cb3bb5c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 26 additions and 22 deletions

View File

@ -100,9 +100,6 @@
<!-- xUnit1004 = warns about skipped tests. Make this a non-fatal build warning. -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);xUnit1004</WarningsNotAsErrors>
<!-- Ignore specific Roslyn warnings for now, https://github.com/dotnet/aspnetcore/issues/22090 -->
<NoWarn Condition="'$(IsAnalyzersProject)' == 'true'">$(NoWarn);RS1024;RS1025;RS1026</NoWarn>
</PropertyGroup>
<!-- Source code settings -->

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Components.Analyzers
return property.GetAttributes().Any(a =>
{
return a.AttributeClass == symbols.ParameterAttribute || a.AttributeClass == symbols.CascadingParameterAttribute;
return SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.ParameterAttribute) || SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.CascadingParameterAttribute);
});
}
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Components.Analyzers
throw new ArgumentNullException(nameof(property));
}
return property.GetAttributes().Any(a => a.AttributeClass == symbols.ParameterAttribute);
return property.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.ParameterAttribute));
}
public static bool IsParameterWithCaptureUnmatchedValues(ComponentSymbols symbols, IPropertySymbol property)
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Components.Analyzers
throw new ArgumentNullException(nameof(property));
}
var attribute = property.GetAttributes().FirstOrDefault(a => a.AttributeClass == symbols.ParameterAttribute);
var attribute = property.GetAttributes().FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.ParameterAttribute));
if (attribute == null)
{
return false;
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Components.Analyzers
throw new ArgumentNullException(nameof(property));
}
return property.GetAttributes().Any(a => a.AttributeClass == symbols.CascadingParameterAttribute);
return property.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.CascadingParameterAttribute));
}
public static bool IsComponent(ComponentSymbols symbols, Compilation compilation, INamedTypeSymbol type)

View File

@ -30,6 +30,7 @@ namespace Microsoft.Extensions.Internal
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
_inner.Register(context);

View File

@ -29,6 +29,8 @@ namespace Microsoft.AspNetCore.Components.Analyzers
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(context =>
{
if (!ComponentSymbols.TryCreate(context.Compilation, out var symbols))

View File

@ -25,6 +25,7 @@ namespace Microsoft.AspNetCore.Components.Analyzers
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(context =>
{

View File

@ -126,7 +126,7 @@ namespace Microsoft.Extensions.Internal
// Similar logic here to VisitDeclarationSymbol, keep these in sync.
private void VisitOperationSymbol(OperationAnalysisContext context, ISymbol symbol)
{
if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly)
if (symbol == null || SymbolEqualityComparer.Default.Equals(symbol.ContainingAssembly, context.Compilation.Assembly))
{
// The type is being referenced within the same assembly. This is valid use of an "internal" type
return;
@ -155,7 +155,7 @@ namespace Microsoft.Extensions.Internal
// Similar logic here to VisitOperationSymbol, keep these in sync.
private void VisitDeclarationSymbol(SymbolAnalysisContext context, ISymbol symbol, ISymbol symbolForDiagnostic)
{
if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly)
if (symbol == null || SymbolEqualityComparer.Default.Equals(symbol.ContainingAssembly, context.Compilation.Assembly))
{
// This is part of the compilation, avoid this analyzer when building from source.
return;

View File

@ -97,7 +97,7 @@ namespace Microsoft.CodeAnalysis
source = source ?? throw new ArgumentNullException(nameof(source));
target = target ?? throw new ArgumentNullException(nameof(target));
if (source == target)
if (SymbolEqualityComparer.Default.Equals(source, target))
{
return true;
}
@ -106,7 +106,7 @@ namespace Microsoft.CodeAnalysis
{
foreach (var @interface in target.AllInterfaces)
{
if (source == @interface)
if (SymbolEqualityComparer.Default.Equals(source, @interface))
{
return true;
}
@ -117,7 +117,7 @@ namespace Microsoft.CodeAnalysis
foreach (var type in target.GetTypeHierarchy())
{
if (source == type)
if (SymbolEqualityComparer.Default.Equals(source, type))
{
return true;
}

View File

@ -141,7 +141,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
}
var implementedMethod = method.ContainingType.FindImplementationForInterfaceMember(disposableDispose);
return implementedMethod == method;
return SymbolEqualityComparer.Default.Equals(implementedMethod, method);
}
}
}

View File

@ -24,6 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
// Generated Razor code is considered auto generated. By default analyzers skip over auto-generated code unless we say otherwise.
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(context =>
@ -105,7 +106,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
private bool IsTagHelperRunnerRunAsync(IMethodSymbol method, SymbolCache symbolCache)
{
if (method != symbolCache.TagHelperRunnerRunAsyncMethodSymbol)
if (!SymbolEqualityComparer.Default.Equals(method, symbolCache.TagHelperRunnerRunAsyncMethodSymbol))
{
return false;
}

View File

@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
foreach (var attribute in symbol.GetAttributes(symbolCache.IModelNameProvider))
{
// BindAttribute uses the Prefix property as an alias for IModelNameProvider.Name
var nameProperty = attribute.AttributeClass == symbolCache.BindAttribute ? "Prefix" : "Name";
var nameProperty = SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, symbolCache.BindAttribute) ? "Prefix" : "Name";
// All of the built-in attributes (FromQueryAttribute, ModelBinderAttribute etc) only support setting the name via
// a property. We'll ignore constructor values.

View File

@ -21,6 +21,8 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
public sealed override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(compilationContext =>
{
var analyzerContext = new ViewFeaturesAnalyzerContext(compilationContext);

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
return false;
}
if (method.ContainingType != HtmlHelperPartialExtensionsType)
if (!SymbolEqualityComparer.Default.Equals(method.ContainingType, HtmlHelperPartialExtensionsType))
{
return false;
}

View File

@ -281,14 +281,14 @@ namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
for (var i = 0; i < property.ExplicitInterfaceImplementations.Length; i++)
{
if (property.ExplicitInterfaceImplementations[i] == statusCodeActionResultStatusProperty)
if (SymbolEqualityComparer.Default.Equals(property.ExplicitInterfaceImplementations[i], statusCodeActionResultStatusProperty))
{
return true;
}
}
var implementedProperty = property.ContainingType.FindImplementationForInterfaceMember(statusCodeActionResultStatusProperty);
return implementedProperty == property;
return SymbolEqualityComparer.Default.Equals(implementedProperty, property);
}
private static bool HasAttributeNamed(ISymbol symbol, string attributeName)

View File

@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
AttributeSyntax attributeSyntax;
bool addUsing;
if (statusCode >= 400 && returnType != null && returnType != errorResponseType)
if (statusCode >= 400 && returnType != null && !SymbolEqualityComparer.Default.Equals(returnType, errorResponseType))
{
// If a returnType was discovered and is different from the errorResponseType, use it in the result.
attributeSyntax = CreateProducesResponseTypeAttribute(context, statusCode, returnType, out addUsing);
@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
addUsingDirective |= addUsing;
}
if (!declaredResponseMetadata.Any(m => m.IsDefault && m.AttributeSource == context.Method))
if (!declaredResponseMetadata.Any(m => m.IsDefault && SymbolEqualityComparer.Default.Equals(m.AttributeSource, context.Method)))
{
// Add a ProducesDefaultResponseTypeAttribute if the method does not already have one.
documentEditor.AddAttribute(context.MethodSyntax, CreateProducesDefaultResponseTypeAttribute());
@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
foreach (var metadata in actualResponseMetadata)
{
if (DeclaredApiResponseMetadata.TryGetDeclaredMetadata(declaredResponseMetadata, metadata, result: out var declaredMetadata) &&
declaredMetadata.AttributeSource == context.Method)
SymbolEqualityComparer.Default.Equals(declaredMetadata.AttributeSource, context.Method))
{
// A ProducesResponseType attribute is declared on the method for the current status code.
continue;

View File

@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
return false;
}
if (propertyReference.Member.ContainingType != symbolCache.ModelStateDictionary)
if (!SymbolEqualityComparer.Default.Equals(propertyReference.Member.ContainingType, symbolCache.ModelStateDictionary))
{
return false;
}