Use CSharpier

This commit is contained in:
Tyrrrz
2023-08-22 21:20:04 +03:00
parent a4726fcefd
commit 21b601da66
99 changed files with 975 additions and 1163 deletions

View File

@@ -13,14 +13,14 @@ public class CommandMustBeAnnotatedAnalyzer : AnalyzerBase
public CommandMustBeAnnotatedAnalyzer()
: base(
$"Commands must be annotated with `{SymbolNames.CliFxCommandAttribute}`",
$"This type must be annotated with `{SymbolNames.CliFxCommandAttribute}` in order to be a valid command.")
{
}
$"This type must be annotated with `{SymbolNames.CliFxCommandAttribute}` in order to be a valid command."
) { }
private void Analyze(
SyntaxNodeAnalysisContext context,
ClassDeclarationSyntax classDeclaration,
ITypeSymbol type)
ITypeSymbol type
)
{
// Ignore abstract classes, because they may be used to define
// base implementations for commands, in which case the command
@@ -28,12 +28,11 @@ public class CommandMustBeAnnotatedAnalyzer : AnalyzerBase
if (type.IsAbstract)
return;
var implementsCommandInterface = type
.AllInterfaces
.Any(i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface));
var implementsCommandInterface = type.AllInterfaces.Any(
i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface)
);
var hasCommandAttribute = type
.GetAttributes()
var hasCommandAttribute = type.GetAttributes()
.Select(a => a.AttributeClass)
.Any(c => c.DisplayNameMatches(SymbolNames.CliFxCommandAttribute));
@@ -41,9 +40,7 @@ public class CommandMustBeAnnotatedAnalyzer : AnalyzerBase
// then it's very likely a user error.
if (implementsCommandInterface && !hasCommandAttribute)
{
context.ReportDiagnostic(
CreateDiagnostic(classDeclaration.Identifier.GetLocation())
);
context.ReportDiagnostic(CreateDiagnostic(classDeclaration.Identifier.GetLocation()));
}
}
@@ -52,4 +49,4 @@ public class CommandMustBeAnnotatedAnalyzer : AnalyzerBase
base.Initialize(context);
context.HandleClassDeclaration(Analyze);
}
}
}