diff --git a/.editorconfig b/.editorconfig index 29e4d106..1d983924 100644 --- a/.editorconfig +++ b/.editorconfig @@ -25,7 +25,7 @@ dotnet_sort_system_directives_first = true # Stuff that is usually best csharp_style_inlined_variable_declaration = true csharp_style_var_elsewhere = true -csharp_space_after_cast = true +csharp_space_after_cast = false csharp_style_pattern_matching_over_as_with_null_check = true csharp_style_pattern_matching_over_is_with_cast_check = true csharp_style_var_for_built_in_types = true diff --git a/src/CommandLineUtils/Conventions/ConstructorInjectionConvention.cs b/src/CommandLineUtils/Conventions/ConstructorInjectionConvention.cs index fa64fe08..709a9671 100644 --- a/src/CommandLineUtils/Conventions/ConstructorInjectionConvention.cs +++ b/src/CommandLineUtils/Conventions/ConstructorInjectionConvention.cs @@ -62,7 +62,7 @@ private void ApplyImpl(ConventionContext context) if (factory != null) { - ((CommandLineApplication) context.Application).ModelFactory = factory; + ((CommandLineApplication)context.Application).ModelFactory = factory; } } @@ -104,11 +104,11 @@ private void ApplyImpl(ConventionContext context) args[i] = service; if (i == parameters.Length - 1) { - return () => (TModel) ctorCandidate.Invoke(args); + return () => (TModel)ctorCandidate.Invoke(args); } } - nextCtor: ; + nextCtor:; } return () => throw new InvalidOperationException(Strings.NoMatchedConstructorFound(typeof(TModel))); diff --git a/src/CommandLineUtils/Conventions/ExecuteMethodConvention.cs b/src/CommandLineUtils/Conventions/ExecuteMethodConvention.cs index 9d0e24b8..a24203b2 100644 --- a/src/CommandLineUtils/Conventions/ExecuteMethodConvention.cs +++ b/src/CommandLineUtils/Conventions/ExecuteMethodConvention.cs @@ -80,7 +80,7 @@ private async Task InvokeAsync(MethodInfo method, object instance, object[] { try { - var result = (Task) method.Invoke(instance, arguments); + var result = (Task)method.Invoke(instance, arguments); if (result is Task intResult) { return await intResult; @@ -103,7 +103,7 @@ private int Invoke(MethodInfo method, object instance, object[] arguments) var result = method.Invoke(instance, arguments); if (method.ReturnType == typeof(int)) { - return (int) result; + return (int)result; } } catch (TargetInvocationException e) diff --git a/src/CommandLineUtils/Internal/AnsiConsole.cs b/src/CommandLineUtils/Internal/AnsiConsole.cs index 31d5ce5b..24b53e22 100644 --- a/src/CommandLineUtils/Internal/AnsiConsole.cs +++ b/src/CommandLineUtils/Internal/AnsiConsole.cs @@ -62,7 +62,7 @@ public void WriteLine(string message) } var escapeScan = 0; - for (; ;) + for (; ; ) { var escapeIndex = message.IndexOf("\x1b[", escapeScan); if (escapeIndex == -1) diff --git a/src/CommandLineUtils/Internal/CommandLineProcessor.cs b/src/CommandLineUtils/Internal/CommandLineProcessor.cs index 79bb0964..155a32a9 100644 --- a/src/CommandLineUtils/Internal/CommandLineProcessor.cs +++ b/src/CommandLineUtils/Internal/CommandLineProcessor.cs @@ -399,10 +399,12 @@ public CommandOrParameterArgument(string raw) : base(raw) private class OptionArgument : Argument { + private static readonly char[] NameValueSeparators = { ':', '=' }; + public OptionArgument(string raw, bool isShortOption) : base(raw) { IsShortOption = isShortOption; - var parts = Raw.Split(new[] { ':', '=' }, 2); + var parts = Raw.Split(NameValueSeparators, 2); if (parts.Length > 1) { Value = parts[1]; @@ -414,8 +416,8 @@ public OptionArgument(string raw, bool isShortOption) : base(raw) Name = parts[0].Substring(sublen); } - public string Name { get; set; } - public string? Value { get; set; } + public string Name { get; } + public string? Value { get; } public bool IsShortOption { get; } } diff --git a/src/CommandLineUtils/Internal/StringDistance.cs b/src/CommandLineUtils/Internal/StringDistance.cs index f62995a7..3a433c81 100644 --- a/src/CommandLineUtils/Internal/StringDistance.cs +++ b/src/CommandLineUtils/Internal/StringDistance.cs @@ -123,7 +123,7 @@ internal static double NormalizeDistance(int distance, int length) return 1; } - return 1.0d - distance / (double) length; + return 1.0d - distance / (double)length; } /// diff --git a/src/CommandLineUtils/Internal/ValueParsers/StockValueParsers.cs b/src/CommandLineUtils/Internal/ValueParsers/StockValueParsers.cs index 1ed3c933..fd209368 100644 --- a/src/CommandLineUtils/Internal/ValueParsers/StockValueParsers.cs +++ b/src/CommandLineUtils/Internal/ValueParsers/StockValueParsers.cs @@ -58,23 +58,23 @@ private static IValueParser FloatingPointParser(NumberParser parser) => (argName, value) => InvalidValueException(argName, $"'{value}' is not a valid floating-point number.")); public static readonly IValueParser Double = FloatingPointParser(double.TryParse); - public static readonly IValueParser Float = FloatingPointParser (float.TryParse ); + public static readonly IValueParser Float = FloatingPointParser(float.TryParse); private static IValueParser IntegerParser(NumberParser parser) => Create(parser, NumberStyles.Integer, (argName, value) => InvalidValueException(argName, $"'{value}' is not a valid number.")); public static readonly IValueParser Int16 = IntegerParser(short.TryParse); - public static readonly IValueParser Int32 = IntegerParser (int.TryParse ); - public static readonly IValueParser Int64 = IntegerParser (long.TryParse ); + public static readonly IValueParser Int32 = IntegerParser(int.TryParse); + public static readonly IValueParser Int64 = IntegerParser(long.TryParse); private static IValueParser NonNegativeIntegerParser(NumberParser parser) => Create(parser, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, (argName, value) => InvalidValueException(argName, $"'{value}' is not a valid, non-negative number.")); - public static readonly IValueParser Byte = NonNegativeIntegerParser (byte.TryParse ); + public static readonly IValueParser Byte = NonNegativeIntegerParser(byte.TryParse); public static readonly IValueParser UInt16 = NonNegativeIntegerParser(ushort.TryParse); - public static readonly IValueParser UInt32 = NonNegativeIntegerParser (uint.TryParse ); - public static readonly IValueParser UInt64 = NonNegativeIntegerParser (ulong.TryParse ); + public static readonly IValueParser UInt32 = NonNegativeIntegerParser(uint.TryParse); + public static readonly IValueParser UInt64 = NonNegativeIntegerParser(ulong.TryParse); private delegate bool DateTimeParser(string s, IFormatProvider provider, DateTimeStyles styles, out T result); diff --git a/src/CommandLineUtils/Utilities/ArgumentEscaper.cs b/src/CommandLineUtils/Utilities/ArgumentEscaper.cs index aa761d77..ebe322a5 100644 --- a/src/CommandLineUtils/Utilities/ArgumentEscaper.cs +++ b/src/CommandLineUtils/Utilities/ArgumentEscaper.cs @@ -93,6 +93,6 @@ private static bool IsSurroundedWithQuotes(string argument) } private static bool ContainsWhitespace(string argument) - => argument.IndexOfAny(new [] { ' ', '\t', '\n' }) >= 0; + => argument.IndexOfAny(new[] { ' ', '\t', '\n' }) >= 0; } } diff --git a/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs b/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs index 36bcc514..e82a770a 100644 --- a/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs +++ b/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs @@ -44,7 +44,8 @@ public void CommandNameCanBeMatched() public void CommandsNamesAreCaseInsensitive() { var app = new CommandLineApplication(); - var cmd = app.Command("TEST", c => { + var cmd = app.Command("TEST", c => + { c.OnExecute(() => 5); }); cmd.AddName("TE"); @@ -106,10 +107,10 @@ public void ItThrowsIfAnotherSubcommandHasNameName() c.AddName("s"); }); - var ex = Assert.Throws(() => app.Command("sub1", _ => {})); + var ex = Assert.Throws(() => app.Command("sub1", _ => { })); Assert.Equal(Strings.DuplicateSubcommandName("sub1"), ex.Message); - ex = Assert.Throws(() => app.Command("s", _ => {})); + ex = Assert.Throws(() => app.Command("s", _ => { })); Assert.Equal(Strings.DuplicateSubcommandName("s"), ex.Message); } @@ -947,7 +948,7 @@ public void LongOptionsCanBeCaseInsensitive() public void CommandNamesMatchingIsCaseInsensitive() { var app = new CommandLineApplication(throwOnUnexpectedArg: false); - var cmd = app.Command("CMD1", _ => {}); + var cmd = app.Command("CMD1", _ => { }); Assert.Same(cmd, app.Parse("CMD1").SelectedCommand); Assert.Same(cmd, app.Parse("cmd1").SelectedCommand); diff --git a/test/CommandLineUtils.Tests/CommandNameFromTypeConventionTests.cs b/test/CommandLineUtils.Tests/CommandNameFromTypeConventionTests.cs index f17656dc..4f238dd7 100644 --- a/test/CommandLineUtils.Tests/CommandNameFromTypeConventionTests.cs +++ b/test/CommandLineUtils.Tests/CommandNameFromTypeConventionTests.cs @@ -19,10 +19,10 @@ public void ItInfersCommandName(string typeName, string commandName) [Subcommand(typeof(AddCommand))] private class Program - {} + { } private class AddCommand - {} + { } [Fact] public void ItInfersSubcommandNameFromTypeName() diff --git a/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs b/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs index 1e920428..df167410 100644 --- a/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs +++ b/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs @@ -167,7 +167,7 @@ public void HelpOptionIsInherited() { var sb = new StringBuilder(); var outWriter = new StringWriter(sb); - var app = new CommandLineApplication {Out = outWriter}; + var app = new CommandLineApplication { Out = outWriter }; app.Conventions.UseDefaultConventions(); app.Commands.ForEach(f => f.Out = outWriter); app.Execute("lvl2", "--help"); @@ -204,7 +204,8 @@ public void NestedHelpOptionsChoosesHelpOptionNearestSelectedCommand(string[] ar }); }); - app.OnExecute(() => { + app.OnExecute(() => + { app.ShowHelp(); return 1; }); diff --git a/test/CommandLineUtils.Tests/StringDistanceTests.cs b/test/CommandLineUtils.Tests/StringDistanceTests.cs index 01d40aeb..4a6b28c2 100644 --- a/test/CommandLineUtils.Tests/StringDistanceTests.cs +++ b/test/CommandLineUtils.Tests/StringDistanceTests.cs @@ -107,8 +107,8 @@ public void SortedMatches(string value, string candidates, string expectedOutput [Fact] public void MatchingWithNullReturnsNull() { - Assert.Empty(StringDistance.GetBestMatchesSorted(null, "", new []{ ""}, 0)); - Assert.Empty(StringDistance.GetBestMatchesSorted((s, s1) => 1, null, new []{ ""}, 0)); + Assert.Empty(StringDistance.GetBestMatchesSorted(null, "", new[] { "" }, 0)); + Assert.Empty(StringDistance.GetBestMatchesSorted((s, s1) => 1, null, new[] { "" }, 0)); Assert.Empty(StringDistance.GetBestMatchesSorted((s, s1) => 1, "", null, 0)); } diff --git a/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs b/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs index 44e1e17c..987edc14 100755 --- a/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs +++ b/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs @@ -190,7 +190,7 @@ private void OnExecute() [Command("LEVEL1")] private class Level1DuplicateCmd - {} + { } [Fact] public void CommandNamesCannotDifferByCaseOnly() diff --git a/test/CommandLineUtils.Tests/ValidateMethodConventionTests.cs b/test/CommandLineUtils.Tests/ValidateMethodConventionTests.cs index 4010fde8..b3f5acf3 100644 --- a/test/CommandLineUtils.Tests/ValidateMethodConventionTests.cs +++ b/test/CommandLineUtils.Tests/ValidateMethodConventionTests.cs @@ -79,8 +79,8 @@ private ValidationResult OnValidate(ValidationContext context, CommandLineContex } Assert.Equal(typeof(CommandLineApplication), context.ObjectInstance.GetType()); - var subcommand = (CommandLineApplication) context.ObjectInstance; - var main = (CommandLineApplication?) subcommand.Parent; + var subcommand = (CommandLineApplication)context.ObjectInstance; + var main = (CommandLineApplication?)subcommand.Parent; var middle = main?.Model.Middle; if (middle.HasValue) diff --git a/test/CommandLineUtils.Tests/ValidationTests.cs b/test/CommandLineUtils.Tests/ValidationTests.cs index 2a991951..0fd79fd4 100644 --- a/test/CommandLineUtils.Tests/ValidationTests.cs +++ b/test/CommandLineUtils.Tests/ValidationTests.cs @@ -100,7 +100,7 @@ public void RequiredOption_Attribute_Pass() Assert.Equal(0, CommandLineApplication.Execute("-p", "p")); } -// Workaround https://github.com/dotnet/roslyn/issues/33199 https://github.com/xunit/xunit/issues/1897 + // Workaround https://github.com/dotnet/roslyn/issues/33199 https://github.com/xunit/xunit/issues/1897 #nullable disable [Theory] [InlineData(null)] diff --git a/test/CommandLineUtils.Tests/ValueParserProviderTests.cs b/test/CommandLineUtils.Tests/ValueParserProviderTests.cs index 6be75536..a7095d3e 100644 --- a/test/CommandLineUtils.Tests/ValueParserProviderTests.cs +++ b/test/CommandLineUtils.Tests/ValueParserProviderTests.cs @@ -128,7 +128,7 @@ public void Dispose() } } -// Workaround https://github.com/dotnet/roslyn/issues/33199 https://github.com/xunit/xunit/issues/1897 + // Workaround https://github.com/dotnet/roslyn/issues/33199 https://github.com/xunit/xunit/issues/1897 #nullable disable public static IEnumerable GetFloatingPointSymbolsData() { diff --git a/test/Hosting.CommandLine.Tests/HostBuilderExtensionsTests.cs b/test/Hosting.CommandLine.Tests/HostBuilderExtensionsTests.cs index 1d2803ba..7b5b09b7 100644 --- a/test/Hosting.CommandLine.Tests/HostBuilderExtensionsTests.cs +++ b/test/Hosting.CommandLine.Tests/HostBuilderExtensionsTests.cs @@ -51,7 +51,7 @@ public async void TestConventionInjection() var convention = new Mock(); convention.Setup(c => c.Apply(It.IsAny())) .Callback((ConventionContext c) => c.Application.ThrowOnUnexpectedArgument = false).Verifiable(); - var args = new[] {"Capture", "some", "test", "arguments"}; + var args = new[] { "Capture", "some", "test", "arguments" }; await new HostBuilder() .ConfigureServices(collection => collection .AddSingleton(new TestConsole(_output)) @@ -68,10 +68,10 @@ public void ItThrowsOnUnknownSubCommand() var ex = Assert.Throws( () => new HostBuilder() .ConfigureServices(collection => collection.AddSingleton(new TestConsole(_output))) - .RunCommandLineApplicationAsync(new string[] {"return41"}) + .RunCommandLineApplicationAsync(new string[] { "return41" }) .GetAwaiter() .GetResult()); - Assert.Equal(new string[] {"return42"}, ex.NearestMatches); + Assert.Equal(new string[] { "return42" }, ex.NearestMatches); } [Fact]