Skip to content

Commit 60cb3bb

Browse files
authored
Fix warnings in analyzer packages (#24837)
1 parent aab95ea commit 60cb3bb

15 files changed

+26
-22
lines changed

Directory.Build.props

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@
100100

101101
<!-- xUnit1004 = warns about skipped tests. Make this a non-fatal build warning. -->
102102
<WarningsNotAsErrors>$(WarningsNotAsErrors);xUnit1004</WarningsNotAsErrors>
103-
104-
<!-- Ignore specific Roslyn warnings for now, https://github.com/dotnet/aspnetcore/issues/22090 -->
105-
<NoWarn Condition="'$(IsAnalyzersProject)' == 'true'">$(NoWarn);RS1024;RS1025;RS1026</NoWarn>
106103
</PropertyGroup>
107104

108105
<!-- Source code settings -->

src/Components/Analyzers/src/ComponentFacts.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static bool IsAnyParameter(ComponentSymbols symbols, IPropertySymbol prop
2424

2525
return property.GetAttributes().Any(a =>
2626
{
27-
return a.AttributeClass == symbols.ParameterAttribute || a.AttributeClass == symbols.CascadingParameterAttribute;
27+
return SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.ParameterAttribute) || SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.CascadingParameterAttribute);
2828
});
2929
}
3030

@@ -40,7 +40,7 @@ public static bool IsParameter(ComponentSymbols symbols, IPropertySymbol propert
4040
throw new ArgumentNullException(nameof(property));
4141
}
4242

43-
return property.GetAttributes().Any(a => a.AttributeClass == symbols.ParameterAttribute);
43+
return property.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.ParameterAttribute));
4444
}
4545

4646
public static bool IsParameterWithCaptureUnmatchedValues(ComponentSymbols symbols, IPropertySymbol property)
@@ -55,7 +55,7 @@ public static bool IsParameterWithCaptureUnmatchedValues(ComponentSymbols symbol
5555
throw new ArgumentNullException(nameof(property));
5656
}
5757

58-
var attribute = property.GetAttributes().FirstOrDefault(a => a.AttributeClass == symbols.ParameterAttribute);
58+
var attribute = property.GetAttributes().FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.ParameterAttribute));
5959
if (attribute == null)
6060
{
6161
return false;
@@ -84,7 +84,7 @@ public static bool IsCascadingParameter(ComponentSymbols symbols, IPropertySymbo
8484
throw new ArgumentNullException(nameof(property));
8585
}
8686

87-
return property.GetAttributes().Any(a => a.AttributeClass == symbols.CascadingParameterAttribute);
87+
return property.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, symbols.CascadingParameterAttribute));
8888
}
8989

9090
public static bool IsComponent(ComponentSymbols symbols, Compilation compilation, INamedTypeSymbol type)

src/Components/Analyzers/src/ComponentInternalUsageDiagnosticAnalzyer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public ComponentInternalUsageDiagnosticAnalyzer()
3030

