mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Add analyzers for invalid validators
This commit is contained in:
@@ -164,6 +164,30 @@ public class MyCommand : ICommand
|
||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||
public string Param { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
new AnalyzerTestCase(
|
||||
"Parameter with valid validator",
|
||||
Analyzer.SupportedDiagnostics,
|
||||
|
||||
// language=cs
|
||||
@"
|
||||
public class MyValidator : ArgumentValueValidator<string>
|
||||
{
|
||||
public ValidationResult Validate(string value) => ValidationResult.Ok();
|
||||
}
|
||||
|
||||
[Command]
|
||||
public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
||||
public string Param { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
@@ -292,6 +316,30 @@ public class MyCommand : ICommand
|
||||
[CommandOption('o', Converter = typeof(MyConverter))]
|
||||
public string Option { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
new AnalyzerTestCase(
|
||||
"Option with valid validator",
|
||||
Analyzer.SupportedDiagnostics,
|
||||
|
||||
// language=cs
|
||||
@"
|
||||
public class MyValidator : ArgumentValueValidator<string>
|
||||
{
|
||||
public ValidationResult Validate(string value) => ValidationResult.Ok();
|
||||
}
|
||||
|
||||
[Command]
|
||||
public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('o', Validators = new[] {typeof(MyValidator)})]
|
||||
public string Option { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
@@ -438,6 +486,30 @@ public class MyCommand : ICommand
|
||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||
public string Param { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
new AnalyzerTestCase(
|
||||
"Parameter with invalid validator",
|
||||
DiagnosticDescriptors.CliFx0026,
|
||||
|
||||
// language=cs
|
||||
@"
|
||||
public class MyValidator
|
||||
{
|
||||
public ValidationResult Validate(string value) => ValidationResult.Ok();
|
||||
}
|
||||
|
||||
[Command]
|
||||
public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
||||
public string Param { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
@@ -566,6 +638,30 @@ public class MyCommand : ICommand
|
||||
[CommandOption('o', Converter = typeof(MyConverter))]
|
||||
public string Option { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
new AnalyzerTestCase(
|
||||
"Option with invalid validator",
|
||||
DiagnosticDescriptors.CliFx0047,
|
||||
|
||||
// language=cs
|
||||
@"
|
||||
public class MyValidator
|
||||
{
|
||||
public ValidationResult Validate(string value) => ValidationResult.Ok();
|
||||
}
|
||||
|
||||
[Command]
|
||||
public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('o', Validators = new[] {typeof(MyValidator)})]
|
||||
public string Option { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user