Fix converter analyzer false positive when handling non-scalars or nullable types

This commit is contained in:
Oleksii Holub
2022-04-20 20:09:14 +03:00
parent 7f206a0c77
commit 864efd3179
14 changed files with 205 additions and 75 deletions

View File

@@ -17,13 +17,6 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase
{
}
private static bool IsScalar(ITypeSymbol type) =>
type.DisplayNameMatches("string") ||
type.DisplayNameMatches("System.String") ||
!type.AllInterfaces
.Select(i => i.ConstructedFrom)
.Any(t => t.DisplayNameMatches("System.Collections.Generic.IEnumerable<T>"));
private void Analyze(
SyntaxNodeAnalysisContext context,
PropertyDeclarationSyntax propertyDeclaration,
@@ -32,10 +25,11 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase
if (property.ContainingType is null)
return;
if (!CommandParameterSymbol.IsParameterProperty(property))
var parameter = CommandParameterSymbol.TryResolve(property);
if (parameter is null)
return;
if (IsScalar(property.Type))
if (parameter.IsScalar())
return;
var otherProperties = property
@@ -47,10 +41,11 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase
foreach (var otherProperty in otherProperties)
{
if (!CommandParameterSymbol.IsParameterProperty(otherProperty))
var otherParameter = CommandParameterSymbol.TryResolve(otherProperty);
if (otherParameter is null)
continue;
if (!IsScalar(otherProperty.Type))
if (!otherParameter.IsScalar())
{
context.ReportDiagnostic(
CreateDiagnostic(propertyDeclaration.Identifier.GetLocation())