3131
public override void Initialize(AnalysisContext context)
3232
{
33+
context.EnableConcurrentExecution();
3334
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
3435

3536
_inner.Register(context);

src/Components/Analyzers/src/ComponentParameterAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public ComponentParameterAnalyzer()
2929

3030
public override void Initialize(AnalysisContext context)
3131
{
32+
context.EnableConcurrentExecution();
33+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
3234
context.RegisterCompilationStartAction(context =>
3335
{
3436
if (!ComponentSymbols.TryCreate(context.Compilation, out var symbols))

src/Components/Analyzers/src/ComponentParameterUsageAnalyzer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public ComponentParameterUsageAnalyzer()
2525

2626
public override void Initialize(AnalysisContext context)
2727
{
28+
context.EnableConcurrentExecution();
2829
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
2930
context.RegisterCompilationStartAction(context =>
3031
{

src/Components/Analyzers/src/InternalUsageAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void AnalyzeSymbol(SymbolAnalysisContext context)
126126
// Similar logic here to VisitDeclarationSymbol, keep these in sync.
127127
private void VisitOperationSymbol(OperationAnalysisContext context, ISymbol symbol)
128128
{
129-
if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly)
129+
if (symbol == null || SymbolEqualityComparer.Default.Equals(symbol.ContainingAssembly, context.Compilation.Assembly))
130130
{
131131
// The type is being referenced within the same assembly. This is valid use of an "internal" type
132132
return;
@@ -155,7 +155,7 @@ private void VisitOperationSymbol(OperationAnalysisContext context, ISymbol symb
155155
// Similar logic here to VisitOperationSymbol, keep these in sync.
156156
private void VisitDeclarationSymbol(SymbolAnalysisContext context, ISymbol symbol, ISymbol symbolForDiagnostic)
157157
{
158-
if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly)
158+
if (symbol == null || SymbolEqualityComparer.Default.Equals(symbol.ContainingAssembly, context.Compilation.Assembly))
159159
{
160160
// This is part of the compilation, avoid this analyzer when building from source.
161161
return;

src/Mvc/Mvc.Analyzers/src/CodeAnalysisExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static bool IsAssignableFrom(this ITypeSymbol source, ITypeSymbol target)
9797
source = source ?? throw new ArgumentNullException(nameof(source));
9898
target = target ?? throw new ArgumentNullException(nameof(target));
9999

100-
if (source == target)
100+
if (SymbolEqualityComparer.Default.Equals(source, target))
101101
{
102102
return true;
103103
}
@@ -106,7 +106,7 @@ public static bool IsAssignableFrom(this ITypeSymbol source, ITypeSymbol target)
106106
{
107107
foreach (var @interface in target.AllInterfaces)
108108
{
109-
if (source == @interface)
109+
if (SymbolEqualityComparer.Default.Equals(source, @interface))
110110
{
111111
return true;
112112
}
@@ -117,7 +117,7 @@ public static bool IsAssignableFrom(this ITypeSymbol source, ITypeSymbol target)
117117

118118
foreach (var type in target.GetTypeHierarchy())
119119
{
120-
if (source == type)
120+
if (SymbolEqualityComparer.Default.Equals(source, type))
121121
{
122122
return true;
123123
}

src/Mvc/Mvc.Analyzers/src/MvcFacts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private static bool IsIDisposableDispose(IMethodSymbol method, IMethodSymbol dis
141141
}
142142

143143
var implementedMethod = method.ContainingType.FindImplementationForInterfaceMember(disposableDispose);
144-
return implementedMethod == method;
144+
return SymbolEqualityComparer.Default.Equals(implementedMethod, method);
145145
}
146146
}
147147
}

src/Mvc/Mvc.Analyzers/src/TagHelpersInCodeBlocksAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public TagHelpersInCodeBlocksAnalyzer()
2424

2525
public override void Initialize(AnalysisContext context)
2626
{
27+
context.EnableConcurrentExecution();
2728
// Generated Razor code is considered auto generated. By default analyzers skip over auto-generated code unless we say otherwise.
2829
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
2930
context.RegisterCompilationStartAction(context =>
@@ -105,7 +106,7 @@ private void InitializeWorker(CompilationStartAnalysisContext context, SymbolCac
105106

106107
private bool IsTagHelperRunnerRunAsync(IMethodSymbol method, SymbolCache symbolCache)
107108
{
108-
if (method != symbolCache.TagHelperRunnerRunAsyncMethodSymbol)
109+
if (!SymbolEqualityComparer.Default.Equals(method, symbolCache.TagHelperRunnerRunAsyncMethodSymbol))
109110
{
110111
return false;
111112
}

src/Mvc/Mvc.Analyzers/src/TopLevelParameterNameAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ internal static string GetName(in SymbolCache symbolCache, ISymbol symbol)
152152
foreach (var attribute in symbol.GetAttributes(symbolCache.IModelNameProvider))
153153
{
154154
// BindAttribute uses the Prefix property as an alias for IModelNameProvider.Name
155-
var nameProperty = attribute.AttributeClass == symbolCache.BindAttribute ? "Prefix" : "Name";
155+
var nameProperty = SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, symbolCache.BindAttribute) ? "Prefix" : "Name";
156156

157157
// All of the built-in attributes (FromQueryAttribute, ModelBinderAttribute etc) only support setting the name via
158158
// a property. We'll ignore constructor values.

src/Mvc/Mvc.Analyzers/src/ViewFeatureAnalyzerBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public ViewFeatureAnalyzerBase(DiagnosticDescriptor diagnosticDescriptor)
2121

2222
public sealed override void Initialize(AnalysisContext context)
2323
{
24+
context.EnableConcurrentExecution();
25+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
2426
context.RegisterCompilationStartAction(compilationContext =>
2527
{
2628
var analyzerContext = new ViewFeaturesAnalyzerContext(compilationContext);

src/Mvc/Mvc.Analyzers/src/ViewFeaturesAnalyzerContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public bool IsHtmlHelperExtensionMethod(IMethodSymbol method)
3232
return false;
3333
}
3434

35-
if (method.ContainingType != HtmlHelperPartialExtensionsType)
35+
if (!SymbolEqualityComparer.Default.Equals(method.ContainingType, HtmlHelperPartialExtensionsType))
3636
{
3737
return false;
3838
}

src/Mvc/Mvc.Api.Analyzers/src/ActualApiResponseMetadataFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ private static bool IsInterfaceImplementation(IPropertySymbol property, IPropert
281281

282282
for (var i = 0; i < property.ExplicitInterfaceImplementations.Length; i++)
283283
{
284-
if (property.ExplicitInterfaceImplementations[i] == statusCodeActionResultStatusProperty)
284+
if (SymbolEqualityComparer.Default.Equals(property.ExplicitInterfaceImplementations[i], statusCodeActionResultStatusProperty))
285285
{
286286
return true;
287287
}
288288
}
289289

290290
var implementedProperty = property.ContainingType.FindImplementationForInterfaceMember(statusCodeActionResultStatusProperty);
291-
return implementedProperty == property;
291+
return SymbolEqualityComparer.Default.Equals(implementedProperty, property);
292292
}
293293

294294
private static bool HasAttributeNamed(ISymbol symbol, string attributeName)

src/Mvc/Mvc.Api.Analyzers/src/AddResponseTypeAttributeCodeFixAction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
7272
AttributeSyntax attributeSyntax;
7373
bool addUsing;
7474

75-
if (statusCode >= 400 && returnType != null && returnType != errorResponseType)
75+
if (statusCode >= 400 && returnType != null && !SymbolEqualityComparer.Default.Equals(returnType, errorResponseType))
7676
{
7777
// If a returnType was discovered and is different from the errorResponseType, use it in the result.
7878
attributeSyntax = CreateProducesResponseTypeAttribute(context, statusCode, returnType, out addUsing);
@@ -86,7 +86,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
8686
addUsingDirective |= addUsing;
8787
}
8888

89-
if (!declaredResponseMetadata.Any(m => m.IsDefault && m.AttributeSource == context.Method))
89+
if (!declaredResponseMetadata.Any(m => m.IsDefault && SymbolEqualityComparer.Default.Equals(m.AttributeSource, context.Method)))
9090
{
9191
// Add a ProducesDefaultResponseTypeAttribute if the method does not already have one.
9292
documentEditor.AddAttribute(context.MethodSyntax, CreateProducesDefaultResponseTypeAttribute());
@@ -200,7 +200,7 @@ private static Dictionary<int, string> GetStatusCodeConstants(INamedTypeSymbol s
200200
foreach (var metadata in actualResponseMetadata)
201201
{
202202
if (DeclaredApiResponseMetadata.TryGetDeclaredMetadata(declaredResponseMetadata, metadata, result: out var declaredMetadata) &&
203-
declaredMetadata.AttributeSource == context.Method)
203+
SymbolEqualityComparer.Default.Equals(declaredMetadata.AttributeSource, context.Method))
204204
{
205205
// A ProducesResponseType attribute is declared on the method for the current status code.
206206
continue;

src/Mvc/Mvc.Api.Analyzers/src/ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private static bool IsModelStateIsValidPropertyAccessor(in ApiControllerSymbolCa
199199
return false;
200200
}
201201

202-
if (propertyReference.Member.ContainingType != symbolCache.ModelStateDictionary)
202+
if (!SymbolEqualityComparer.Default.Equals(propertyReference.Member.ContainingType, symbolCache.ModelStateDictionary))
203203
{
204204
return false;
205205
}

0 commit comments

Comments
 (0)