From 21b601da665589a190f40b70c4373c96344b482f Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:20:04 +0300 Subject: [PATCH] Use CSharpier --- .../CliFx.Analyzers.Tests.csproj | 1 + .../CommandMustBeAnnotatedAnalyzerSpecs.cs | 14 +- ...mandMustImplementInterfaceAnalyzerSpecs.cs | 14 +- CliFx.Analyzers.Tests/GeneralSpecs.cs | 7 +- .../OptionMustBeInsideCommandAnalyzerSpecs.cs | 14 +- ...RequiredIfPropertyRequiredAnalyzerSpecs.cs | 20 +- ...ionMustHaveNameOrShortNameAnalyzerSpecs.cs | 17 +- .../OptionMustHaveUniqueNameAnalyzerSpecs.cs | 14 +- ...ionMustHaveUniqueShortNameAnalyzerSpecs.cs | 20 +- ...tionMustHaveValidConverterAnalyzerSpecs.cs | 26 +- .../OptionMustHaveValidNameAnalyzerSpecs.cs | 17 +- ...tionMustHaveValidShortNameAnalyzerSpecs.cs | 17 +- ...ionMustHaveValidValidatorsAnalyzerSpecs.cs | 20 +- ...rameterMustBeInsideCommandAnalyzerSpecs.cs | 17 +- ...terMustBeLastIfNonRequiredAnalyzerSpecs.cs | 17 +- ...meterMustBeLastIfNonScalarAnalyzerSpecs.cs | 17 +- ...RequiredIfPropertyRequiredAnalyzerSpecs.cs | 20 +- ...rMustBeSingleIfNonRequiredAnalyzerSpecs.cs | 17 +- ...terMustBeSingleIfNonScalarAnalyzerSpecs.cs | 17 +- ...arameterMustHaveUniqueNameAnalyzerSpecs.cs | 11 +- ...rameterMustHaveUniqueOrderAnalyzerSpecs.cs | 14 +- ...eterMustHaveValidConverterAnalyzerSpecs.cs | 27 +- ...terMustHaveValidValidatorsAnalyzerSpecs.cs | 20 +- ...stemConsoleShouldBeAvoidedAnalyzerSpecs.cs | 23 +- .../Utils/AnalyzerAssertions.cs | 114 +++---- CliFx.Analyzers/AnalyzerBase.cs | 5 +- CliFx.Analyzers/CliFx.Analyzers.csproj | 1 + .../CommandMustBeAnnotatedAnalyzer.cs | 23 +- .../CommandMustImplementInterfaceAnalyzer.cs | 23 +- .../ObjectModel/CommandOptionSymbol.cs | 61 ++-- .../ObjectModel/CommandParameterSymbol.cs | 47 +-- .../ObjectModel/ICommandMemberSymbol.cs | 6 +- CliFx.Analyzers/ObjectModel/SymbolNames.cs | 5 +- .../OptionMustBeInsideCommandAnalyzer.cs | 17 +- ...ustBeRequiredIfPropertyRequiredAnalyzer.cs | 16 +- .../OptionMustHaveNameOrShortNameAnalyzer.cs | 10 +- .../OptionMustHaveUniqueNameAnalyzer.cs | 17 +- .../OptionMustHaveUniqueShortNameAnalyzer.cs | 17 +- .../OptionMustHaveValidConverterAnalyzer.cs | 37 ++- .../OptionMustHaveValidNameAnalyzer.cs | 17 +- .../OptionMustHaveValidShortNameAnalyzer.cs | 17 +- .../OptionMustHaveValidValidatorsAnalyzer.cs | 22 +- .../ParameterMustBeInsideCommandAnalyzer.cs | 17 +- ...arameterMustBeLastIfNonRequiredAnalyzer.cs | 15 +- .../ParameterMustBeLastIfNonScalarAnalyzer.cs | 15 +- ...ustBeRequiredIfPropertyRequiredAnalyzer.cs | 16 +- ...ameterMustBeSingleIfNonRequiredAnalyzer.cs | 15 +- ...arameterMustBeSingleIfNonScalarAnalyzer.cs | 15 +- .../ParameterMustHaveUniqueNameAnalyzer.cs | 25 +- .../ParameterMustHaveUniqueOrderAnalyzer.cs | 17 +- ...ParameterMustHaveValidConverterAnalyzer.cs | 37 ++- ...arameterMustHaveValidValidatorsAnalyzer.cs | 22 +- .../SystemConsoleShouldBeAvoidedAnalyzer.cs | 17 +- .../Utils/Extensions/RoslynExtensions.cs | 80 +++-- .../Utils/Extensions/StringExtensions.cs | 5 +- CliFx.Benchmarks/Benchmarks.CliFx.cs | 2 +- CliFx.Benchmarks/Benchmarks.Clipr.cs | 6 +- CliFx.Benchmarks/Benchmarks.Cocona.cs | 14 +- .../Benchmarks.CommandLineParser.cs | 6 +- CliFx.Benchmarks/Benchmarks.McMaster.cs | 2 +- CliFx.Benchmarks/Benchmarks.PowerArgs.cs | 6 +- .../Benchmarks.SystemCommandLine.cs | 17 +- CliFx.Benchmarks/Benchmarks.cs | 13 +- CliFx.Benchmarks/CliFx.Benchmarks.csproj | 1 + CliFx.Demo/CliFx.Demo.csproj | 1 + CliFx.Demo/Commands/BookAddCommand.cs | 36 +-- CliFx.Demo/Commands/BookCommand.cs | 2 +- CliFx.Demo/Commands/BookListCommand.cs | 2 +- CliFx.Demo/Commands/BookRemoveCommand.cs | 2 +- CliFx.Demo/Domain/Book.cs | 2 +- CliFx.Demo/Domain/Isbn.cs | 10 +- CliFx.Demo/Domain/Library.cs | 2 +- CliFx.Demo/Domain/LibraryProvider.cs | 8 +- CliFx.Demo/Program.cs | 2 +- CliFx.Demo/Utils/ConsoleExtensions.cs | 2 +- CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj | 4 + .../Commands/CancellationTestCommand.cs | 7 +- .../Commands/ConsoleTestCommand.cs | 2 +- .../Commands/EnvironmentTestCommand.cs | 2 +- CliFx.Tests.Dummy/Program.cs | 16 +- CliFx.Tests/ApplicationSpecs.cs | 25 +- CliFx.Tests/CancellationSpecs.cs | 35 +-- CliFx.Tests/CliFx.Tests.csproj | 1 + CliFx.Tests/ConsoleSpecs.cs | 15 +- CliFx.Tests/ConversionSpecs.cs | 100 ++----- CliFx.Tests/DirectivesSpecs.cs | 39 +-- CliFx.Tests/EnvironmentSpecs.cs | 38 +-- CliFx.Tests/ErrorReportingSpecs.cs | 33 +- CliFx.Tests/HelpTextSpecs.cs | 283 ++++++++++-------- CliFx.Tests/OptionBindingSpecs.cs | 133 ++------ CliFx.Tests/ParameterBindingSpecs.cs | 38 +-- CliFx.Tests/RoutingSpecs.cs | 10 +- CliFx.Tests/SpecsBase.cs | 5 +- CliFx.Tests/TypeActivationSpecs.cs | 6 +- CliFx.Tests/Utils/DynamicCommandBuilder.cs | 24 +- .../Utils/Extensions/AssertionExtensions.cs | 24 +- .../Utils/Extensions/ConsoleExtensions.cs | 7 +- CliFx.Tests/Utils/NoOpCommand.cs | 2 +- CliFx/CliFx.csproj | 1 + 99 files changed, 975 insertions(+), 1163 deletions(-) diff --git a/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj b/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj index 7c7b365..1ed73c5 100644 --- a/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj +++ b/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj @@ -11,6 +11,7 @@ + diff --git a/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs index f80ea01..1e90212 100644 --- a/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs @@ -13,8 +13,7 @@ public class CommandMustBeAnnotatedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyCommand : ICommand { public ValueTask ExecuteAsync(IConsole console) => default; @@ -30,8 +29,7 @@ public class CommandMustBeAnnotatedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public abstract class MyCommand : ICommand { @@ -48,8 +46,7 @@ public class CommandMustBeAnnotatedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public abstract class MyCommand : ICommand { public ValueTask ExecuteAsync(IConsole console) => default; @@ -65,8 +62,7 @@ public class CommandMustBeAnnotatedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class Foo { public int Bar { get; init; } = 5; @@ -76,4 +72,4 @@ public class CommandMustBeAnnotatedAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs index 1e14d1e..04d7f1c 100644 --- a/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class CommandMustImplementInterfaceAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new CommandMustImplementInterfaceAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new CommandMustImplementInterfaceAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_command_does_not_implement_ICommand_interface() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand { @@ -31,8 +31,7 @@ public class CommandMustImplementInterfaceAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -49,8 +48,7 @@ public class CommandMustImplementInterfaceAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class Foo { public int Bar { get; init; } = 5; @@ -60,4 +58,4 @@ public class CommandMustImplementInterfaceAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/GeneralSpecs.cs b/CliFx.Analyzers.Tests/GeneralSpecs.cs index 041b9a9..38d61b7 100644 --- a/CliFx.Analyzers.Tests/GeneralSpecs.cs +++ b/CliFx.Analyzers.Tests/GeneralSpecs.cs @@ -12,11 +12,10 @@ public class GeneralSpecs public void All_analyzers_have_unique_diagnostic_IDs() { // Arrange - var analyzers = typeof(AnalyzerBase) - .Assembly + var analyzers = typeof(AnalyzerBase).Assembly .GetTypes() .Where(t => !t.IsAbstract && t.IsAssignableTo(typeof(DiagnosticAnalyzer))) - .Select(t => (DiagnosticAnalyzer) Activator.CreateInstance(t)!) + .Select(t => (DiagnosticAnalyzer)Activator.CreateInstance(t)!) .ToArray(); // Act @@ -27,4 +26,4 @@ public class GeneralSpecs // Assert diagnosticIds.Should().OnlyHaveUniqueItems(); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs index 2099dce..97a5121 100644 --- a/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs @@ -13,8 +13,7 @@ public class OptionMustBeInsideCommandAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyClass { [CommandOption("foo")] @@ -31,8 +30,7 @@ public class OptionMustBeInsideCommandAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -52,8 +50,7 @@ public class OptionMustBeInsideCommandAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public abstract class MyCommand { [CommandOption("foo")] @@ -70,8 +67,7 @@ public class OptionMustBeInsideCommandAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -84,4 +80,4 @@ public class OptionMustBeInsideCommandAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs index e8393ef..f41468c 100644 --- a/CliFx.Analyzers.Tests/OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustBeRequiredIfPropertyRequiredAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new OptionMustBeRequiredIfPropertyRequiredAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_non_required_option_is_bound_to_a_required_property() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -34,8 +34,7 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -55,8 +54,7 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -76,8 +74,7 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -97,8 +94,7 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -111,4 +107,4 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs index 17ff457..e9fae73 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class OptionMustHaveNameOrShortNameAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustHaveNameOrShortNameAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new OptionMustHaveNameOrShortNameAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_an_option_does_not_have_a_name_or_short_name() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -34,8 +34,7 @@ public class OptionMustHaveNameOrShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -55,8 +54,7 @@ public class OptionMustHaveNameOrShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -76,8 +74,7 @@ public class OptionMustHaveNameOrShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -90,4 +87,4 @@ public class OptionMustHaveNameOrShortNameAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs index c122467..d242695 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs @@ -13,8 +13,7 @@ public class OptionMustHaveUniqueNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +36,7 @@ public class OptionMustHaveUniqueNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +59,7 @@ public class OptionMustHaveUniqueNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -82,8 +79,7 @@ public class OptionMustHaveUniqueNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -96,4 +92,4 @@ public class OptionMustHaveUniqueNameAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs index 860c564..8a09a1b 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class OptionMustHaveUniqueShortNameAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustHaveUniqueShortNameAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new OptionMustHaveUniqueShortNameAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_an_option_has_the_same_short_name_as_another_option() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +37,7 @@ public class OptionMustHaveUniqueShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +60,7 @@ public class OptionMustHaveUniqueShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -85,8 +83,7 @@ public class OptionMustHaveUniqueShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -106,8 +103,7 @@ public class OptionMustHaveUniqueShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -120,4 +116,4 @@ public class OptionMustHaveUniqueShortNameAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs index 78b8537..dc163ab 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class OptionMustHaveValidConverterAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustHaveValidConverterAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new OptionMustHaveValidConverterAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_an_option_has_a_converter_that_does_not_derive_from_BindingConverter() { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter { public string Convert(string? rawValue) => rawValue; @@ -39,8 +39,7 @@ public class OptionMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override int Convert(string? rawValue) => 42; @@ -65,8 +64,7 @@ public class OptionMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override string Convert(string? rawValue) => rawValue; @@ -91,8 +89,7 @@ public class OptionMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override int Convert(string? rawValue) => 42; @@ -117,8 +114,7 @@ public class OptionMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override string Convert(string? rawValue) => rawValue; @@ -143,8 +139,7 @@ public class OptionMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -164,8 +159,7 @@ public class OptionMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -178,4 +172,4 @@ public class OptionMustHaveValidConverterAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs index 1612446..f55e161 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs @@ -13,8 +13,7 @@ public class OptionMustHaveValidNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -34,8 +33,7 @@ public class OptionMustHaveValidNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -55,8 +53,7 @@ public class OptionMustHaveValidNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -76,8 +73,7 @@ public class OptionMustHaveValidNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -97,8 +93,7 @@ public class OptionMustHaveValidNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -111,4 +106,4 @@ public class OptionMustHaveValidNameAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs index a4fc58a..a086b40 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class OptionMustHaveValidShortNameAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustHaveValidShortNameAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new OptionMustHaveValidShortNameAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_an_option_has_a_short_name_which_is_not_a_letter_character() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -34,8 +34,7 @@ public class OptionMustHaveValidShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -55,8 +54,7 @@ public class OptionMustHaveValidShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -76,8 +74,7 @@ public class OptionMustHaveValidShortNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -90,4 +87,4 @@ public class OptionMustHaveValidShortNameAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs index 5224c00..9fcb78e 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class OptionMustHaveValidValidatorsAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new OptionMustHaveValidValidatorsAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new OptionMustHaveValidValidatorsAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_an_option_has_a_validator_that_does_not_derive_from_BindingValidator() { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyValidator { public void Validate(string value) {} @@ -39,8 +39,7 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyValidator : BindingValidator { public override BindingValidationError Validate(int value) => Ok(); @@ -65,8 +64,7 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyValidator : BindingValidator { public override BindingValidationError Validate(string value) => Ok(); @@ -91,8 +89,7 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -112,8 +109,7 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -126,4 +122,4 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs index 4ba69e3..b7b4b36 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustBeInsideCommandAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeInsideCommandAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustBeInsideCommandAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_parameter_is_inside_a_class_that_is_not_a_command() { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyClass { [CommandParameter(0)] @@ -31,8 +31,7 @@ public class ParameterMustBeInsideCommandAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -52,8 +51,7 @@ public class ParameterMustBeInsideCommandAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public abstract class MyCommand { [CommandParameter(0)] @@ -70,8 +68,7 @@ public class ParameterMustBeInsideCommandAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -84,4 +81,4 @@ public class ParameterMustBeInsideCommandAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs index 03f52b3..3f4bb66 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustBeLastIfNonRequiredAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeLastIfNonRequiredAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustBeLastIfNonRequiredAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_non_required_parameter_is_not_the_last_in_order() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +37,7 @@ public class ParameterMustBeLastIfNonRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +60,7 @@ public class ParameterMustBeLastIfNonRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -85,8 +83,7 @@ public class ParameterMustBeLastIfNonRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -99,4 +96,4 @@ public class ParameterMustBeLastIfNonRequiredAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs index dd5f208..abe13db 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustBeLastIfNonScalarAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeLastIfNonScalarAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustBeLastIfNonScalarAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_non_scalar_parameter_is_not_the_last_in_order() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +37,7 @@ public class ParameterMustBeLastIfNonScalarAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +60,7 @@ public class ParameterMustBeLastIfNonScalarAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -85,8 +83,7 @@ public class ParameterMustBeLastIfNonScalarAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -99,4 +96,4 @@ public class ParameterMustBeLastIfNonScalarAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs index 5bb42f7..fe2162f 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeRequiredIfPropertyRequiredAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustBeRequiredIfPropertyRequiredAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_non_required_parameter_is_bound_to_a_required_property() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -34,8 +34,7 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -55,8 +54,7 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -76,8 +74,7 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -97,8 +94,7 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -111,4 +107,4 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs index 074d152..5decbc1 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustBeSingleIfNonRequiredAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeSingleIfNonRequiredAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustBeSingleIfNonRequiredAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_more_than_one_non_required_parameters_are_defined() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +37,7 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +60,7 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -85,8 +83,7 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -99,4 +96,4 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs index 9fd29e6..be4bd76 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustBeSingleIfNonScalarAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeSingleIfNonScalarAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustBeSingleIfNonScalarAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_more_than_one_non_scalar_parameters_are_defined() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +37,7 @@ public class ParameterMustBeSingleIfNonScalarAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +60,7 @@ public class ParameterMustBeSingleIfNonScalarAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -85,8 +83,7 @@ public class ParameterMustBeSingleIfNonScalarAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -99,4 +96,4 @@ public class ParameterMustBeSingleIfNonScalarAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs index 02e588b..30fc5b9 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs @@ -13,8 +13,7 @@ public class ParameterMustHaveUniqueNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +36,7 @@ public class ParameterMustHaveUniqueNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +59,7 @@ public class ParameterMustHaveUniqueNameAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -75,4 +72,4 @@ public class ParameterMustHaveUniqueNameAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs index b7ceb08..1262046 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustHaveUniqueOrderAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustHaveUniqueOrderAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustHaveUniqueOrderAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_parameter_has_the_same_order_as_another_parameter() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -37,8 +37,7 @@ public class ParameterMustHaveUniqueOrderAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -61,8 +60,7 @@ public class ParameterMustHaveUniqueOrderAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -75,4 +73,4 @@ public class ParameterMustHaveUniqueOrderAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs index 21acce2..60a79b7 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustHaveValidConverterAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustHaveValidConverterAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustHaveValidConverterAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_parameter_has_a_converter_that_does_not_derive_from_BindingConverter() { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter { public string Convert(string? rawValue) => rawValue; @@ -39,8 +39,7 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override int Convert(string? rawValue) => 42; @@ -56,7 +55,6 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs } """; - // Act & assert Analyzer.Should().ProduceDiagnostics(code); } @@ -66,8 +64,7 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override string Convert(string? rawValue) => rawValue; @@ -92,8 +89,7 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override int Convert(string? rawValue) => 42; @@ -118,8 +114,7 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyConverter : BindingConverter { public override string Convert(string? rawValue) => rawValue; @@ -144,8 +139,7 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -165,8 +159,7 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -179,4 +172,4 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs index 098c5ea..778a702 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class ParameterMustHaveValidValidatorsAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustHaveValidValidatorsAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new ParameterMustHaveValidValidatorsAnalyzer(); [Fact] public void Analyzer_reports_an_error_a_parameter_has_a_validator_that_does_not_derive_from_BindingValidator() { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyValidator { public void Validate(string value) {} @@ -39,8 +39,7 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyValidator : BindingValidator { public override BindingValidationError Validate(int value) => Ok(); @@ -65,8 +64,7 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ public class MyValidator : BindingValidator { public override BindingValidationError Validate(string value) => Ok(); @@ -91,8 +89,7 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -112,8 +109,7 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -126,4 +122,4 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs index 3f0e657..8992c8e 100644 --- a/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs @@ -6,15 +6,15 @@ namespace CliFx.Analyzers.Tests; public class SystemConsoleShouldBeAvoidedAnalyzerSpecs { - private static DiagnosticAnalyzer Analyzer { get; } = new SystemConsoleShouldBeAvoidedAnalyzer(); + private static DiagnosticAnalyzer Analyzer { get; } = + new SystemConsoleShouldBeAvoidedAnalyzer(); [Fact] public void Analyzer_reports_an_error_if_a_command_calls_a_method_on_SystemConsole() { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -35,8 +35,7 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -57,8 +56,7 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -79,8 +77,7 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -101,8 +98,7 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -121,8 +117,7 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs { // Arrange // lang=csharp - const string code = - """ + const string code = """ [Command] public class MyCommand : ICommand { @@ -136,4 +131,4 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs // Act & assert Analyzer.Should().NotProduceDiagnostics(code); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs index 83df884..1fb1ef6 100644 --- a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs +++ b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs @@ -18,9 +18,7 @@ internal class AnalyzerAssertions : ReferenceTypeAssertions t.IsPublic) .Select(t => t.Namespace) @@ -43,10 +40,10 @@ internal class AnalyzerAssertions : ReferenceTypeAssertions $"using {n};")) + - string.Join(Environment.NewLine, defaultCliFxNamespaces.Select(n => $"using {n};")) + - Environment.NewLine + - sourceCode; + string.Join(Environment.NewLine, defaultSystemNamespaces.Select(n => $"using {n};")) + + string.Join(Environment.NewLine, defaultCliFxNamespaces.Select(n => $"using {n};")) + + Environment.NewLine + + sourceCode; // Parse the source code var ast = SyntaxFactory.ParseSyntaxTree( @@ -58,8 +55,9 @@ internal class AnalyzerAssertions : ReferenceTypeAssertions d.Id).Distinct().ToArray(); var isSuccessfulAssertion = - expectedDiagnosticIds.Intersect(producedDiagnosticIds).Count() == - expectedDiagnosticIds.Length; + expectedDiagnosticIds.Intersect(producedDiagnosticIds).Count() + == expectedDiagnosticIds.Length; - Execute.Assertion.ForCondition(isSuccessfulAssertion).FailWith(() => - { - var buffer = new StringBuilder(); - - buffer.AppendLine("Expected and produced diagnostics do not match."); - buffer.AppendLine(); - - buffer.AppendLine("Expected diagnostics:"); - - foreach (var expectedDiagnostic in expectedDiagnostics) + Execute.Assertion + .ForCondition(isSuccessfulAssertion) + .FailWith(() => { - buffer.Append(" - "); - buffer.Append(expectedDiagnostic.Id); + var buffer = new StringBuilder(); + + buffer.AppendLine("Expected and produced diagnostics do not match."); buffer.AppendLine(); - } - buffer.AppendLine(); + buffer.AppendLine("Expected diagnostics:"); - buffer.AppendLine("Produced diagnostics:"); - - if (producedDiagnostics.Any()) - { - foreach (var producedDiagnostic in producedDiagnostics) + foreach (var expectedDiagnostic in expectedDiagnostics) { buffer.Append(" - "); - buffer.Append(producedDiagnostic); + buffer.Append(expectedDiagnostic.Id); + buffer.AppendLine(); } - } - else - { - buffer.AppendLine(" < none >"); - } - return new FailReason(buffer.ToString()); - }); + buffer.AppendLine(); + + buffer.AppendLine("Produced diagnostics:"); + + if (producedDiagnostics.Any()) + { + foreach (var producedDiagnostic in producedDiagnostics) + { + buffer.Append(" - "); + buffer.Append(producedDiagnostic); + } + } + else + { + buffer.AppendLine(" < none >"); + } + + return new FailReason(buffer.ToString()); + }); } public void NotProduceDiagnostics(string sourceCode) @@ -148,27 +148,29 @@ internal class AnalyzerAssertions : ReferenceTypeAssertions - { - var buffer = new StringBuilder(); - - buffer.AppendLine("Expected no produced diagnostics."); - buffer.AppendLine(); - - buffer.AppendLine("Produced diagnostics:"); - - foreach (var producedDiagnostic in producedDiagnostics) + Execute.Assertion + .ForCondition(isSuccessfulAssertion) + .FailWith(() => { - buffer.Append(" - "); - buffer.Append(producedDiagnostic); - } + var buffer = new StringBuilder(); - return new FailReason(buffer.ToString()); - }); + buffer.AppendLine("Expected no produced diagnostics."); + buffer.AppendLine(); + + buffer.AppendLine("Produced diagnostics:"); + + foreach (var producedDiagnostic in producedDiagnostics) + { + buffer.Append(" - "); + buffer.Append(producedDiagnostic); + } + + return new FailReason(buffer.ToString()); + }); } } internal static class AnalyzerAssertionsExtensions { public static AnalyzerAssertions Should(this DiagnosticAnalyzer analyzer) => new(analyzer); -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/AnalyzerBase.cs b/CliFx.Analyzers/AnalyzerBase.cs index 3e5aced..c022ca0 100644 --- a/CliFx.Analyzers/AnalyzerBase.cs +++ b/CliFx.Analyzers/AnalyzerBase.cs @@ -14,7 +14,8 @@ public abstract class AnalyzerBase : DiagnosticAnalyzer protected AnalyzerBase( string diagnosticTitle, string diagnosticMessage, - DiagnosticSeverity diagnosticSeverity = DiagnosticSeverity.Error) + DiagnosticSeverity diagnosticSeverity = DiagnosticSeverity.Error + ) { SupportedDiagnostic = new DiagnosticDescriptor( "CliFx_" + GetType().Name.TrimEnd("Analyzer"), @@ -36,4 +37,4 @@ public abstract class AnalyzerBase : DiagnosticAnalyzer context.EnableConcurrentExecution(); context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/CliFx.Analyzers.csproj b/CliFx.Analyzers/CliFx.Analyzers.csproj index 642b368..08d300f 100644 --- a/CliFx.Analyzers/CliFx.Analyzers.csproj +++ b/CliFx.Analyzers/CliFx.Analyzers.csproj @@ -17,6 +17,7 @@ + diff --git a/CliFx.Analyzers/CommandMustBeAnnotatedAnalyzer.cs b/CliFx.Analyzers/CommandMustBeAnnotatedAnalyzer.cs index 67d1697..76047d3 100644 --- a/CliFx.Analyzers/CommandMustBeAnnotatedAnalyzer.cs +++ b/CliFx.Analyzers/CommandMustBeAnnotatedAnalyzer.cs @@ -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); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/CommandMustImplementInterfaceAnalyzer.cs b/CliFx.Analyzers/CommandMustImplementInterfaceAnalyzer.cs index a9e886b..4a2154b 100644 --- a/CliFx.Analyzers/CommandMustImplementInterfaceAnalyzer.cs +++ b/CliFx.Analyzers/CommandMustImplementInterfaceAnalyzer.cs @@ -13,31 +13,28 @@ public class CommandMustImplementInterfaceAnalyzer : AnalyzerBase public CommandMustImplementInterfaceAnalyzer() : base( $"Commands must implement `{SymbolNames.CliFxCommandInterface}` interface", - $"This type must implement `{SymbolNames.CliFxCommandInterface}` interface in order to be a valid command.") - { - } + $"This type must implement `{SymbolNames.CliFxCommandInterface}` interface in order to be a valid command." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, ClassDeclarationSyntax classDeclaration, - ITypeSymbol type) + ITypeSymbol type + ) { - var hasCommandAttribute = type - .GetAttributes() + var hasCommandAttribute = type.GetAttributes() .Select(a => a.AttributeClass) .Any(c => c.DisplayNameMatches(SymbolNames.CliFxCommandAttribute)); - var implementsCommandInterface = type - .AllInterfaces - .Any(i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface)); + var implementsCommandInterface = type.AllInterfaces.Any( + i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface) + ); // If the attribute is present, but the interface is not implemented, // it's very likely a user error. if (hasCommandAttribute && !implementsCommandInterface) { - context.ReportDiagnostic( - CreateDiagnostic(classDeclaration.Identifier.GetLocation()) - ); + context.ReportDiagnostic(CreateDiagnostic(classDeclaration.Identifier.GetLocation())); } } @@ -46,4 +43,4 @@ public class CommandMustImplementInterfaceAnalyzer : AnalyzerBase base.Initialize(context); context.HandleClassDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ObjectModel/CommandOptionSymbol.cs b/CliFx.Analyzers/ObjectModel/CommandOptionSymbol.cs index 17c4d4c..8893647 100644 --- a/CliFx.Analyzers/ObjectModel/CommandOptionSymbol.cs +++ b/CliFx.Analyzers/ObjectModel/CommandOptionSymbol.cs @@ -25,7 +25,8 @@ internal partial class CommandOptionSymbol : ICommandMemberSymbol char? shortName, bool? isRequired, ITypeSymbol? converterType, - IReadOnlyList validatorTypes) + IReadOnlyList validatorTypes + ) { Property = property; Name = name; @@ -38,9 +39,14 @@ internal partial class CommandOptionSymbol : ICommandMemberSymbol internal partial class CommandOptionSymbol { - private static AttributeData? TryGetOptionAttribute(IPropertySymbol property) => property - .GetAttributes() - .FirstOrDefault(a => a.AttributeClass?.DisplayNameMatches(SymbolNames.CliFxCommandOptionAttribute) == true); + private static AttributeData? TryGetOptionAttribute(IPropertySymbol property) => + property + .GetAttributes() + .FirstOrDefault( + a => + a.AttributeClass?.DisplayNameMatches(SymbolNames.CliFxCommandOptionAttribute) + == true + ); public static CommandOptionSymbol? TryResolve(IPropertySymbol property) { @@ -48,42 +54,47 @@ internal partial class CommandOptionSymbol if (attribute is null) return null; - var name = attribute - .ConstructorArguments - .Where(a => a.Type?.SpecialType == SpecialType.System_String) - .Select(a => a.Value) - .FirstOrDefault() as string; + var name = + attribute.ConstructorArguments + .Where(a => a.Type?.SpecialType == SpecialType.System_String) + .Select(a => a.Value) + .FirstOrDefault() as string; - var shortName = attribute - .ConstructorArguments - .Where(a => a.Type?.SpecialType == SpecialType.System_Char) - .Select(a => a.Value) - .FirstOrDefault() as char?; + var shortName = + attribute.ConstructorArguments + .Where(a => a.Type?.SpecialType == SpecialType.System_Char) + .Select(a => a.Value) + .FirstOrDefault() as char?; - var isRequired = attribute - .NamedArguments - .Where(a => a.Key == "IsRequired") - .Select(a => a.Value.Value) - .FirstOrDefault() as bool?; + var isRequired = + attribute.NamedArguments + .Where(a => a.Key == "IsRequired") + .Select(a => a.Value.Value) + .FirstOrDefault() as bool?; - var converter = attribute - .NamedArguments + var converter = attribute.NamedArguments .Where(a => a.Key == "Converter") .Select(a => a.Value.Value) .Cast() .FirstOrDefault(); - var validators = attribute - .NamedArguments + var validators = attribute.NamedArguments .Where(a => a.Key == "Validators") .SelectMany(a => a.Value.Values) .Select(c => c.Value) .Cast() .ToArray(); - return new CommandOptionSymbol(property, name, shortName, isRequired, converter, validators); + return new CommandOptionSymbol( + property, + name, + shortName, + isRequired, + converter, + validators + ); } public static bool IsOptionProperty(IPropertySymbol property) => TryGetOptionAttribute(property) is not null; -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ObjectModel/CommandParameterSymbol.cs b/CliFx.Analyzers/ObjectModel/CommandParameterSymbol.cs index cbda9d7..ed34a98 100644 --- a/CliFx.Analyzers/ObjectModel/CommandParameterSymbol.cs +++ b/CliFx.Analyzers/ObjectModel/CommandParameterSymbol.cs @@ -25,7 +25,8 @@ internal partial class CommandParameterSymbol : ICommandMemberSymbol string? name, bool? isRequired, ITypeSymbol? converterType, - IReadOnlyList validatorTypes) + IReadOnlyList validatorTypes + ) { Property = property; Order = order; @@ -38,9 +39,14 @@ internal partial class CommandParameterSymbol : ICommandMemberSymbol internal partial class CommandParameterSymbol { - private static AttributeData? TryGetParameterAttribute(IPropertySymbol property) => property - .GetAttributes() - .FirstOrDefault(a => a.AttributeClass?.DisplayNameMatches(SymbolNames.CliFxCommandParameterAttribute) == true); + private static AttributeData? TryGetParameterAttribute(IPropertySymbol property) => + property + .GetAttributes() + .FirstOrDefault( + a => + a.AttributeClass?.DisplayNameMatches(SymbolNames.CliFxCommandParameterAttribute) + == true + ); public static CommandParameterSymbol? TryResolve(IPropertySymbol property) { @@ -48,32 +54,27 @@ internal partial class CommandParameterSymbol if (attribute is null) return null; - var order = (int)attribute - .ConstructorArguments - .Select(a => a.Value) - .First()!; + var order = (int)attribute.ConstructorArguments.Select(a => a.Value).First()!; - var name = attribute - .NamedArguments - .Where(a => a.Key == "Name") - .Select(a => a.Value.Value) - .FirstOrDefault() as string; + var name = + attribute.NamedArguments + .Where(a => a.Key == "Name") + .Select(a => a.Value.Value) + .FirstOrDefault() as string; - var isRequired = attribute - .NamedArguments - .Where(a => a.Key == "IsRequired") - .Select(a => a.Value.Value) - .FirstOrDefault() as bool?; + var isRequired = + attribute.NamedArguments + .Where(a => a.Key == "IsRequired") + .Select(a => a.Value.Value) + .FirstOrDefault() as bool?; - var converter = attribute - .NamedArguments + var converter = attribute.NamedArguments .Where(a => a.Key == "Converter") .Select(a => a.Value.Value) .Cast() .FirstOrDefault(); - var validators = attribute - .NamedArguments + var validators = attribute.NamedArguments .Where(a => a.Key == "Validators") .SelectMany(a => a.Value.Values) .Select(c => c.Value) @@ -85,4 +86,4 @@ internal partial class CommandParameterSymbol public static bool IsParameterProperty(IPropertySymbol property) => TryGetParameterAttribute(property) is not null; -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ObjectModel/ICommandMemberSymbol.cs b/CliFx.Analyzers/ObjectModel/ICommandMemberSymbol.cs index 3fb81d8..377f13b 100644 --- a/CliFx.Analyzers/ObjectModel/ICommandMemberSymbol.cs +++ b/CliFx.Analyzers/ObjectModel/ICommandMemberSymbol.cs @@ -16,6 +16,6 @@ internal interface ICommandMemberSymbol internal static class CommandMemberSymbolExtensions { public static bool IsScalar(this ICommandMemberSymbol member) => - member.Property.Type.SpecialType == SpecialType.System_String || - member.Property.Type.TryGetEnumerableUnderlyingType() is null; -} \ No newline at end of file + member.Property.Type.SpecialType == SpecialType.System_String + || member.Property.Type.TryGetEnumerableUnderlyingType() is null; +} diff --git a/CliFx.Analyzers/ObjectModel/SymbolNames.cs b/CliFx.Analyzers/ObjectModel/SymbolNames.cs index aae8629..cc4b817 100644 --- a/CliFx.Analyzers/ObjectModel/SymbolNames.cs +++ b/CliFx.Analyzers/ObjectModel/SymbolNames.cs @@ -4,9 +4,10 @@ internal static class SymbolNames { public const string CliFxCommandInterface = "CliFx.ICommand"; public const string CliFxCommandAttribute = "CliFx.Attributes.CommandAttribute"; - public const string CliFxCommandParameterAttribute = "CliFx.Attributes.CommandParameterAttribute"; + public const string CliFxCommandParameterAttribute = + "CliFx.Attributes.CommandParameterAttribute"; public const string CliFxCommandOptionAttribute = "CliFx.Attributes.CommandOptionAttribute"; public const string CliFxConsoleInterface = "CliFx.Infrastructure.IConsole"; public const string CliFxBindingConverterClass = "CliFx.Extensibility.BindingConverter"; public const string CliFxBindingValidatorClass = "CliFx.Extensibility.BindingValidator"; -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustBeInsideCommandAnalyzer.cs b/CliFx.Analyzers/OptionMustBeInsideCommandAnalyzer.cs index 805203f..0d8c930 100644 --- a/CliFx.Analyzers/OptionMustBeInsideCommandAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustBeInsideCommandAnalyzer.cs @@ -13,14 +13,14 @@ public class OptionMustBeInsideCommandAnalyzer : AnalyzerBase public OptionMustBeInsideCommandAnalyzer() : base( "Options must be defined inside commands", - $"This option must be defined inside a class that implements `{SymbolNames.CliFxCommandInterface}`.") - { - } + $"This option must be defined inside a class that implements `{SymbolNames.CliFxCommandInterface}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -31,10 +31,9 @@ public class OptionMustBeInsideCommandAnalyzer : AnalyzerBase if (!CommandOptionSymbol.IsOptionProperty(property)) return; - var isInsideCommand = property - .ContainingType - .AllInterfaces - .Any(i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface)); + var isInsideCommand = property.ContainingType.AllInterfaces.Any( + i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface) + ); if (!isInsideCommand) { @@ -49,4 +48,4 @@ public class OptionMustBeInsideCommandAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustBeRequiredIfPropertyRequiredAnalyzer.cs b/CliFx.Analyzers/OptionMustBeRequiredIfPropertyRequiredAnalyzer.cs index 866d231..c8f4c30 100644 --- a/CliFx.Analyzers/OptionMustBeRequiredIfPropertyRequiredAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustBeRequiredIfPropertyRequiredAnalyzer.cs @@ -12,14 +12,14 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzer : AnalyzerBase public OptionMustBeRequiredIfPropertyRequiredAnalyzer() : base( "Options bound to required properties cannot be marked as non-required", - "This option cannot be marked as non-required because it's bound to a required property.") - { - } + "This option cannot be marked as non-required because it's bound to a required property." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -34,11 +34,7 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzer : AnalyzerBase if (option.IsRequired != false) return; - context.ReportDiagnostic( - CreateDiagnostic( - propertyDeclaration.Identifier.GetLocation() - ) - ); + context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.Identifier.GetLocation())); } public override void Initialize(AnalysisContext context) @@ -46,4 +42,4 @@ public class OptionMustBeRequiredIfPropertyRequiredAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustHaveNameOrShortNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveNameOrShortNameAnalyzer.cs index 557c7fa..8e0b98f 100644 --- a/CliFx.Analyzers/OptionMustHaveNameOrShortNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveNameOrShortNameAnalyzer.cs @@ -12,14 +12,14 @@ public class OptionMustHaveNameOrShortNameAnalyzer : AnalyzerBase public OptionMustHaveNameOrShortNameAnalyzer() : base( "Options must have either a name or short name specified", - "This option must have either a name or short name specified.") - { - } + "This option must have either a name or short name specified." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { var option = CommandOptionSymbol.TryResolve(property); if (option is null) @@ -38,4 +38,4 @@ public class OptionMustHaveNameOrShortNameAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs index f99a1a3..a186fc8 100644 --- a/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveUniqueNameAnalyzer.cs @@ -14,16 +14,16 @@ public class OptionMustHaveUniqueNameAnalyzer : AnalyzerBase public OptionMustHaveUniqueNameAnalyzer() : base( "Options must have unique names", - "This option's name must be unique within the command (comparison IS NOT case sensitive). " + - "Specified name: `{0}`. " + - "Property bound to another option with the same name: `{1}`.") - { - } + "This option's name must be unique within the command (comparison IS NOT case sensitive). " + + "Specified name: `{0}`. " + + "Property bound to another option with the same name: `{1}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -35,8 +35,7 @@ public class OptionMustHaveUniqueNameAnalyzer : AnalyzerBase if (string.IsNullOrWhiteSpace(option.Name)) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -69,4 +68,4 @@ public class OptionMustHaveUniqueNameAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs index a60ef0a..eeba515 100644 --- a/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveUniqueShortNameAnalyzer.cs @@ -13,16 +13,16 @@ public class OptionMustHaveUniqueShortNameAnalyzer : AnalyzerBase public OptionMustHaveUniqueShortNameAnalyzer() : base( "Options must have unique short names", - "This option's short name must be unique within the command (comparison IS case sensitive). " + - "Specified short name: `{0}` " + - "Property bound to another option with the same short name: `{1}`.") - { - } + "This option's short name must be unique within the command (comparison IS case sensitive). " + + "Specified short name: `{0}` " + + "Property bound to another option with the same short name: `{1}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -34,8 +34,7 @@ public class OptionMustHaveUniqueShortNameAnalyzer : AnalyzerBase if (option.ShortName is null) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -68,4 +67,4 @@ public class OptionMustHaveUniqueShortNameAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustHaveValidConverterAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveValidConverterAnalyzer.cs index 7e8bd4c..99a1545 100644 --- a/CliFx.Analyzers/OptionMustHaveValidConverterAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveValidConverterAnalyzer.cs @@ -13,14 +13,14 @@ public class OptionMustHaveValidConverterAnalyzer : AnalyzerBase public OptionMustHaveValidConverterAnalyzer() : base( $"Option converters must derive from `{SymbolNames.CliFxBindingConverterClass}`", - $"Converter specified for this option must derive from a compatible `{SymbolNames.CliFxBindingConverterClass}`.") - { - } + $"Converter specified for this option must derive from a compatible `{SymbolNames.CliFxBindingConverterClass}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { var option = CommandOptionSymbol.TryResolve(property); if (option is null) @@ -29,21 +29,26 @@ public class OptionMustHaveValidConverterAnalyzer : AnalyzerBase if (option.ConverterType is null) return; - var converterValueType = option - .ConverterType + var converterValueType = option.ConverterType .GetBaseTypes() - .FirstOrDefault(t => t.ConstructedFrom.DisplayNameMatches(SymbolNames.CliFxBindingConverterClass))? - .TypeArguments - .FirstOrDefault(); + .FirstOrDefault( + t => t.ConstructedFrom.DisplayNameMatches(SymbolNames.CliFxBindingConverterClass) + ) + ?.TypeArguments.FirstOrDefault(); // Value returned by the converter must be assignable to the property type var isCompatible = - converterValueType is not null && (option.IsScalar() - // Scalar - ? context.Compilation.IsAssignable(converterValueType, property.Type) - // Non-scalar (assume we can handle all IEnumerable types for simplicity) - : property.Type.TryGetEnumerableUnderlyingType() is { } enumerableUnderlyingType && - context.Compilation.IsAssignable(converterValueType, enumerableUnderlyingType) + converterValueType is not null + && ( + option.IsScalar() + // Scalar + ? context.Compilation.IsAssignable(converterValueType, property.Type) + // Non-scalar (assume we can handle all IEnumerable types for simplicity) + : property.Type.TryGetEnumerableUnderlyingType() is { } enumerableUnderlyingType + && context.Compilation.IsAssignable( + converterValueType, + enumerableUnderlyingType + ) ); if (!isCompatible) @@ -59,4 +64,4 @@ public class OptionMustHaveValidConverterAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs index e49d1bb..4904a43 100644 --- a/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveValidNameAnalyzer.cs @@ -12,15 +12,15 @@ public class OptionMustHaveValidNameAnalyzer : AnalyzerBase public OptionMustHaveValidNameAnalyzer() : base( "Options must have valid names", - "This option's name must be at least 2 characters long and must start with a letter. " + - "Specified name: `{0}`.") - { - } + "This option's name must be at least 2 characters long and must start with a letter. " + + "Specified name: `{0}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { var option = CommandOptionSymbol.TryResolve(property); if (option is null) @@ -32,10 +32,7 @@ public class OptionMustHaveValidNameAnalyzer : AnalyzerBase if (option.Name.Length < 2 || !char.IsLetter(option.Name[0])) { context.ReportDiagnostic( - CreateDiagnostic( - propertyDeclaration.Identifier.GetLocation(), - option.Name - ) + CreateDiagnostic(propertyDeclaration.Identifier.GetLocation(), option.Name) ); } } @@ -45,4 +42,4 @@ public class OptionMustHaveValidNameAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs index 838293c..2af4fd7 100644 --- a/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveValidShortNameAnalyzer.cs @@ -12,15 +12,15 @@ public class OptionMustHaveValidShortNameAnalyzer : AnalyzerBase public OptionMustHaveValidShortNameAnalyzer() : base( "Option short names must be letter characters", - "This option's short name must be a single letter character. " + - "Specified short name: `{0}`.") - { - } + "This option's short name must be a single letter character. " + + "Specified short name: `{0}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { var option = CommandOptionSymbol.TryResolve(property); if (option is null) @@ -32,10 +32,7 @@ public class OptionMustHaveValidShortNameAnalyzer : AnalyzerBase if (!char.IsLetter(option.ShortName.Value)) { context.ReportDiagnostic( - CreateDiagnostic( - propertyDeclaration.Identifier.GetLocation(), - option.ShortName - ) + CreateDiagnostic(propertyDeclaration.Identifier.GetLocation(), option.ShortName) ); } } @@ -45,4 +42,4 @@ public class OptionMustHaveValidShortNameAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/OptionMustHaveValidValidatorsAnalyzer.cs b/CliFx.Analyzers/OptionMustHaveValidValidatorsAnalyzer.cs index 091dfc9..2e45e35 100644 --- a/CliFx.Analyzers/OptionMustHaveValidValidatorsAnalyzer.cs +++ b/CliFx.Analyzers/OptionMustHaveValidValidatorsAnalyzer.cs @@ -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); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustBeInsideCommandAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeInsideCommandAnalyzer.cs index 6003cfe..c75fee8 100644 --- a/CliFx.Analyzers/ParameterMustBeInsideCommandAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeInsideCommandAnalyzer.cs @@ -13,14 +13,14 @@ public class ParameterMustBeInsideCommandAnalyzer : AnalyzerBase public ParameterMustBeInsideCommandAnalyzer() : base( "Parameters must be defined inside commands", - $"This parameter must be defined inside a class that implements `{SymbolNames.CliFxCommandInterface}`.") - { - } + $"This parameter must be defined inside a class that implements `{SymbolNames.CliFxCommandInterface}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -31,10 +31,9 @@ public class ParameterMustBeInsideCommandAnalyzer : AnalyzerBase if (!CommandParameterSymbol.IsParameterProperty(property)) return; - var isInsideCommand = property - .ContainingType - .AllInterfaces - .Any(i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface)); + var isInsideCommand = property.ContainingType.AllInterfaces.Any( + i => i.DisplayNameMatches(SymbolNames.CliFxCommandInterface) + ); if (!isInsideCommand) { @@ -49,4 +48,4 @@ public class ParameterMustBeInsideCommandAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs index 29a5764..4991a59 100644 --- a/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeLastIfNonRequiredAnalyzer.cs @@ -13,15 +13,15 @@ public class ParameterMustBeLastIfNonRequiredAnalyzer : AnalyzerBase public ParameterMustBeLastIfNonRequiredAnalyzer() : base( "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). " + - "Property bound to another non-required parameter: `{0}`.") - { - } + "This parameter is non-required so it must be the last in order (its order must be highest within the command). " + + "Property bound to another non-required parameter: `{0}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -33,8 +33,7 @@ public class ParameterMustBeLastIfNonRequiredAnalyzer : AnalyzerBase if (parameter.IsRequired != false) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -63,4 +62,4 @@ public class ParameterMustBeLastIfNonRequiredAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs index 7c634b8..033442c 100644 --- a/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeLastIfNonScalarAnalyzer.cs @@ -13,15 +13,15 @@ public class ParameterMustBeLastIfNonScalarAnalyzer : AnalyzerBase public ParameterMustBeLastIfNonScalarAnalyzer() : base( "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). " + - "Property bound to another non-scalar parameter: `{0}`.") - { - } + "This parameter has a non-scalar type so it must be the last in order (its order must be highest within the command). " + + "Property bound to another non-scalar parameter: `{0}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -33,8 +33,7 @@ public class ParameterMustBeLastIfNonScalarAnalyzer : AnalyzerBase if (parameter.IsScalar()) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -63,4 +62,4 @@ public class ParameterMustBeLastIfNonScalarAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustBeRequiredIfPropertyRequiredAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeRequiredIfPropertyRequiredAnalyzer.cs index c4ad97e..d4ff8d0 100644 --- a/CliFx.Analyzers/ParameterMustBeRequiredIfPropertyRequiredAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeRequiredIfPropertyRequiredAnalyzer.cs @@ -12,14 +12,14 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzer : AnalyzerBase public ParameterMustBeRequiredIfPropertyRequiredAnalyzer() : base( "Parameters bound to required properties cannot be marked as non-required", - "This parameter cannot be marked as non-required because it's bound to a required property.") - { - } + "This parameter cannot be marked as non-required because it's bound to a required property." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -34,11 +34,7 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzer : AnalyzerBase if (parameter.IsRequired != false) return; - context.ReportDiagnostic( - CreateDiagnostic( - propertyDeclaration.Identifier.GetLocation() - ) - ); + context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.Identifier.GetLocation())); } public override void Initialize(AnalysisContext context) @@ -46,4 +42,4 @@ public class ParameterMustBeRequiredIfPropertyRequiredAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs index 3b29950..5638fd3 100644 --- a/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeSingleIfNonRequiredAnalyzer.cs @@ -13,15 +13,15 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzer : AnalyzerBase public ParameterMustBeSingleIfNonRequiredAnalyzer() : base( "Parameters marked as non-required are limited to one per command", - "This parameter is non-required so it must be the only such parameter in the command. " + - "Property bound to another non-required parameter: `{0}`.") - { - } + "This parameter is non-required so it must be the only such parameter in the command. " + + "Property bound to another non-required parameter: `{0}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -33,8 +33,7 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzer : AnalyzerBase if (parameter.IsRequired != false) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -63,4 +62,4 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs b/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs index b4d928c..bbf02ea 100644 --- a/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustBeSingleIfNonScalarAnalyzer.cs @@ -13,15 +13,15 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase public ParameterMustBeSingleIfNonScalarAnalyzer() : base( "Parameters of non-scalar types are limited to one per command", - "This parameter has a non-scalar type so it must be the only such parameter in the command. " + - "Property bound to another non-scalar parameter: `{0}`.") - { - } + "This parameter has a non-scalar type so it must be the only such parameter in the command. " + + "Property bound to another non-scalar parameter: `{0}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -33,8 +33,7 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase if (parameter.IsScalar()) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -63,4 +62,4 @@ public class ParameterMustBeSingleIfNonScalarAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs b/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs index 62d8292..cdcc8cc 100644 --- a/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustHaveUniqueNameAnalyzer.cs @@ -14,16 +14,16 @@ public class ParameterMustHaveUniqueNameAnalyzer : AnalyzerBase public ParameterMustHaveUniqueNameAnalyzer() : base( "Parameters must have unique names", - "This parameter's name must be unique within the command (comparison IS NOT case sensitive). " + - "Specified name: `{0}`. " + - "Property bound to another parameter with the same name: `{1}`.") - { - } + "This parameter's name must be unique within the command (comparison IS NOT case sensitive). " + + "Specified name: `{0}`. " + + "Property bound to another parameter with the same name: `{1}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -35,8 +35,7 @@ public class ParameterMustHaveUniqueNameAnalyzer : AnalyzerBase if (string.IsNullOrWhiteSpace(parameter.Name)) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -51,7 +50,13 @@ public class ParameterMustHaveUniqueNameAnalyzer : AnalyzerBase if (string.IsNullOrWhiteSpace(otherParameter.Name)) continue; - if (string.Equals(parameter.Name, otherParameter.Name, StringComparison.OrdinalIgnoreCase)) + if ( + string.Equals( + parameter.Name, + otherParameter.Name, + StringComparison.OrdinalIgnoreCase + ) + ) { context.ReportDiagnostic( CreateDiagnostic( @@ -69,4 +74,4 @@ public class ParameterMustHaveUniqueNameAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs b/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs index 9ef2411..4d4661e 100644 --- a/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustHaveUniqueOrderAnalyzer.cs @@ -13,16 +13,16 @@ public class ParameterMustHaveUniqueOrderAnalyzer : AnalyzerBase public ParameterMustHaveUniqueOrderAnalyzer() : base( "Parameters must have unique order", - "This parameter's order must be unique within the command. " + - "Specified order: {0}. " + - "Property bound to another parameter with the same order: `{1}`.") - { - } + "This parameter's order must be unique within the command. " + + "Specified order: {0}. " + + "Property bound to another parameter with the same order: `{1}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { if (property.ContainingType is null) return; @@ -31,8 +31,7 @@ public class ParameterMustHaveUniqueOrderAnalyzer : AnalyzerBase if (parameter is null) return; - var otherProperties = property - .ContainingType + var otherProperties = property.ContainingType .GetMembers() .OfType() .Where(m => !m.Equals(property)) @@ -62,4 +61,4 @@ public class ParameterMustHaveUniqueOrderAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustHaveValidConverterAnalyzer.cs b/CliFx.Analyzers/ParameterMustHaveValidConverterAnalyzer.cs index f04bdd9..1de5ff4 100644 --- a/CliFx.Analyzers/ParameterMustHaveValidConverterAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustHaveValidConverterAnalyzer.cs @@ -13,14 +13,14 @@ public class ParameterMustHaveValidConverterAnalyzer : AnalyzerBase public ParameterMustHaveValidConverterAnalyzer() : base( $"Parameter converters must derive from `{SymbolNames.CliFxBindingConverterClass}`", - $"Converter specified for this parameter must derive from a compatible `{SymbolNames.CliFxBindingConverterClass}`.") - { - } + $"Converter specified for this parameter must derive from a compatible `{SymbolNames.CliFxBindingConverterClass}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { var parameter = CommandParameterSymbol.TryResolve(property); if (parameter is null) @@ -29,21 +29,26 @@ public class ParameterMustHaveValidConverterAnalyzer : AnalyzerBase if (parameter.ConverterType is null) return; - var converterValueType = parameter - .ConverterType + var converterValueType = parameter.ConverterType .GetBaseTypes() - .FirstOrDefault(t => t.ConstructedFrom.DisplayNameMatches(SymbolNames.CliFxBindingConverterClass))? - .TypeArguments - .FirstOrDefault(); + .FirstOrDefault( + t => t.ConstructedFrom.DisplayNameMatches(SymbolNames.CliFxBindingConverterClass) + ) + ?.TypeArguments.FirstOrDefault(); // Value returned by the converter must be assignable to the property type var isCompatible = - converterValueType is not null && (parameter.IsScalar() - // Scalar - ? context.Compilation.IsAssignable(converterValueType, property.Type) - // Non-scalar (assume we can handle all IEnumerable types for simplicity) - : property.Type.TryGetEnumerableUnderlyingType() is { } enumerableUnderlyingType && - context.Compilation.IsAssignable(converterValueType, enumerableUnderlyingType) + converterValueType is not null + && ( + parameter.IsScalar() + // Scalar + ? context.Compilation.IsAssignable(converterValueType, property.Type) + // Non-scalar (assume we can handle all IEnumerable types for simplicity) + : property.Type.TryGetEnumerableUnderlyingType() is { } enumerableUnderlyingType + && context.Compilation.IsAssignable( + converterValueType, + enumerableUnderlyingType + ) ); if (!isCompatible) @@ -59,4 +64,4 @@ public class ParameterMustHaveValidConverterAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/ParameterMustHaveValidValidatorsAnalyzer.cs b/CliFx.Analyzers/ParameterMustHaveValidValidatorsAnalyzer.cs index 275df82..1ebcd90 100644 --- a/CliFx.Analyzers/ParameterMustHaveValidValidatorsAnalyzer.cs +++ b/CliFx.Analyzers/ParameterMustHaveValidValidatorsAnalyzer.cs @@ -13,14 +13,14 @@ public class ParameterMustHaveValidValidatorsAnalyzer : AnalyzerBase public ParameterMustHaveValidValidatorsAnalyzer() : base( $"Parameter validators must derive from `{SymbolNames.CliFxBindingValidatorClass}`", - $"Each validator specified for this parameter must derive from a compatible `{SymbolNames.CliFxBindingValidatorClass}`.") - { - } + $"Each validator specified for this parameter must derive from a compatible `{SymbolNames.CliFxBindingValidatorClass}`." + ) { } private void Analyze( SyntaxNodeAnalysisContext context, PropertyDeclarationSyntax propertyDeclaration, - IPropertySymbol property) + IPropertySymbol property + ) { var parameter = CommandParameterSymbol.TryResolve(property); if (parameter is null) @@ -30,14 +30,16 @@ public class ParameterMustHaveValidValidatorsAnalyzer : 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 ParameterMustHaveValidValidatorsAnalyzer : AnalyzerBase base.Initialize(context); context.HandlePropertyDeclaration(Analyze); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/SystemConsoleShouldBeAvoidedAnalyzer.cs b/CliFx.Analyzers/SystemConsoleShouldBeAvoidedAnalyzer.cs index 14d7f94..e64e394 100644 --- a/CliFx.Analyzers/SystemConsoleShouldBeAvoidedAnalyzer.cs +++ b/CliFx.Analyzers/SystemConsoleShouldBeAvoidedAnalyzer.cs @@ -15,13 +15,13 @@ public class SystemConsoleShouldBeAvoidedAnalyzer : AnalyzerBase : base( $"Avoid calling `System.Console` where `{SymbolNames.CliFxConsoleInterface}` is available", $"Use the provided `{SymbolNames.CliFxConsoleInterface}` abstraction instead of `System.Console` to ensure that the command can be tested in isolation.", - DiagnosticSeverity.Warning) - { - } + DiagnosticSeverity.Warning + ) { } private MemberAccessExpressionSyntax? TryGetSystemConsoleMemberAccess( SyntaxNodeAnalysisContext context, - SyntaxNode node) + SyntaxNode node + ) { var currentNode = node; @@ -53,8 +53,7 @@ public class SystemConsoleShouldBeAvoidedAnalyzer : AnalyzerBase return; // Check if IConsole is available in scope as an alternative to System.Console - var isConsoleInterfaceAvailable = context - .Node + var isConsoleInterfaceAvailable = context.Node .Ancestors() .OfType() .SelectMany(m => m.ParameterList.Parameters) @@ -65,9 +64,7 @@ public class SystemConsoleShouldBeAvoidedAnalyzer : AnalyzerBase if (isConsoleInterfaceAvailable) { - context.ReportDiagnostic( - CreateDiagnostic(systemConsoleMemberAccess.GetLocation()) - ); + context.ReportDiagnostic(CreateDiagnostic(systemConsoleMemberAccess.GetLocation())); } } @@ -76,4 +73,4 @@ public class SystemConsoleShouldBeAvoidedAnalyzer : AnalyzerBase base.Initialize(context); context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.SimpleMemberAccessExpression); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/Utils/Extensions/RoslynExtensions.cs b/CliFx.Analyzers/Utils/Extensions/RoslynExtensions.cs index 202e72f..00d6c21 100644 --- a/CliFx.Analyzers/Utils/Extensions/RoslynExtensions.cs +++ b/CliFx.Analyzers/Utils/Extensions/RoslynExtensions.cs @@ -29,56 +29,72 @@ internal static class RoslynExtensions } } - public static ITypeSymbol? TryGetEnumerableUnderlyingType(this ITypeSymbol type) => type - .AllInterfaces - .FirstOrDefault(i => i.ConstructedFrom.SpecialType == SpecialType.System_Collections_Generic_IEnumerable_T)? - .TypeArguments[0]; + public static ITypeSymbol? TryGetEnumerableUnderlyingType(this ITypeSymbol type) => + type.AllInterfaces + .FirstOrDefault( + i => + i.ConstructedFrom.SpecialType + == SpecialType.System_Collections_Generic_IEnumerable_T + ) + ?.TypeArguments[0]; // Detect if the property is required through roundabout means so as to not have to take dependency // on higher versions of the C# compiler. - public static bool IsRequired(this IPropertySymbol property) => property + public static bool IsRequired(this IPropertySymbol property) => + property // Can't rely on the RequiredMemberAttribute because it's generated by the compiler, not added by the user, // so we have to check for the presence of the `required` modifier in the syntax tree instead. .DeclaringSyntaxReferences - .Select(r => r.GetSyntax()) - .OfType() - .SelectMany(p => p.Modifiers) - .Any(m => m.IsKind((SyntaxKind)8447)); + .Select(r => r.GetSyntax()) + .OfType() + .SelectMany(p => p.Modifiers) + .Any(m => m.IsKind((SyntaxKind)8447)); - public static bool IsAssignable(this Compilation compilation, ITypeSymbol source, ITypeSymbol destination) => - compilation.ClassifyConversion(source, destination).Exists; + public static bool IsAssignable( + this Compilation compilation, + ITypeSymbol source, + ITypeSymbol destination + ) => compilation.ClassifyConversion(source, destination).Exists; public static void HandleClassDeclaration( this AnalysisContext analysisContext, - Action analyze) + Action analyze + ) { - analysisContext.RegisterSyntaxNodeAction(ctx => - { - if (ctx.Node is not ClassDeclarationSyntax classDeclaration) - return; + analysisContext.RegisterSyntaxNodeAction( + ctx => + { + if (ctx.Node is not ClassDeclarationSyntax classDeclaration) + return; - var type = ctx.SemanticModel.GetDeclaredSymbol(classDeclaration); - if (type is null) - return; + var type = ctx.SemanticModel.GetDeclaredSymbol(classDeclaration); + if (type is null) + return; - analyze(ctx, classDeclaration, type); - }, SyntaxKind.ClassDeclaration); + analyze(ctx, classDeclaration, type); + }, + SyntaxKind.ClassDeclaration + ); } public static void HandlePropertyDeclaration( this AnalysisContext analysisContext, - Action analyze) + Action analyze + ) { - analysisContext.RegisterSyntaxNodeAction(ctx => - { - if (ctx.Node is not PropertyDeclarationSyntax propertyDeclaration) - return; + analysisContext.RegisterSyntaxNodeAction( + ctx => + { + if (ctx.Node is not PropertyDeclarationSyntax propertyDeclaration) + return; - var property = ctx.SemanticModel.GetDeclaredSymbol(propertyDeclaration); - if (property is null) - return; + var property = ctx.SemanticModel.GetDeclaredSymbol(propertyDeclaration); + if (property is null) + return; - analyze(ctx, propertyDeclaration, property); - }, SyntaxKind.PropertyDeclaration); + analyze(ctx, propertyDeclaration, property); + }, + SyntaxKind.PropertyDeclaration + ); } -} \ No newline at end of file +} diff --git a/CliFx.Analyzers/Utils/Extensions/StringExtensions.cs b/CliFx.Analyzers/Utils/Extensions/StringExtensions.cs index cb0c4fc..0848e56 100644 --- a/CliFx.Analyzers/Utils/Extensions/StringExtensions.cs +++ b/CliFx.Analyzers/Utils/Extensions/StringExtensions.cs @@ -7,11 +7,12 @@ internal static class StringExtensions public static string TrimEnd( this string str, string sub, - StringComparison comparison = StringComparison.Ordinal) + StringComparison comparison = StringComparison.Ordinal + ) { while (str.EndsWith(sub, comparison)) str = str[..^sub.Length]; return str; } -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.CliFx.cs b/CliFx.Benchmarks/Benchmarks.CliFx.cs index d335202..8435729 100644 --- a/CliFx.Benchmarks/Benchmarks.CliFx.cs +++ b/CliFx.Benchmarks/Benchmarks.CliFx.cs @@ -29,4 +29,4 @@ public partial class Benchmarks .AddCommand() .Build() .RunAsync(Arguments, new Dictionary()); -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.Clipr.cs b/CliFx.Benchmarks/Benchmarks.Clipr.cs index 7821a1d..80743d3 100644 --- a/CliFx.Benchmarks/Benchmarks.Clipr.cs +++ b/CliFx.Benchmarks/Benchmarks.Clipr.cs @@ -16,11 +16,9 @@ public partial class Benchmarks [NamedArgument('b', "bool", Constraint = NumArgsConstraint.Optional, Const = true)] public bool BoolOption { get; set; } - public void Execute() - { - } + public void Execute() { } } [Benchmark(Description = "Clipr")] public void ExecuteWithClipr() => CliParser.Parse(Arguments).Execute(); -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.Cocona.cs b/CliFx.Benchmarks/Benchmarks.Cocona.cs index ff5e3e8..a42526c 100644 --- a/CliFx.Benchmarks/Benchmarks.Cocona.cs +++ b/CliFx.Benchmarks/Benchmarks.Cocona.cs @@ -8,16 +8,12 @@ public partial class Benchmarks public class CoconaCommand { public void Execute( - [Option("str", new []{'s'})] - string? strOption, - [Option("int", new []{'i'})] - int intOption, - [Option("bool", new []{'b'})] - bool boolOption) - { - } + [Option("str", new[] { 's' })] string? strOption, + [Option("int", new[] { 'i' })] int intOption, + [Option("bool", new[] { 'b' })] bool boolOption + ) { } } [Benchmark(Description = "Cocona")] public void ExecuteWithCocona() => CoconaApp.Run(Arguments); -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.CommandLineParser.cs b/CliFx.Benchmarks/Benchmarks.CommandLineParser.cs index fe89cb5..ac97b8f 100644 --- a/CliFx.Benchmarks/Benchmarks.CommandLineParser.cs +++ b/CliFx.Benchmarks/Benchmarks.CommandLineParser.cs @@ -16,9 +16,7 @@ public partial class Benchmarks [Option('b', "bool")] public bool BoolOption { get; set; } - public void Execute() - { - } + public void Execute() { } } [Benchmark(Description = "CommandLineParser")] @@ -26,4 +24,4 @@ public partial class Benchmarks new Parser() .ParseArguments(Arguments, typeof(CommandLineParserCommand)) .WithParsed(c => c.Execute()); -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.McMaster.cs b/CliFx.Benchmarks/Benchmarks.McMaster.cs index 3b599c7..31ee40a 100644 --- a/CliFx.Benchmarks/Benchmarks.McMaster.cs +++ b/CliFx.Benchmarks/Benchmarks.McMaster.cs @@ -21,4 +21,4 @@ public partial class Benchmarks [Benchmark(Description = "McMaster.Extensions.CommandLineUtils")] public int ExecuteWithMcMaster() => CommandLineApplication.Execute(Arguments); -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.PowerArgs.cs b/CliFx.Benchmarks/Benchmarks.PowerArgs.cs index c6c9aa5..f229dff 100644 --- a/CliFx.Benchmarks/Benchmarks.PowerArgs.cs +++ b/CliFx.Benchmarks/Benchmarks.PowerArgs.cs @@ -16,11 +16,9 @@ public partial class Benchmarks [ArgShortcut("--bool"), ArgShortcut("-b")] public bool BoolOption { get; set; } - public void Main() - { - } + public void Main() { } } [Benchmark(Description = "PowerArgs")] public void ExecuteWithPowerArgs() => Args.InvokeMain(Arguments); -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.SystemCommandLine.cs b/CliFx.Benchmarks/Benchmarks.SystemCommandLine.cs index 37cd542..28522a3 100644 --- a/CliFx.Benchmarks/Benchmarks.SystemCommandLine.cs +++ b/CliFx.Benchmarks/Benchmarks.SystemCommandLine.cs @@ -15,18 +15,9 @@ public partial class Benchmarks { var command = new RootCommand { - new Option(new[] {"--str", "-s"}) - { - Argument = new Argument() - }, - new Option(new[] {"--int", "-i"}) - { - Argument = new Argument() - }, - new Option(new[] {"--bool", "-b"}) - { - Argument = new Argument() - } + new Option(new[] { "--str", "-s" }) { Argument = new Argument() }, + new Option(new[] { "--int", "-i" }) { Argument = new Argument() }, + new Option(new[] { "--bool", "-b" }) { Argument = new Argument() } }; command.Handler = CommandHandler.Create( @@ -40,4 +31,4 @@ public partial class Benchmarks [Benchmark(Description = "System.CommandLine")] public async Task ExecuteWithSystemCommandLine() => await new SystemCommandLineCommand().ExecuteAsync(Arguments); -} \ No newline at end of file +} diff --git a/CliFx.Benchmarks/Benchmarks.cs b/CliFx.Benchmarks/Benchmarks.cs index 7f1a371..c01fc3e 100644 --- a/CliFx.Benchmarks/Benchmarks.cs +++ b/CliFx.Benchmarks/Benchmarks.cs @@ -9,11 +9,10 @@ namespace CliFx.Benchmarks; [Orderer(SummaryOrderPolicy.FastestToSlowest)] public partial class Benchmarks { - private static readonly string[] Arguments = {"--str", "hello world", "-i", "13", "-b"}; + private static readonly string[] Arguments = { "--str", "hello world", "-i", "13", "-b" }; - public static void Main() => BenchmarkRunner.Run( - DefaultConfig - .Instance - .WithOptions(ConfigOptions.DisableOptimizationsValidator) - ); -} \ No newline at end of file + public static void Main() => + BenchmarkRunner.Run( + DefaultConfig.Instance.WithOptions(ConfigOptions.DisableOptimizationsValidator) + ); +} diff --git a/CliFx.Benchmarks/CliFx.Benchmarks.csproj b/CliFx.Benchmarks/CliFx.Benchmarks.csproj index daa7932..42d1d76 100644 --- a/CliFx.Benchmarks/CliFx.Benchmarks.csproj +++ b/CliFx.Benchmarks/CliFx.Benchmarks.csproj @@ -10,6 +10,7 @@ + diff --git a/CliFx.Demo/CliFx.Demo.csproj b/CliFx.Demo/CliFx.Demo.csproj index c22b744..643f25f 100644 --- a/CliFx.Demo/CliFx.Demo.csproj +++ b/CliFx.Demo/CliFx.Demo.csproj @@ -7,6 +7,7 @@ + diff --git a/CliFx.Demo/Commands/BookAddCommand.cs b/CliFx.Demo/Commands/BookAddCommand.cs index 891483d..58ac3cf 100644 --- a/CliFx.Demo/Commands/BookAddCommand.cs +++ b/CliFx.Demo/Commands/BookAddCommand.cs @@ -49,21 +49,23 @@ public partial class BookAddCommand { private static readonly Random Random = new(); - private static DateTimeOffset CreateRandomDate() => new( - Random.Next(1800, 2020), - Random.Next(1, 12), - Random.Next(1, 28), - Random.Next(1, 23), - Random.Next(1, 59), - Random.Next(1, 59), - TimeSpan.Zero - ); + private static DateTimeOffset CreateRandomDate() => + new( + Random.Next(1800, 2020), + Random.Next(1, 12), + Random.Next(1, 28), + Random.Next(1, 23), + Random.Next(1, 59), + Random.Next(1, 59), + TimeSpan.Zero + ); - private static Isbn CreateRandomIsbn() => new( - Random.Next(0, 999), - Random.Next(0, 99), - Random.Next(0, 99999), - Random.Next(0, 99), - Random.Next(0, 9) - ); -} \ No newline at end of file + private static Isbn CreateRandomIsbn() => + new( + Random.Next(0, 999), + Random.Next(0, 99), + Random.Next(0, 99999), + Random.Next(0, 99), + Random.Next(0, 9) + ); +} diff --git a/CliFx.Demo/Commands/BookCommand.cs b/CliFx.Demo/Commands/BookCommand.cs index f410b78..f20bcbf 100644 --- a/CliFx.Demo/Commands/BookCommand.cs +++ b/CliFx.Demo/Commands/BookCommand.cs @@ -31,4 +31,4 @@ public class BookCommand : ICommand return default; } -} \ No newline at end of file +} diff --git a/CliFx.Demo/Commands/BookListCommand.cs b/CliFx.Demo/Commands/BookListCommand.cs index 096693b..ed26410 100644 --- a/CliFx.Demo/Commands/BookListCommand.cs +++ b/CliFx.Demo/Commands/BookListCommand.cs @@ -33,4 +33,4 @@ public class BookListCommand : ICommand return default; } -} \ No newline at end of file +} diff --git a/CliFx.Demo/Commands/BookRemoveCommand.cs b/CliFx.Demo/Commands/BookRemoveCommand.cs index 605b5c9..4342d97 100644 --- a/CliFx.Demo/Commands/BookRemoveCommand.cs +++ b/CliFx.Demo/Commands/BookRemoveCommand.cs @@ -32,4 +32,4 @@ public class BookRemoveCommand : ICommand return default; } -} \ No newline at end of file +} diff --git a/CliFx.Demo/Domain/Book.cs b/CliFx.Demo/Domain/Book.cs index 47e23f1..a29b77c 100644 --- a/CliFx.Demo/Domain/Book.cs +++ b/CliFx.Demo/Domain/Book.cs @@ -2,4 +2,4 @@ namespace CliFx.Demo.Domain; -public record Book(string Title, string Author, DateTimeOffset Published, Isbn Isbn); \ No newline at end of file +public record Book(string Title, string Author, DateTimeOffset Published, Isbn Isbn); diff --git a/CliFx.Demo/Domain/Isbn.cs b/CliFx.Demo/Domain/Isbn.cs index ff2f0fc..a00726a 100644 --- a/CliFx.Demo/Domain/Isbn.cs +++ b/CliFx.Demo/Domain/Isbn.cs @@ -2,7 +2,13 @@ namespace CliFx.Demo.Domain; -public partial record Isbn(int EanPrefix, int RegistrationGroup, int Registrant, int Publication, int CheckDigit) +public partial record Isbn( + int EanPrefix, + int RegistrationGroup, + int Registrant, + int Publication, + int CheckDigit +) { public override string ToString() => $"{EanPrefix:000}-{RegistrationGroup:00}-{Registrant:00000}-{Publication:00}-{CheckDigit:0}"; @@ -22,4 +28,4 @@ public partial record Isbn int.Parse(components[4], formatProvider) ); } -} \ No newline at end of file +} diff --git a/CliFx.Demo/Domain/Library.cs b/CliFx.Demo/Domain/Library.cs index 8032e5d..ee4098d 100644 --- a/CliFx.Demo/Domain/Library.cs +++ b/CliFx.Demo/Domain/Library.cs @@ -25,4 +25,4 @@ public partial record Library(IReadOnlyList Books) public partial record Library { public static Library Empty { get; } = new(Array.Empty()); -} \ No newline at end of file +} diff --git a/CliFx.Demo/Domain/LibraryProvider.cs b/CliFx.Demo/Domain/LibraryProvider.cs index 478c368..16d6588 100644 --- a/CliFx.Demo/Domain/LibraryProvider.cs +++ b/CliFx.Demo/Domain/LibraryProvider.cs @@ -6,7 +6,8 @@ namespace CliFx.Demo.Domain; public class LibraryProvider { - private static string StorageFilePath { get; } = Path.Combine(Directory.GetCurrentDirectory(), "Library.json"); + private static string StorageFilePath { get; } = + Path.Combine(Directory.GetCurrentDirectory(), "Library.json"); private void StoreLibrary(Library library) { @@ -24,7 +25,8 @@ public class LibraryProvider return JsonSerializer.Deserialize(data) ?? Library.Empty; } - public Book? TryGetBook(string title) => GetLibrary().Books.FirstOrDefault(b => b.Title == title); + public Book? TryGetBook(string title) => + GetLibrary().Books.FirstOrDefault(b => b.Title == title); public void AddBook(Book book) { @@ -37,4 +39,4 @@ public class LibraryProvider var updatedLibrary = GetLibrary().WithoutBook(book); StoreLibrary(updatedLibrary); } -} \ No newline at end of file +} diff --git a/CliFx.Demo/Program.cs b/CliFx.Demo/Program.cs index 3494d74..3cb8faf 100644 --- a/CliFx.Demo/Program.cs +++ b/CliFx.Demo/Program.cs @@ -18,4 +18,4 @@ return await new CliApplicationBuilder() return services.BuildServiceProvider(); }) .Build() - .RunAsync(); \ No newline at end of file + .RunAsync(); diff --git a/CliFx.Demo/Utils/ConsoleExtensions.cs b/CliFx.Demo/Utils/ConsoleExtensions.cs index 2c3f5a5..a0605ba 100644 --- a/CliFx.Demo/Utils/ConsoleExtensions.cs +++ b/CliFx.Demo/Utils/ConsoleExtensions.cs @@ -33,4 +33,4 @@ internal static class ConsoleExtensions using (writer.Console.WithForegroundColor(ConsoleColor.White)) writer.WriteLine(book.Isbn); } -} \ No newline at end of file +} diff --git a/CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj b/CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj index 8857a95..e8f06cf 100644 --- a/CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj +++ b/CliFx.Tests.Dummy/CliFx.Tests.Dummy.csproj @@ -6,6 +6,10 @@ ../favicon.ico + + + + diff --git a/CliFx.Tests.Dummy/Commands/CancellationTestCommand.cs b/CliFx.Tests.Dummy/Commands/CancellationTestCommand.cs index 96987b5..b2c568c 100644 --- a/CliFx.Tests.Dummy/Commands/CancellationTestCommand.cs +++ b/CliFx.Tests.Dummy/Commands/CancellationTestCommand.cs @@ -14,10 +14,7 @@ public class CancellationTestCommand : ICommand { console.Output.WriteLine("Started."); - await Task.Delay( - TimeSpan.FromSeconds(3), - console.RegisterCancellationHandler() - ); + await Task.Delay(TimeSpan.FromSeconds(3), console.RegisterCancellationHandler()); console.Output.WriteLine("Completed."); } @@ -27,4 +24,4 @@ public class CancellationTestCommand : ICommand throw; } } -} \ No newline at end of file +} diff --git a/CliFx.Tests.Dummy/Commands/ConsoleTestCommand.cs b/CliFx.Tests.Dummy/Commands/ConsoleTestCommand.cs index 19ede61..bc79e77 100644 --- a/CliFx.Tests.Dummy/Commands/ConsoleTestCommand.cs +++ b/CliFx.Tests.Dummy/Commands/ConsoleTestCommand.cs @@ -20,4 +20,4 @@ public class ConsoleTestCommand : ICommand return default; } -} \ No newline at end of file +} diff --git a/CliFx.Tests.Dummy/Commands/EnvironmentTestCommand.cs b/CliFx.Tests.Dummy/Commands/EnvironmentTestCommand.cs index 871565c..1ec64f8 100644 --- a/CliFx.Tests.Dummy/Commands/EnvironmentTestCommand.cs +++ b/CliFx.Tests.Dummy/Commands/EnvironmentTestCommand.cs @@ -16,4 +16,4 @@ public class EnvironmentTestCommand : ICommand return default; } -} \ No newline at end of file +} diff --git a/CliFx.Tests.Dummy/Program.cs b/CliFx.Tests.Dummy/Program.cs index ea48a82..eb6265e 100644 --- a/CliFx.Tests.Dummy/Program.cs +++ b/CliFx.Tests.Dummy/Program.cs @@ -10,10 +10,11 @@ namespace CliFx.Tests.Dummy; public static class Program { // Path to the apphost - public static string FilePath { get; } = Path.ChangeExtension( - Assembly.GetExecutingAssembly().Location, - RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "exe" : null - ); + public static string FilePath { get; } = + Path.ChangeExtension( + Assembly.GetExecutingAssembly().Location, + RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "exe" : null + ); public static async Task Main() { @@ -23,9 +24,6 @@ public static class Program "false" ); - await new CliApplicationBuilder() - .AddCommandsFromThisAssembly() - .Build() - .RunAsync(); + await new CliApplicationBuilder().AddCommandsFromThisAssembly().Build().RunAsync(); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/ApplicationSpecs.cs b/CliFx.Tests/ApplicationSpecs.cs index f331ebd..89b2554 100644 --- a/CliFx.Tests/ApplicationSpecs.cs +++ b/CliFx.Tests/ApplicationSpecs.cs @@ -11,9 +11,7 @@ namespace CliFx.Tests; public class ApplicationSpecs : SpecsBase { public ApplicationSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_create_an_application_with_the_default_configuration() @@ -24,10 +22,7 @@ public class ApplicationSpecs : SpecsBase .UseConsole(FakeConsole) .Build(); - var exitCode = await app.RunAsync( - Array.Empty(), - new Dictionary() - ); + var exitCode = await app.RunAsync(Array.Empty(), new Dictionary()); // Assert exitCode.Should().Be(0); @@ -40,8 +35,8 @@ public class ApplicationSpecs : SpecsBase var app = new CliApplicationBuilder() .AddCommand() .AddCommandsFrom(typeof(NoOpCommand).Assembly) - .AddCommands(new[] {typeof(NoOpCommand)}) - .AddCommandsFrom(new[] {typeof(NoOpCommand).Assembly}) + .AddCommands(new[] { typeof(NoOpCommand) }) + .AddCommandsFrom(new[] { typeof(NoOpCommand).Assembly }) .AddCommandsFromThisAssembly() .AllowDebugMode() .AllowPreviewMode() @@ -53,10 +48,7 @@ public class ApplicationSpecs : SpecsBase .UseTypeActivator(Activator.CreateInstance!) .Build(); - var exitCode = await app.RunAsync( - Array.Empty(), - new Dictionary() - ); + var exitCode = await app.RunAsync(Array.Empty(), new Dictionary()); // Assert exitCode.Should().Be(0); @@ -71,10 +63,7 @@ public class ApplicationSpecs : SpecsBase .UseConsole(FakeConsole) .Build(); - var exitCode = await app.RunAsync( - Array.Empty(), - new Dictionary() - ); + var exitCode = await app.RunAsync(Array.Empty(), new Dictionary()); // Assert exitCode.Should().NotBe(0); @@ -82,4 +71,4 @@ public class ApplicationSpecs : SpecsBase var stdErr = FakeConsole.ReadErrorString(); stdErr.Should().Contain("not a valid command"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/CancellationSpecs.cs b/CliFx.Tests/CancellationSpecs.cs index d71dbd8..8359f6b 100644 --- a/CliFx.Tests/CancellationSpecs.cs +++ b/CliFx.Tests/CancellationSpecs.cs @@ -15,9 +15,7 @@ namespace CliFx.Tests; public class CancellationSpecs : SpecsBase { public CancellationSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact(Timeout = 15000)] public async Task I_can_configure_the_command_to_listen_to_the_interrupt_signal() @@ -41,24 +39,20 @@ public class CancellationSpecs : SpecsBase PipeTarget.ToStringBuilder(stdOutBuffer) ); - var command = - Cli.Wrap(Dummy.Program.FilePath).WithArguments("cancel-test") | - pipeTarget; + var command = Cli.Wrap(Dummy.Program.FilePath).WithArguments("cancel-test") | pipeTarget; // Act & assert - await Assert.ThrowsAnyAsync(async () => - await command.ExecuteAsync( - // Forceful cancellation (not required because we have a timeout) - CancellationToken.None, - // Graceful cancellation - cts.Token - ) + await Assert.ThrowsAnyAsync( + async () => + await command.ExecuteAsync( + // Forceful cancellation (not required because we have a timeout) + CancellationToken.None, + // Graceful cancellation + cts.Token + ) ); - stdOutBuffer.ToString().Trim().Should().ConsistOfLines( - "Started.", - "Cancelled." - ); + stdOutBuffer.ToString().Trim().Should().ConsistOfLines("Started.", "Cancelled."); } [Fact] @@ -111,9 +105,6 @@ public class CancellationSpecs : SpecsBase exitCode.Should().NotBe(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Trim().Should().ConsistOfLines( - "Started.", - "Cancelled." - ); + stdOut.Trim().Should().ConsistOfLines("Started.", "Cancelled."); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/CliFx.Tests.csproj b/CliFx.Tests/CliFx.Tests.csproj index 2f6cc9f..3819c78 100644 --- a/CliFx.Tests/CliFx.Tests.csproj +++ b/CliFx.Tests/CliFx.Tests.csproj @@ -12,6 +12,7 @@ + diff --git a/CliFx.Tests/ConsoleSpecs.cs b/CliFx.Tests/ConsoleSpecs.cs index 62e3663..6f4d058 100644 --- a/CliFx.Tests/ConsoleSpecs.cs +++ b/CliFx.Tests/ConsoleSpecs.cs @@ -17,9 +17,7 @@ namespace CliFx.Tests; public class ConsoleSpecs : SpecsBase { public ConsoleSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact(Timeout = 15000)] public async Task I_can_run_the_application_with_the_default_console_implementation_to_interact_with_the_system_console() @@ -28,8 +26,7 @@ public class ConsoleSpecs : SpecsBase // Arrange var command = - "Hello world" | - Cli.Wrap(Dummy.Program.FilePath).WithArguments("console-test"); + "Hello world" | Cli.Wrap(Dummy.Program.FilePath).WithArguments("console-test"); // Act var result = await command.ExecuteBufferedAsync(); @@ -205,10 +202,6 @@ public class ConsoleSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Trim().Should().ConsistOfLines( - "D0", - "A", - "Backspace" - ); + stdOut.Trim().Should().ConsistOfLines("D0", "A", "Backspace"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/ConversionSpecs.cs b/CliFx.Tests/ConversionSpecs.cs index fe0cfc0..bee5312 100644 --- a/CliFx.Tests/ConversionSpecs.cs +++ b/CliFx.Tests/ConversionSpecs.cs @@ -11,9 +11,7 @@ namespace CliFx.Tests; public class ConversionSpecs : SpecsBase { public ConversionSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_bind_a_parameter_or_an_option_to_a_string_property() @@ -44,7 +42,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "xyz"}, + new[] { "-f", "xyz" }, new Dictionary() ); @@ -84,7 +82,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "xyz"}, + new[] { "-f", "xyz" }, new Dictionary() ); @@ -133,12 +131,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] - { - "-f", "true", - "-b", "false", - "-c" - }, + new[] { "-f", "true", "-b", "false", "-c" }, new Dictionary() ); @@ -146,11 +139,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = True", - "Bar = False", - "Baz = True" - ); + stdOut.Should().ConsistOfLines("Foo = True", "Bar = False", "Baz = True"); } [Fact] @@ -182,7 +171,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "32"}, + new[] { "-f", "32" }, new Dictionary() ); @@ -222,7 +211,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "32.14"}, + new[] { "-f", "32.14" }, new Dictionary() ); @@ -262,7 +251,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "1995-04-28Z"}, + new[] { "-f", "1995-04-28Z" }, new Dictionary() ); @@ -302,7 +291,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "12:34:56"}, + new[] { "-f", "12:34:56" }, new Dictionary() ); @@ -344,7 +333,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "two"}, + new[] { "-f", "two" }, new Dictionary() ); @@ -389,7 +378,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-b", "123"}, + new[] { "-b", "123" }, new Dictionary() ); @@ -397,10 +386,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = ", - "Bar = 123" - ); + stdOut.Should().ConsistOfLines("Foo = ", "Bar = 123"); } [Fact] @@ -439,7 +425,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-b", "two"}, + new[] { "-b", "two" }, new Dictionary() ); @@ -447,10 +433,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = ", - "Bar = 2" - ); + stdOut.Should().ConsistOfLines("Foo = ", "Bar = 2"); } [Fact] @@ -489,7 +472,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "xyz"}, + new[] { "-f", "xyz" }, new Dictionary() ); @@ -554,7 +537,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "hello", "-b", "world"}, + new[] { "-f", "hello", "-b", "world" }, new Dictionary() ); @@ -562,10 +545,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = hello", - "Bar = world" - ); + stdOut.Should().ConsistOfLines("Foo = hello", "Bar = world"); } [Fact] @@ -603,7 +583,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "hello world"}, + new[] { "-f", "hello world" }, new Dictionary() ); @@ -645,7 +625,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "one", "two", "three"}, + new[] { "-f", "one", "two", "three" }, new Dictionary() ); @@ -653,11 +633,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -691,7 +667,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "one", "two", "three"}, + new[] { "-f", "one", "two", "three" }, new Dictionary() ); @@ -699,11 +675,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -737,7 +709,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "one", "two", "three"}, + new[] { "-f", "one", "two", "three" }, new Dictionary() ); @@ -745,11 +717,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -783,7 +751,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "1", "13", "27"}, + new[] { "-f", "1", "13", "27" }, new Dictionary() ); @@ -791,11 +759,7 @@ public class ConversionSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "1", - "13", - "27" - ); + stdOut.Should().ConsistOfLines("1", "13", "27"); } [Fact] @@ -827,7 +791,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "xyz"}, + new[] { "-f", "xyz" }, new Dictionary() ); @@ -870,7 +834,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "one", "two"}, + new[] { "-f", "one", "two" }, new Dictionary() ); @@ -906,7 +870,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "12.34"}, + new[] { "-f", "12.34" }, new Dictionary() ); @@ -952,7 +916,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "12"}, + new[] { "-f", "12" }, new Dictionary() ); @@ -997,7 +961,7 @@ public class ConversionSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "bar"}, + new[] { "-f", "bar" }, new Dictionary() ); @@ -1007,4 +971,4 @@ public class ConversionSpecs : SpecsBase var stdErr = FakeConsole.ReadErrorString(); stdErr.Should().Contain("Hello world"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/DirectivesSpecs.cs b/CliFx.Tests/DirectivesSpecs.cs index 5d260e5..d656951 100644 --- a/CliFx.Tests/DirectivesSpecs.cs +++ b/CliFx.Tests/DirectivesSpecs.cs @@ -14,9 +14,7 @@ namespace CliFx.Tests; public class DirectivesSpecs : SpecsBase { public DirectivesSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact(Timeout = 15000)] public async Task I_can_use_the_debug_directive_to_make_the_application_wait_for_the_debugger_to_attach() @@ -32,9 +30,7 @@ public class DirectivesSpecs : SpecsBase cts.Cancel(); } - var command = - Cli.Wrap(Dummy.Program.FilePath).WithArguments("[debug]") | - HandleStdOut; + var command = Cli.Wrap(Dummy.Program.FilePath).WithArguments("[debug]") | HandleStdOut; // Act & assert try @@ -70,22 +66,29 @@ public class DirectivesSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"[preview]", "cmd", "param", "-abc", "--option", "foo"}, - new Dictionary - { - ["ENV_QOP"] = "hello", - ["ENV_KIL"] = "world" - } + new[] { "[preview]", "cmd", "param", "-abc", "--option", "foo" }, + new Dictionary { ["ENV_QOP"] = "hello", ["ENV_KIL"] = "world" } ); // Assert exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "cmd", "", "[-a]", "[-b]", "[-c]", "[--option \"foo\"]", - "ENV_QOP", "=", "\"hello\"", - "ENV_KIL", "=", "\"world\"" - ); + stdOut + .Should() + .ContainAllInOrder( + "cmd", + "", + "[-a]", + "[-b]", + "[-c]", + "[--option \"foo\"]", + "ENV_QOP", + "=", + "\"hello\"", + "ENV_KIL", + "=", + "\"world\"" + ); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/EnvironmentSpecs.cs b/CliFx.Tests/EnvironmentSpecs.cs index ebdae4f..3731467 100644 --- a/CliFx.Tests/EnvironmentSpecs.cs +++ b/CliFx.Tests/EnvironmentSpecs.cs @@ -15,9 +15,7 @@ namespace CliFx.Tests; public class EnvironmentSpecs : SpecsBase { public EnvironmentSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_configure_an_option_to_fall_back_to_an_environment_variable_if_the_user_does_not_provide_the_corresponding_argument() @@ -53,22 +51,15 @@ public class EnvironmentSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo", "42"}, - new Dictionary - { - ["ENV_FOO"] = "100", - ["ENV_BAR"] = "200" - } + new[] { "--foo", "42" }, + new Dictionary { ["ENV_FOO"] = "100", ["ENV_BAR"] = "200" } ); // Assert exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Trim().Should().ConsistOfLines( - "42", - "200" - ); + stdOut.Trim().Should().ConsistOfLines("42", "200"); } [Fact] @@ -103,20 +94,14 @@ public class EnvironmentSpecs : SpecsBase // Act var exitCode = await application.RunAsync( Array.Empty(), - new Dictionary - { - ["ENV_FOO"] = $"bar{Path.PathSeparator}baz" - } + new Dictionary { ["ENV_FOO"] = $"bar{Path.PathSeparator}baz" } ); // Assert exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "bar", - "baz" - ); + stdOut.Should().ConsistOfLines("bar", "baz"); } [Fact] @@ -149,10 +134,7 @@ public class EnvironmentSpecs : SpecsBase // Act var exitCode = await application.RunAsync( Array.Empty(), - new Dictionary - { - ["ENV_FOO"] = $"bar{Path.PathSeparator}baz" - } + new Dictionary { ["ENV_FOO"] = $"bar{Path.PathSeparator}baz" } ); // Assert @@ -171,9 +153,7 @@ public class EnvironmentSpecs : SpecsBase // Arrange var command = Cli.Wrap(Dummy.Program.FilePath) .WithArguments("env-test") - .WithEnvironmentVariables(e => e - .Set("ENV_TARGET", "Mars") - ); + .WithEnvironmentVariables(e => e.Set("ENV_TARGET", "Mars")); // Act var result = await command.ExecuteBufferedAsync(); @@ -181,4 +161,4 @@ public class EnvironmentSpecs : SpecsBase // Assert result.StandardOutput.Trim().Should().Be("Hello Mars!"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/ErrorReportingSpecs.cs b/CliFx.Tests/ErrorReportingSpecs.cs index dbe71df..9819b5f 100644 --- a/CliFx.Tests/ErrorReportingSpecs.cs +++ b/CliFx.Tests/ErrorReportingSpecs.cs @@ -12,9 +12,7 @@ namespace CliFx.Tests; public class ErrorReportingSpecs : SpecsBase { public ErrorReportingSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_throw_an_exception_in_a_command_to_report_an_error_with_a_stacktrace() @@ -50,10 +48,9 @@ public class ErrorReportingSpecs : SpecsBase stdOut.Should().BeEmpty(); var stdErr = FakeConsole.ReadErrorString(); - stdErr.Should().ContainAllInOrder( - "System.Exception", "Something went wrong", - "at", "CliFx." - ); + stdErr + .Should() + .ContainAllInOrder("System.Exception", "Something went wrong", "at", "CliFx."); } [Fact] @@ -90,11 +87,16 @@ public class ErrorReportingSpecs : SpecsBase stdOut.Should().BeEmpty(); var stdErr = FakeConsole.ReadErrorString(); - stdErr.Should().ContainAllInOrder( - "System.Exception", "Something went wrong", - "System.Exception", "Another exception", - "at", "CliFx." - ); + stdErr + .Should() + .ContainAllInOrder( + "System.Exception", + "Something went wrong", + "System.Exception", + "Another exception", + "at", + "CliFx." + ); } [Fact] @@ -168,10 +170,7 @@ public class ErrorReportingSpecs : SpecsBase stdOut.Should().BeEmpty(); var stdErr = FakeConsole.ReadErrorString(); - stdErr.Should().ContainAllInOrder( - "CliFx.Exceptions.CommandException", - "at", "CliFx." - ); + stdErr.Should().ContainAllInOrder("CliFx.Exceptions.CommandException", "at", "CliFx."); } [Fact] @@ -211,4 +210,4 @@ public class ErrorReportingSpecs : SpecsBase var stdErr = FakeConsole.ReadErrorString(); stdErr.Trim().Should().Be("Something went wrong"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/HelpTextSpecs.cs b/CliFx.Tests/HelpTextSpecs.cs index 05d58c5..d8421ca 100644 --- a/CliFx.Tests/HelpTextSpecs.cs +++ b/CliFx.Tests/HelpTextSpecs.cs @@ -12,9 +12,7 @@ namespace CliFx.Tests; public class HelpTextSpecs : SpecsBase { public HelpTextSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_request_the_help_text_by_running_the_application_without_arguments_if_the_default_command_is_not_defined() @@ -61,7 +59,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -101,7 +99,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -146,7 +144,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"cmd", "--help"}, + new[] { "cmd", "--help" }, new Dictionary() ); @@ -191,7 +189,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"cmd", "sub", "--help"}, + new[] { "cmd", "sub", "--help" }, new Dictionary() ); @@ -214,7 +212,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"invalid-command", "--invalid-option"}, + new[] { "invalid-command", "--invalid-option" }, new Dictionary() ); @@ -241,7 +239,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -249,11 +247,7 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAll( - "App title", - "App description", - "App version" - ); + stdOut.Should().ContainAll("App title", "App description", "App version"); } [Fact] @@ -278,7 +272,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -286,10 +280,7 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "DESCRIPTION", - "Description of the default command." - ); + stdOut.Should().ContainAllInOrder("DESCRIPTION", "Description of the default command."); } [Fact] @@ -320,7 +311,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -328,10 +319,7 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "USAGE", - "[command]", "[...]" - ); + stdOut.Should().ContainAllInOrder("USAGE", "[command]", "[...]"); } [Fact] @@ -365,7 +353,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -373,10 +361,7 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "USAGE", - "", "", "" - ); + stdOut.Should().ContainAllInOrder("USAGE", "", "", ""); } // https://github.com/Tyrrrz/CliFx/issues/117 @@ -425,10 +410,7 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "USAGE", - "", "", "" - ); + stdOut.Should().ContainAllInOrder("USAGE", "", "", ""); } [Fact] @@ -462,7 +444,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -470,10 +452,9 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "USAGE", - "--foo ", "--baz ", "[options]" - ); + stdOut + .Should() + .ContainAllInOrder("USAGE", "--foo ", "--baz ", "[options]"); } [Fact] @@ -504,7 +485,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -512,12 +493,16 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "PARAMETERS", - "foo", "Description of foo.", - "OPTIONS", - "--bar", "Description of bar." - ); + stdOut + .Should() + .ContainAllInOrder( + "PARAMETERS", + "foo", + "Description of foo.", + "OPTIONS", + "--bar", + "Description of bar." + ); } [Fact] @@ -542,7 +527,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -550,11 +535,16 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "OPTIONS", - "-h", "--help", "Shows help text", - "--version", "Shows version information" - ); + stdOut + .Should() + .ContainAllInOrder( + "OPTIONS", + "-h", + "--help", + "Shows help text", + "--version", + "Shows version information" + ); } [Fact] @@ -579,7 +569,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"cmd", "--help"}, + new[] { "cmd", "--help" }, new Dictionary() ); @@ -588,14 +578,9 @@ public class HelpTextSpecs : SpecsBase var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "OPTIONS", - "-h", "--help", "Shows help text" - ); + stdOut.Should().ContainAllInOrder("OPTIONS", "-h", "--help", "Shows help text"); - stdOut.Should().NotContainAny( - "--version", "Shows version information" - ); + stdOut.Should().NotContainAny("--version", "Shows version information"); } [Fact] @@ -628,7 +613,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -636,12 +621,22 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "PARAMETERS", - "foo", "Choices:", "One", "Two", "Three", - "OPTIONS", - "--bar", "Choices:", "One", "Two", "Three" - ); + stdOut + .Should() + .ContainAllInOrder( + "PARAMETERS", + "foo", + "Choices:", + "One", + "Two", + "Three", + "OPTIONS", + "--bar", + "Choices:", + "One", + "Two", + "Three" + ); } [Fact] @@ -674,7 +669,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -682,12 +677,22 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "PARAMETERS", - "foo", "Choices:", "One", "Two", "Three", - "OPTIONS", - "--bar", "Choices:", "One", "Two", "Three" - ); + stdOut + .Should() + .ContainAllInOrder( + "PARAMETERS", + "foo", + "Choices:", + "One", + "Two", + "Three", + "OPTIONS", + "--bar", + "Choices:", + "One", + "Two", + "Three" + ); } [Fact] @@ -720,7 +725,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -728,12 +733,22 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "PARAMETERS", - "foo", "Choices:", "One", "Two", "Three", - "OPTIONS", - "--bar", "Choices:", "One", "Two", "Three" - ); + stdOut + .Should() + .ContainAllInOrder( + "PARAMETERS", + "foo", + "Choices:", + "One", + "Two", + "Three", + "OPTIONS", + "--bar", + "Choices:", + "One", + "Two", + "Three" + ); } [Fact] @@ -766,7 +781,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -774,11 +789,17 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "OPTIONS", - "--foo", "Environment variable:", "ENV_FOO", - "--bar", "Environment variable:", "ENV_BAR" - ); + stdOut + .Should() + .ContainAllInOrder( + "OPTIONS", + "--foo", + "Environment variable:", + "ENV_FOO", + "--bar", + "Environment variable:", + "ENV_BAR" + ); } [Fact] @@ -829,7 +850,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -838,16 +859,34 @@ public class HelpTextSpecs : SpecsBase var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "OPTIONS", - "--foo", "Default:", "42", - "--bar", "Default:", "hello", - "--baz", "Default:", "one", "two", "three", - "--qwe", "Default:", "True", - "--qop", "Default:", "1337", - "--zor", "Default:", "02:03:00", - "--lol", "Default:", "Two" - ); + stdOut + .Should() + .ContainAllInOrder( + "OPTIONS", + "--foo", + "Default:", + "42", + "--bar", + "Default:", + "hello", + "--baz", + "Default:", + "one", + "two", + "three", + "--qwe", + "Default:", + "True", + "--qop", + "Default:", + "1337", + "--zor", + "Default:", + "02:03:00", + "--lol", + "Default:", + "Two" + ); stdOut.Should().NotContain("not printed"); } @@ -892,7 +931,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -901,20 +940,23 @@ public class HelpTextSpecs : SpecsBase var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "COMMANDS", - "cmd1", "Description of one command.", - "cmd2", "Description of another command.", - // `cmd2 child` will appear as an immediate command because it does not - // have a more specific parent. - "cmd3 child", "Description of an orphaned command." - ); + stdOut + .Should() + .ContainAllInOrder( + "COMMANDS", + "cmd1", + "Description of one command.", + "cmd2", + "Description of another command.", + // `cmd2 child` will appear as an immediate command because it does not + // have a more specific parent. + "cmd3 child", + "Description of an orphaned command." + ); // `cmd2 child` will still appear in the list of `cmd2` subcommands, // but its description will not be visible. - stdOut.Should().NotContain( - "Description of another command's child command." - ); + stdOut.Should().NotContain("Description of another command's child command."); } [Fact] @@ -963,7 +1005,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--help"}, + new[] { "--help" }, new Dictionary() ); @@ -971,11 +1013,18 @@ public class HelpTextSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ContainAllInOrder( - "COMMANDS", - "cmd1", "Subcommands:", "cmd1 child1", - "cmd2", "Subcommands:", "cmd2 child1", "cmd2 child2" - ); + stdOut + .Should() + .ContainAllInOrder( + "COMMANDS", + "cmd1", + "Subcommands:", + "cmd1 child1", + "cmd2", + "Subcommands:", + "cmd2 child1", + "cmd2 child2" + ); } [Fact] @@ -990,7 +1039,7 @@ public class HelpTextSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--version"}, + new[] { "--version" }, new Dictionary() ); @@ -1000,4 +1049,4 @@ public class HelpTextSpecs : SpecsBase var stdOut = FakeConsole.ReadOutputString(); stdOut.Trim().Should().Be("v6.9"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/OptionBindingSpecs.cs b/CliFx.Tests/OptionBindingSpecs.cs index e45a388..6fb1af8 100644 --- a/CliFx.Tests/OptionBindingSpecs.cs +++ b/CliFx.Tests/OptionBindingSpecs.cs @@ -12,9 +12,7 @@ namespace CliFx.Tests; public class OptionBindingSpecs : SpecsBase { public OptionBindingSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_bind_an_option_to_a_property_and_get_the_value_from_the_corresponding_argument_by_name() @@ -45,7 +43,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo"}, + new[] { "--foo" }, new Dictionary() ); @@ -84,10 +82,7 @@ public class OptionBindingSpecs : SpecsBase .Build(); // Act - var exitCode = await application.RunAsync( - new[] {"-f"}, - new Dictionary() - ); + var exitCode = await application.RunAsync(new[] { "-f" }, new Dictionary()); // Assert exitCode.Should().Be(0); @@ -130,11 +125,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] - { - "--foo", "one", - "--bar", "two" - }, + new[] { "--foo", "one", "--bar", "two" }, new Dictionary() ); @@ -142,10 +133,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = one", - "Bar = two" - ); + stdOut.Should().ConsistOfLines("Foo = one", "Bar = two"); } [Fact] @@ -182,11 +170,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] - { - "-f", "one", - "-b", "two" - }, + new[] { "-f", "one", "-b", "two" }, new Dictionary() ); @@ -194,10 +178,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = one", - "Bar = two" - ); + stdOut.Should().ConsistOfLines("Foo = one", "Bar = two"); } [Fact] @@ -234,7 +215,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-fb", "value"}, + new[] { "-fb", "value" }, new Dictionary() ); @@ -242,10 +223,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = ", - "Bar = value" - ); + stdOut.Should().ConsistOfLines("Foo = ", "Bar = value"); } [Fact] @@ -279,7 +257,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo", "one", "two", "three"}, + new[] { "--foo", "one", "two", "three" }, new Dictionary() ); @@ -287,11 +265,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -325,7 +299,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"-f", "one", "two", "three"}, + new[] { "-f", "one", "two", "three" }, new Dictionary() ); @@ -333,11 +307,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -371,12 +341,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] - { - "--foo", "one", - "--foo", "two", - "--foo", "three" - }, + new[] { "--foo", "one", "--foo", "two", "--foo", "three" }, new Dictionary() ); @@ -384,11 +349,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -422,12 +383,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] - { - "-f", "one", - "-f", "two", - "-f", "three" - }, + new[] { "-f", "one", "-f", "two", "-f", "three" }, new Dictionary() ); @@ -435,11 +391,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -473,12 +425,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] - { - "--foo", "one", - "-f", "two", - "--foo", "three" - }, + new[] { "--foo", "one", "-f", "two", "--foo", "three" }, new Dictionary() ); @@ -486,11 +433,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "one", - "two", - "three" - ); + stdOut.Should().ConsistOfLines("one", "two", "three"); } [Fact] @@ -527,7 +470,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo", "one"}, + new[] { "--foo", "one" }, new Dictionary() ); @@ -535,10 +478,7 @@ public class OptionBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = one", - "Bar = hello" - ); + stdOut.Should().ConsistOfLines("Foo = one", "Bar = hello"); } [Fact] @@ -604,24 +544,13 @@ public class OptionBindingSpecs : SpecsBase .Build(); // Act - var exitCode = await application.RunAsync( - new[] - { - "--foo", "42", - "--bar", - "--baz", "xyz" - } - ); + var exitCode = await application.RunAsync(new[] { "--foo", "42", "--bar", "--baz", "xyz" }); // Assert exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = 42", - "Bar = True", - "Baz = xyz" - ); + stdOut.Should().ConsistOfLines("Foo = 42", "Bar = True", "Baz = xyz"); } [Fact] @@ -653,7 +582,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo", "-13"}, + new[] { "--foo", "-13" }, new Dictionary() ); @@ -725,7 +654,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo"}, + new[] { "--foo" }, new Dictionary() ); @@ -761,7 +690,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo"}, + new[] { "--foo" }, new Dictionary() ); @@ -797,11 +726,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] - { - "--foo", "one", - "--bar", "two" - }, + new[] { "--foo", "one", "--bar", "two" }, new Dictionary() ); @@ -837,7 +762,7 @@ public class OptionBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"--foo", "one", "two", "three"}, + new[] { "--foo", "one", "two", "three" }, new Dictionary() ); @@ -847,4 +772,4 @@ public class OptionBindingSpecs : SpecsBase var stdErr = FakeConsole.ReadErrorString(); stdErr.Should().Contain("expects a single argument, but provided with multiple"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/ParameterBindingSpecs.cs b/CliFx.Tests/ParameterBindingSpecs.cs index 3390c84..f162966 100644 --- a/CliFx.Tests/ParameterBindingSpecs.cs +++ b/CliFx.Tests/ParameterBindingSpecs.cs @@ -11,9 +11,7 @@ namespace CliFx.Tests; public class ParameterBindingSpecs : SpecsBase { public ParameterBindingSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_bind_a_parameter_to_a_property_and_get_the_value_from_the_corresponding_argument() @@ -49,7 +47,7 @@ public class ParameterBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"one", "two"}, + new[] { "one", "two" }, new Dictionary() ); @@ -57,10 +55,7 @@ public class ParameterBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = one", - "Bar = two" - ); + stdOut.Should().ConsistOfLines("Foo = one", "Bar = two"); } [Fact] @@ -106,7 +101,7 @@ public class ParameterBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"one", "two", "three", "four", "five", "--boo", "xxx"}, + new[] { "one", "two", "three", "four", "five", "--boo", "xxx" }, new Dictionary() ); @@ -114,13 +109,9 @@ public class ParameterBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = one", - "Bar = two", - "Baz = three", - "Baz = four", - "Baz = five" - ); + stdOut + .Should() + .ConsistOfLines("Foo = one", "Bar = two", "Baz = three", "Baz = four", "Baz = five"); } [Fact] @@ -151,7 +142,7 @@ public class ParameterBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"one"}, + new[] { "one" }, new Dictionary() ); @@ -190,7 +181,7 @@ public class ParameterBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"one"}, + new[] { "one" }, new Dictionary() ); @@ -235,7 +226,7 @@ public class ParameterBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"abc"}, + new[] { "abc" }, new Dictionary() ); @@ -243,10 +234,7 @@ public class ParameterBindingSpecs : SpecsBase exitCode.Should().Be(0); var stdOut = FakeConsole.ReadOutputString(); - stdOut.Should().ConsistOfLines( - "Foo = abc", - "Bar = xyz" - ); + stdOut.Should().ConsistOfLines("Foo = abc", "Bar = xyz"); } [Fact] @@ -277,7 +265,7 @@ public class ParameterBindingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"one", "two", "three"}, + new[] { "one", "two", "three" }, new Dictionary() ); @@ -287,4 +275,4 @@ public class ParameterBindingSpecs : SpecsBase var stdErr = FakeConsole.ReadErrorString(); stdErr.Should().Contain("Unexpected parameter(s)"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/RoutingSpecs.cs b/CliFx.Tests/RoutingSpecs.cs index 5d3146a..e3ce9a2 100644 --- a/CliFx.Tests/RoutingSpecs.cs +++ b/CliFx.Tests/RoutingSpecs.cs @@ -11,9 +11,7 @@ namespace CliFx.Tests; public class RoutingSpecs : SpecsBase { public RoutingSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_configure_a_command_to_be_executed_by_default_when_the_user_does_not_specify_a_command_name() @@ -118,7 +116,7 @@ public class RoutingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"cmd"}, + new[] { "cmd" }, new Dictionary() ); @@ -175,7 +173,7 @@ public class RoutingSpecs : SpecsBase // Act var exitCode = await application.RunAsync( - new[] {"cmd", "child"}, + new[] { "cmd", "child" }, new Dictionary() ); @@ -185,4 +183,4 @@ public class RoutingSpecs : SpecsBase var stdOut = FakeConsole.ReadOutputString(); stdOut.Trim().Should().Be("cmd child"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/SpecsBase.cs b/CliFx.Tests/SpecsBase.cs index c5d223f..e5cdac0 100644 --- a/CliFx.Tests/SpecsBase.cs +++ b/CliFx.Tests/SpecsBase.cs @@ -11,12 +11,11 @@ public abstract class SpecsBase : IDisposable public FakeInMemoryConsole FakeConsole { get; } = new(); - protected SpecsBase(ITestOutputHelper testOutput) => - TestOutput = testOutput; + protected SpecsBase(ITestOutputHelper testOutput) => TestOutput = testOutput; public void Dispose() { FakeConsole.DumpToTestOutput(TestOutput); FakeConsole.Dispose(); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/TypeActivationSpecs.cs b/CliFx.Tests/TypeActivationSpecs.cs index cadeb81..b5cc618 100644 --- a/CliFx.Tests/TypeActivationSpecs.cs +++ b/CliFx.Tests/TypeActivationSpecs.cs @@ -13,9 +13,7 @@ namespace CliFx.Tests; public class TypeActivationSpecs : SpecsBase { public TypeActivationSpecs(ITestOutputHelper testOutput) - : base(testOutput) - { - } + : base(testOutput) { } [Fact] public async Task I_can_configure_the_application_to_use_the_default_type_activator_to_initialize_types_through_parameterless_constructors() @@ -225,4 +223,4 @@ public class TypeActivationSpecs : SpecsBase var stdErr = FakeConsole.ReadErrorString(); stdErr.Should().Contain("Failed to create an instance of type"); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/Utils/DynamicCommandBuilder.cs b/CliFx.Tests/Utils/DynamicCommandBuilder.cs index 2cad754..0819aa1 100644 --- a/CliFx.Tests/Utils/DynamicCommandBuilder.cs +++ b/CliFx.Tests/Utils/DynamicCommandBuilder.cs @@ -31,8 +31,7 @@ internal static class DynamicCommandBuilder }; // Get default CliFx namespaces - var defaultCliFxNamespaces = typeof(ICommand) - .Assembly + var defaultCliFxNamespaces = typeof(ICommand).Assembly .GetTypes() .Where(t => t.IsPublic) .Select(t => t.Namespace) @@ -41,10 +40,10 @@ internal static class DynamicCommandBuilder // Append default imports to the source code var sourceCodeWithUsings = - string.Join(Environment.NewLine, defaultSystemNamespaces.Select(n => $"using {n};")) + - string.Join(Environment.NewLine, defaultCliFxNamespaces.Select(n => $"using {n};")) + - Environment.NewLine + - sourceCode; + string.Join(Environment.NewLine, defaultSystemNamespaces.Select(n => $"using {n};")) + + string.Join(Environment.NewLine, defaultCliFxNamespaces.Select(n => $"using {n};")) + + Environment.NewLine + + sourceCode; // Parse the source code var ast = SyntaxFactory.ParseSyntaxTree( @@ -55,10 +54,14 @@ internal static class DynamicCommandBuilder // Compile the code to IL var compilation = CSharpCompilation.Create( "CliFxTests_DynamicAssembly_" + Guid.NewGuid(), - new[] {ast}, + new[] { ast }, Net70.References.All .Append(MetadataReference.CreateFromFile(typeof(ICommand).Assembly.Location)) - .Append(MetadataReference.CreateFromFile(typeof(DynamicCommandBuilder).Assembly.Location)), + .Append( + MetadataReference.CreateFromFile( + typeof(DynamicCommandBuilder).Assembly.Location + ) + ), // DLL to avoid having to define the Main() method new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) ); @@ -82,8 +85,7 @@ internal static class DynamicCommandBuilder using var buffer = new MemoryStream(); var emit = compilation.Emit(buffer); - var emitErrors = emit - .Diagnostics + var emitErrors = emit.Diagnostics .Where(d => d.Severity >= DiagnosticSeverity.Error) .ToArray(); @@ -128,4 +130,4 @@ internal static class DynamicCommandBuilder return commandTypes.Single(); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs b/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs index 7b6f893..8cd3a38 100644 --- a/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs +++ b/CliFx.Tests/Utils/Extensions/AssertionExtensions.cs @@ -8,22 +8,22 @@ namespace CliFx.Tests.Utils.Extensions; internal static class AssertionExtensions { - public static void ConsistOfLines( - this StringAssertions assertions, - IEnumerable lines) + public static void ConsistOfLines(this StringAssertions assertions, IEnumerable lines) { - var actualLines = assertions.Subject.Split(new[] {'\n', '\r'}, StringSplitOptions.RemoveEmptyEntries); + var actualLines = assertions.Subject.Split( + new[] { '\n', '\r' }, + StringSplitOptions.RemoveEmptyEntries + ); actualLines.Should().Equal(lines); } - public static void ConsistOfLines( - this StringAssertions assertions, - params string[] lines) => - assertions.ConsistOfLines((IEnumerable) lines); + public static void ConsistOfLines(this StringAssertions assertions, params string[] lines) => + assertions.ConsistOfLines((IEnumerable)lines); public static AndConstraint ContainAllInOrder( this StringAssertions assertions, - IEnumerable values) + IEnumerable values + ) { var lastIndex = 0; @@ -46,6 +46,6 @@ internal static class AssertionExtensions public static AndConstraint ContainAllInOrder( this StringAssertions assertions, - params string[] values) => - assertions.ContainAllInOrder((IEnumerable) values); -} \ No newline at end of file + params string[] values + ) => assertions.ContainAllInOrder((IEnumerable)values); +} diff --git a/CliFx.Tests/Utils/Extensions/ConsoleExtensions.cs b/CliFx.Tests/Utils/Extensions/ConsoleExtensions.cs index febbdb4..5633713 100644 --- a/CliFx.Tests/Utils/Extensions/ConsoleExtensions.cs +++ b/CliFx.Tests/Utils/Extensions/ConsoleExtensions.cs @@ -5,7 +5,10 @@ namespace CliFx.Tests.Utils.Extensions; internal static class ConsoleExtensions { - public static void DumpToTestOutput(this FakeInMemoryConsole console, ITestOutputHelper testOutputHelper) + public static void DumpToTestOutput( + this FakeInMemoryConsole console, + ITestOutputHelper testOutputHelper + ) { testOutputHelper.WriteLine("[*] Captured standard output:"); testOutputHelper.WriteLine(console.ReadOutputString()); @@ -13,4 +16,4 @@ internal static class ConsoleExtensions testOutputHelper.WriteLine("[*] Captured standard error:"); testOutputHelper.WriteLine(console.ReadErrorString()); } -} \ No newline at end of file +} diff --git a/CliFx.Tests/Utils/NoOpCommand.cs b/CliFx.Tests/Utils/NoOpCommand.cs index c2b5a99..812c014 100644 --- a/CliFx.Tests/Utils/NoOpCommand.cs +++ b/CliFx.Tests/Utils/NoOpCommand.cs @@ -8,4 +8,4 @@ namespace CliFx.Tests.Utils; internal class NoOpCommand : ICommand { public ValueTask ExecuteAsync(IConsole console) => default; -} \ No newline at end of file +} diff --git a/CliFx/CliFx.csproj b/CliFx/CliFx.csproj index e8972a1..fba6242 100644 --- a/CliFx/CliFx.csproj +++ b/CliFx/CliFx.csproj @@ -24,6 +24,7 @@ +