Skip to content

Commit

Permalink
Clean up files a bit (#1790)
Browse files Browse the repository at this point in the history
* Remove unnecessary using statements

* Simplify to new(...)

* Minor Fixes
  • Loading branch information
BenjaminMichaelis authored Jul 5, 2022
1 parent a1958c0 commit 5618b2d
Show file tree
Hide file tree
Showing 76 changed files with 101 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.CommandLine.Hosting;
using System.CommandLine.NamingConventionBinder;
using System.CommandLine.Parsing;
using ApprovalTests;
using ApprovalTests.Reporters;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Benchmarks.Helpers;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Parsing;
using System.Linq;
using BenchmarkDotNet.Attributes;

namespace System.CommandLine.Benchmarks.CommandLine
Expand Down Expand Up @@ -40,7 +39,7 @@ private void GenerateTestNestedCommands(Command parent, int depth, int countPerL
for (int i = 0; i < countPerLevel; i++)
{
string cmdName = $"{parent.Name}_{depth}.{i}";
Command cmd = new Command(cmdName);
Command cmd = new(cmdName);
parent.AddCommand(cmd);
GenerateTestNestedCommands(cmd, depth - 1, countPerLevel);
}
Expand Down Expand Up @@ -73,7 +72,7 @@ public void SetupParser()
}

[Benchmark]
public Parser ParserFromNestedCommands_Ctor() => new Parser(_rootCommand);
public Parser ParserFromNestedCommands_Ctor() => new(_rootCommand);

[Benchmark]
public ParseResult Parser_Parse() => _testParser.Parse(_testSymbolsAsString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BenchmarkDotNet.Attributes;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.Threading.Tasks;

Expand All @@ -25,10 +24,10 @@ public class Perf_Parser_Simple

private static RootCommand BuildCommand()
{
Option<bool> boolOption = new Option<bool>(new[] { "--bool", "-b" }, "Bool option");
Option<string> stringOption = new Option<string>(new[] { "--string", "-s" }, "String option");
Option<bool> boolOption = new(new[] { "--bool", "-b" }, "Bool option");
Option<string> stringOption = new(new[] { "--string", "-s" }, "String option");

RootCommand command = new RootCommand
RootCommand command = new()
{
boolOption,
stringOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine.Parsing;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace System.CommandLine.Benchmarks.DragonFruit
[InvocationCount(3000)]
public class Perf_CommandLine_EntryPoint
{
private readonly NullConsole _nullConsole = new NullConsole();
private readonly NullConsole _nullConsole = new();
private Assembly _testAssembly;
private string _testAssemblyFilePath;
private string _testAssemblyXmlDocsFilePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace System.CommandLine.Benchmarks.DragonFruit
[InvocationCount(3000)]
public class Perf_CommandLine_Help
{
private readonly NullConsole _nullConsole = new NullConsole();
private readonly NullConsole _nullConsole = new();
private Assembly _testAssembly;
private string _testAssemblyFilePath;
private string _testAssemblyXmlDocsFilePath;
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Benchmarks/Helpers/NullConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace System.CommandLine.Benchmarks.Helpers
{
class NullConsole : IConsole
{
readonly NullStreamWriter _nullWriter = new NullStreamWriter();
readonly NullStreamWriter _nullWriter = new();

public IStandardStreamWriter Out => _nullWriter;
public IStandardStreamWriter Error => _nullWriter;
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Immutable;
using System.IO;
using BenchmarkDotNet.Running;
using System.Linq;
using BenchmarkDotNet.Configs;
using System.Collections.Immutable;
using System.IO;

namespace System.CommandLine.Benchmarks
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Rendering;
using System.ComponentModel;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace System.CommandLine.DragonFruit.Tests
public class ConfigureFromMethodTests
{
private object[] _receivedValues;
private readonly TestConsole _testConsole = new TestConsole();
private readonly TestConsole _testConsole = new();

[Fact]
public async Task Generated_boolean_parameters_will_accept_zero_arguments()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.IO;
using FluentAssertions;
using System.Linq;
using Xunit;

namespace System.CommandLine.DragonFruit.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.CommandLine.Help;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.CommandLine.Parsing;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
Expand Down
6 changes: 0 additions & 6 deletions src/System.CommandLine.Hosting.Tests/HostingHandlerTest.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System.CommandLine;
using System.CommandLine.Binding;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.CommandLine.Parsing;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Xunit;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.CommandLine.Parsing;
using System.Linq;

using Microsoft.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Binding;
using System.CommandLine.Tests.Utility;
using System.IO;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Binding;
using System.CommandLine.Tests.Binding;
using System.CommandLine.Tests.Utility;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Binding;
using System.CommandLine.Tests.Binding;
using System.Linq;
using FluentAssertions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Binding;
using System.CommandLine.Tests.Binding;
using System.Linq;
using FluentAssertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine.Binding;
using System.Linq;
using System.Reflection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine.Binding;
using System.Linq;

namespace System.CommandLine.NamingConventionBinder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine.Binding;
using System.Reflection;

namespace System.CommandLine.NamingConventionBinder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine.Binding;

namespace System.CommandLine.NamingConventionBinder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
using System.CommandLine.Binding;
using System.Linq;
using System.Reflection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace System.CommandLine.Rendering.Tests
{
public class ConsoleRendererTests
{
private readonly TestTerminal _terminal = new TestTerminal();
private readonly TestTerminal _terminal = new();

private readonly ITestOutputHelper _output;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;
using FluentAssertions;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace System.CommandLine.Rendering.Tests
{
public class RenderingTestCase
{
private static readonly TextSpanFormatter _formatter = new TextSpanFormatter();
private static readonly TextSpanFormatter _formatter = new();

public RenderingTestCase(
string name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void Column_widths_are_aligned_to_the_longest_cell_in_file_mode()
.Be(lines[2].IndexOf("an option"));
}

private TextRendered Cell(string text, int left, int top) => new TextRendered(text, new Point(left, top));
private TextRendered Cell(string text, int left, int top) => new(text, new Point(left, top));
}

public class OptionsHelpView : TableView<Option>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.CommandLine.Parsing;
using System.CommandLine.Tests.Utility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace System.CommandLine.Rendering.Tests
{
public class TestTerminalTests : TerminalTests
{
protected TestTerminal _terminal = new TestTerminal();
protected TestTerminal _terminal = new();

protected override ITerminal GetTerminal() => _terminal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace System.CommandLine.Rendering.Tests
{
public class TextStyleRenderingTests
{
private readonly TextSpanFormatter _textSpanFormatter = new TextSpanFormatter();
private readonly TestTerminal _terminal = new TestTerminal();
private readonly TextSpanFormatter _textSpanFormatter = new();
private readonly TestTerminal _terminal = new();

[Fact]
public void BackgroundColorSpans_are_replaced_with_ANSI_codes_during_ANSI_rendering()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void BeforeRenderAction()

private class TestSynchronizationContext : SynchronizationContext
{
private readonly List<Action> _postActions = new List<Action>();
private readonly List<Action> _postActions = new();
public void InvokePostCallbacks()
{
while (_postActions.FirstOrDefault() is Action postAction)
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine.Rendering.Tests/WordWrappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace System.CommandLine.Rendering.Tests
{
public class WordWrappingTests
{
private readonly TestTerminal _terminal = new TestTerminal();
private readonly TestTerminal _terminal = new();

[Theory]
[MemberData(nameof(TestCases))]
Expand Down Expand Up @@ -185,6 +185,6 @@ IEnumerable<RenderingTestCase> TestCases()
}

private static TextRendered Line(int left, int top, string text) =>
new TextRendered(text, new Point(left, top));
new(text, new Point(left, top));
}
}
6 changes: 3 additions & 3 deletions src/System.CommandLine.Rendering/AnsiRenderingSpanVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void VisitCursorControlSpan(CursorControlSpan cursorControlSpan)
}

private static readonly Dictionary<string, AnsiControlCode> _foregroundColorControlCodeMappings =
new Dictionary<string, AnsiControlCode>
new()
{
[nameof(ForegroundColorSpan.Reset)] = Color.Foreground.Default,
[nameof(ForegroundColorSpan.Black)] = Color.Foreground.Black,
Expand All @@ -104,7 +104,7 @@ public override void VisitCursorControlSpan(CursorControlSpan cursorControlSpan)
};

private static readonly Dictionary<string, AnsiControlCode> _backgroundColorControlCodeMappings =
new Dictionary<string, AnsiControlCode>
new()
{
[nameof(BackgroundColorSpan.Reset)] = Color.Background.Default,
[nameof(BackgroundColorSpan.Black)] = Color.Background.Black,
Expand All @@ -126,7 +126,7 @@ public override void VisitCursorControlSpan(CursorControlSpan cursorControlSpan)
};

private static readonly Dictionary<string, AnsiControlCode> _styleControlCodeMappings =
new Dictionary<string, AnsiControlCode>
new()
{
[nameof(StyleSpan.AttributesOff)] = Ansi.Text.AttributesOff,
[nameof(StyleSpan.BlinkOff)] = Ansi.Text.BlinkOff,
Expand Down
Loading

0 comments on commit 5618b2d

Please sign in to comment.