Skip to content

Commit

Permalink
style: run dotnet-format
Browse files Browse the repository at this point in the history
  • Loading branch information
natemcmaster committed Jun 20, 2019
1 parent 1ef731a commit 833e9c2
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void ApplyImpl<TModel>(ConventionContext context)

if (factory != null)
{
((CommandLineApplication<TModel>) context.Application).ModelFactory = factory;
((CommandLineApplication<TModel>)context.Application).ModelFactory = factory;
}
}

Expand Down Expand Up @@ -104,11 +104,11 @@ private void ApplyImpl<TModel>(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)));
Expand Down
4 changes: 2 additions & 2 deletions src/CommandLineUtils/Conventions/ExecuteMethodConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private async Task<int> 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<int> intResult)
{
return await intResult;
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/CommandLineUtils/Internal/AnsiConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void WriteLine(string message)
}

var escapeScan = 0;
for (; ;)
for (; ; )
{
var escapeIndex = message.IndexOf("\x1b[", escapeScan);
if (escapeIndex == -1)
Expand Down
8 changes: 5 additions & 3 deletions src/CommandLineUtils/Internal/CommandLineProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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; }
}

Expand Down
2 changes: 1 addition & 1 deletion src/CommandLineUtils/Internal/StringDistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/CommandLineUtils/Internal/ValueParsers/StockValueParsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ private static IValueParser<T> FloatingPointParser<T>(NumberParser<T> parser) =>
(argName, value) => InvalidValueException(argName, $"'{value}' is not a valid floating-point number."));

public static readonly IValueParser<double> Double = FloatingPointParser<double>(double.TryParse);
public static readonly IValueParser<float> Float = FloatingPointParser<float> (float.TryParse );
public static readonly IValueParser<float> Float = FloatingPointParser<float>(float.TryParse);

private static IValueParser<T> IntegerParser<T>(NumberParser<T> parser) =>
Create(parser, NumberStyles.Integer, (argName, value) => InvalidValueException(argName, $"'{value}' is not a valid number."));

public static readonly IValueParser<short> Int16 = IntegerParser<short>(short.TryParse);
public static readonly IValueParser<int> Int32 = IntegerParser<int> (int.TryParse );
public static readonly IValueParser<long> Int64 = IntegerParser<long> (long.TryParse );
public static readonly IValueParser<int> Int32 = IntegerParser<int>(int.TryParse);
public static readonly IValueParser<long> Int64 = IntegerParser<long>(long.TryParse);

private static IValueParser<T> NonNegativeIntegerParser<T>(NumberParser<T> parser) =>
Create(parser, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite,
(argName, value) => InvalidValueException(argName, $"'{value}' is not a valid, non-negative number."));

public static readonly IValueParser<byte> Byte = NonNegativeIntegerParser<byte> (byte.TryParse );
public static readonly IValueParser<byte> Byte = NonNegativeIntegerParser<byte>(byte.TryParse);
public static readonly IValueParser<ushort> UInt16 = NonNegativeIntegerParser<ushort>(ushort.TryParse);
public static readonly IValueParser<uint> UInt32 = NonNegativeIntegerParser<uint> (uint.TryParse );
public static readonly IValueParser<ulong> UInt64 = NonNegativeIntegerParser<ulong> (ulong.TryParse );
public static readonly IValueParser<uint> UInt32 = NonNegativeIntegerParser<uint>(uint.TryParse);
public static readonly IValueParser<ulong> UInt64 = NonNegativeIntegerParser<ulong>(ulong.TryParse);

private delegate bool DateTimeParser<T>(string s, IFormatProvider provider, DateTimeStyles styles, out T result);

Expand Down
2 changes: 1 addition & 1 deletion src/CommandLineUtils/Utilities/ArgumentEscaper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
9 changes: 5 additions & 4 deletions test/CommandLineUtils.Tests/CommandLineApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -106,10 +107,10 @@ public void ItThrowsIfAnotherSubcommandHasNameName()
c.AddName("s");
});

