You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +00:00
Clean diagnostic rules
Move the following diagnostics into static readonly fields: GD0101, GD0102, GD0103, GD0104, GD0105, GD0106, GD0107, GD0201, GD0202, GD0203, GD0301, GD0302, GD0303, GD0401, GD0402. To be more consistent, the titles for the following diagnostics were modified: GD0101, GD0105, GD0106, GD0302, GD0303, GD0401, GD0402. A subsequent update of the documentation repo is needed. Tests for the following diagnostics were created: GD0201, GD0202, GD0203.
This commit is contained in:
@@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.Diagnostics;
|
||||
namespace Godot.SourceGenerators
|
||||
{
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public class MustBeVariantAnalyzer : DiagnosticAnalyzer
|
||||
public sealed class MustBeVariantAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
|
||||
=> ImmutableArray.Create(
|
||||
@@ -62,7 +62,11 @@ namespace Godot.SourceGenerators
|
||||
{
|
||||
if (!typeParamSymbol.GetAttributes().Any(a => a.AttributeClass?.IsGodotMustBeVariantAttribute() ?? false))
|
||||
{
|
||||
Common.ReportGenericTypeParameterMustBeVariantAnnotated(context, typeSyntax, typeSymbol);
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.GenericTypeParameterMustBeVariantAnnotatedRule,
|
||||
typeSyntax.GetLocation(),
|
||||
typeSymbol.ToDisplayString()
|
||||
));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -71,8 +75,11 @@ namespace Godot.SourceGenerators
|
||||
|
||||
if (marshalType is null)
|
||||
{
|
||||
Common.ReportGenericTypeArgumentMustBeVariant(context, typeSyntax, typeSymbol);
|
||||
continue;
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.GenericTypeArgumentMustBeVariantRule,
|
||||
typeSyntax.GetLocation(),
|
||||
typeSymbol.ToDisplayString()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,8 +113,15 @@ namespace Godot.SourceGenerators
|
||||
/// <param name="parentSymbol">The symbol retrieved for the parent node syntax.</param>
|
||||
/// <param name="typeArgumentSyntax">The type node syntax of the argument type to check.</param>
|
||||
/// <param name="typeArgumentSymbol">The symbol retrieved for the type node syntax.</param>
|
||||
/// <param name="typeArgumentIndex"></param>
|
||||
/// <returns><see langword="true"/> if the type must be variant and must be analyzed.</returns>
|
||||
private bool ShouldCheckTypeArgument(SyntaxNodeAnalysisContext context, SyntaxNode parentSyntax, ISymbol parentSymbol, TypeSyntax typeArgumentSyntax, ITypeSymbol typeArgumentSymbol, int typeArgumentIndex)
|
||||
private bool ShouldCheckTypeArgument(
|
||||
SyntaxNodeAnalysisContext context,
|
||||
SyntaxNode parentSyntax,
|
||||
ISymbol parentSymbol,
|
||||
TypeSyntax typeArgumentSyntax,
|
||||
ITypeSymbol typeArgumentSymbol,
|
||||
int typeArgumentIndex)
|
||||
{
|
||||
ITypeParameterSymbol? typeParamSymbol = parentSymbol switch
|
||||
{
|
||||
@@ -120,18 +134,24 @@ namespace Godot.SourceGenerators
|
||||
|
||||
INamedTypeSymbol { TypeParameters.Length: > 0 } typeSymbol
|
||||
=> typeSymbol.TypeParameters[typeArgumentIndex],
|
||||
|
||||
_
|
||||
=> null
|
||||
};
|
||||
|
||||
if (typeParamSymbol == null)
|
||||
if (typeParamSymbol != null)
|
||||
{
|
||||
Common.ReportTypeArgumentParentSymbolUnhandled(context, typeArgumentSyntax, parentSymbol);
|
||||
return false;
|
||||
return typeParamSymbol.GetAttributes()
|
||||
.Any(a => a.AttributeClass?.IsGodotMustBeVariantAttribute() ?? false);
|
||||
}
|
||||
|
||||
return typeParamSymbol.GetAttributes()
|
||||
.Any(a => a.AttributeClass?.IsGodotMustBeVariantAttribute() ?? false);
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
Common.TypeArgumentParentSymbolUnhandledRule,
|
||||
typeArgumentSyntax.GetLocation(),
|
||||
parentSymbol.ToDisplayString()
|
||||
));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user