mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Cleanup
This commit is contained in:
@@ -71,10 +71,9 @@ internal partial class CommandOptionSymbol
|
||||
{
|
||||
var attribute = TryGetOptionAttribute(property);
|
||||
|
||||
if (attribute is null)
|
||||
return null;
|
||||
|
||||
return FromAttribute(attribute);
|
||||
return attribute is not null
|
||||
? FromAttribute(attribute)
|
||||
: null;
|
||||
}
|
||||
|
||||
public static bool IsOptionProperty(IPropertySymbol property) =>
|
||||
|
||||
@@ -10,9 +10,9 @@ internal partial class CommandParameterSymbol
|
||||
public int Order { get; }
|
||||
|
||||
public string? Name { get; }
|
||||
|
||||
|
||||
public bool? IsRequired { get; }
|
||||
|
||||
|
||||
public ITypeSymbol? ConverterType { get; }
|
||||
|
||||
public IReadOnlyList<ITypeSymbol> ValidatorTypes { get; }
|
||||
@@ -41,7 +41,7 @@ internal partial class CommandParameterSymbol
|
||||
|
||||
private static CommandParameterSymbol FromAttribute(AttributeData attribute)
|
||||
{
|
||||
var order = (int) attribute
|
||||
var order = (int)attribute
|
||||
.ConstructorArguments
|
||||
.Select(a => a.Value)
|
||||
.First()!;
|
||||
@@ -51,7 +51,7 @@ internal partial class CommandParameterSymbol
|
||||
.Where(a => a.Key == "Name")
|
||||
.Select(a => a.Value.Value)
|
||||
.FirstOrDefault() as string;
|
||||
|
||||
|
||||
var isRequired = attribute
|
||||
.NamedArguments
|
||||
.Where(a => a.Key == "IsRequired")
|
||||
|
||||
@@ -12,8 +12,8 @@ public class ParameterMustBeLastIfNonScalarAnalyzer : AnalyzerBase
|
||||
{
|
||||
public ParameterMustBeLastIfNonScalarAnalyzer()
|
||||
: base(
|
||||
"Parameters of non-scalar types must be last in order",
|
||||
"This parameter has a non-scalar type so it must be last in order (its order must be highest within the command).")
|
||||
"Parameters of non-scalar types must be the last in order",
|
||||
"This parameter has a non-scalar type so it must be the last in order (its order must be highest within the command).")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
@@ -13,8 +12,8 @@ public class ParameterMustBeLastIfNotRequiredAnalyzer : AnalyzerBase
|
||||
{
|
||||
public ParameterMustBeLastIfNotRequiredAnalyzer()
|
||||
: base(
|
||||
"Only last parameter can be optional",
|
||||
"IsRequired can only be set to false on the last parameter.")
|
||||
"Parameters marked as non-required must be the last in order",
|
||||
"This parameter is non-required so it must be the last in order (its order must be highest within the command).")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,10 +26,12 @@ public class ParameterMustBeLastIfNotRequiredAnalyzer : AnalyzerBase
|
||||
return;
|
||||
|
||||
var parameter = CommandParameterSymbol.TryResolve(property);
|
||||
|
||||
if (parameter is null || parameter.IsRequired != false)
|
||||
if (parameter is null)
|
||||
return;
|
||||
|
||||
|
||||
if (parameter.IsRequired != false)
|
||||
return;
|
||||
|
||||
var otherProperties = property
|
||||
.ContainingType
|
||||
.GetMembers()
|
||||
@@ -44,7 +45,7 @@ public class ParameterMustBeLastIfNotRequiredAnalyzer : AnalyzerBase
|
||||
if (otherParameter is null)
|
||||
continue;
|
||||
|
||||
if (parameter.IsRequired is false && parameter.Order < otherParameter.Order)
|
||||
if (otherParameter.Order > parameter.Order)
|
||||
{
|
||||
context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user