var ex = Assert.Throws<InvalidOperationException>(() => app.Command("sub1", _ => {}));
var ex = Assert.Throws<InvalidOperationException>(() => app.Command("sub1", _ => { }));
Assert.Equal(Strings.DuplicateSubcommandName("sub1"), ex.Message);

ex = Assert.Throws<InvalidOperationException>(() => app.Command("s", _ => {}));
ex = Assert.Throws<InvalidOperationException>(() => app.Command("s", _ => { }));
Assert.Equal(Strings.DuplicateSubcommandName("s"), ex.Message);
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public void ItInfersCommandName(string typeName, string commandName)

[Subcommand(typeof(AddCommand))]
private class Program
{}
{ }

private class AddCommand
{}
{ }

[Fact]
public void ItInfersSubcommandNameFromTypeName()
Expand Down
5 changes: 3 additions & 2 deletions test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void HelpOptionIsInherited()
{
var sb = new StringBuilder();
var outWriter = new StringWriter(sb);
var app = new CommandLineApplication<Parent> {Out = outWriter};
var app = new CommandLineApplication<Parent> { Out = outWriter };
app.Conventions.UseDefaultConventions();
app.Commands.ForEach(f => f.Out = outWriter);
app.Execute("lvl2", "--help");
Expand Down Expand Up @@ -204,7 +204,8 @@ public void NestedHelpOptionsChoosesHelpOptionNearestSelectedCommand(string[] ar
});
});

app.OnExecute(() => {
app.OnExecute(() =>
{
app.ShowHelp();
return 1;
});
Expand Down
4 changes: 2 additions & 2 deletions test/CommandLineUtils.Tests/StringDistanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion test/CommandLineUtils.Tests/SubcommandAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void OnExecute()

[Command("LEVEL1")]
private class Level1DuplicateCmd
{}
{ }

[Fact]
public void CommandNamesCannotDifferByCaseOnly()
Expand Down
4 changes: 2 additions & 2 deletions test/CommandLineUtils.Tests/ValidateMethodConventionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ private ValidationResult OnValidate(ValidationContext context, CommandLineContex
}

Assert.Equal(typeof(CommandLineApplication<SubcommandValidate>), context.ObjectInstance.GetType());
var subcommand = (CommandLineApplication<SubcommandValidate>) context.ObjectInstance;
var main = (CommandLineApplication<MainValidate>?) subcommand.Parent;
var subcommand = (CommandLineApplication<SubcommandValidate>)context.ObjectInstance;
var main = (CommandLineApplication<MainValidate>?)subcommand.Parent;

var middle = main?.Model.Middle;
if (middle.HasValue)
Expand Down
2 changes: 1 addition & 1 deletion test/CommandLineUtils.Tests/ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void RequiredOption_Attribute_Pass()
Assert.Equal(0, CommandLineApplication.Execute<RequiredOption>("-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)]
Expand Down
2 changes: 1 addition & 1 deletion test/CommandLineUtils.Tests/ValueParserProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<object[]> GetFloatingPointSymbolsData()
{
Expand Down
6 changes: 3 additions & 3 deletions test/Hosting.CommandLine.Tests/HostBuilderExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async void TestConventionInjection()
var convention = new Mock<IConvention>();
convention.Setup(c => c.Apply(It.IsAny<ConventionContext>()))
.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<IConsole>(new TestConsole(_output))
Expand All @@ -68,10 +68,10 @@ public void ItThrowsOnUnknownSubCommand()
var ex = Assert.Throws<UnrecognizedCommandParsingException>(
() => new HostBuilder()
.ConfigureServices(collection => collection.AddSingleton<IConsole>(new TestConsole(_output)))
.RunCommandLineApplicationAsync<ParentCommand>(new string[] {"return41"})
.RunCommandLineApplicationAsync<ParentCommand>(new string[] { "return41" })
.GetAwaiter()
.GetResult());
Assert.Equal(new string[] {"return42"}, ex.NearestMatches);
Assert.Equal(new string[] { "return42" }, ex.NearestMatches);
}

[Fact]
Expand Down

0 comments on commit 833e9c2

Please sign in to comment.