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 OptionMustHaveValidValidatorsAnalyzer : AnalyzerBase
public OptionMustHaveValidValidatorsAnalyzer()
: base(
$"Option validators must derive from `{SymbolNames.CliFxBindingValidatorClass}`",
$"Each validator specified for this option must derive from a compatible `{SymbolNames.CliFxBindingValidatorClass}`.")
{
}
$"Each validator specified for this option must derive from a compatible `{SymbolNames.CliFxBindingValidatorClass}`."
) { }
private void Analyze(
SyntaxNodeAnalysisContext context,
PropertyDeclarationSyntax propertyDeclaration,
IPropertySymbol property)
IPropertySymbol property
)
{
var option = CommandOptionSymbol.TryResolve(property);
if (option is null)
@@ -30,14 +30,16 @@ public class OptionMustHaveValidValidatorsAnalyzer : AnalyzerBase
{
var validatorValueType = validatorType
.GetBaseTypes()
.FirstOrDefault(t => t.ConstructedFrom.DisplayNameMatches(SymbolNames.CliFxBindingValidatorClass))?
.TypeArguments
.FirstOrDefault();
.FirstOrDefault(
t =>
t.ConstructedFrom.DisplayNameMatches(SymbolNames.CliFxBindingValidatorClass)
)
?.TypeArguments.FirstOrDefault();
// Value passed to the validator must be assignable from the property type
var isCompatible =
validatorValueType is not null &&
context.Compilation.IsAssignable(property.Type, validatorValueType);
validatorValueType is not null
&& context.Compilation.IsAssignable(property.Type, validatorValueType);
if (!isCompatible)
{
@@ -56,4 +58,4 @@ public class OptionMustHaveValidValidatorsAnalyzer : AnalyzerBase
base.Initialize(context);
context.HandlePropertyDeclaration(Analyze);
}
}
}