Skip to content

Commit e67be50

Browse files
authored
cleanup: apply VS code cleanups (#423)
1 parent d4bedcf commit e67be50

File tree

63 files changed

+182
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+182
-165
lines changed

.editorconfig

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,34 @@ csharp_style_expression_bodied_indexers = true
4848
csharp_style_expression_bodied_accessors = true
4949
csharp_style_throw_expression = true
5050

51+
# Default severity for analyzer diagnostics with category 'Style' (escalated to build warnings)
52+
# dotnet_analyzer_diagnostic.category-Style.severity = suggestion
53+
54+
# Required naming sylte
55+
dotnet_diagnostic.IDE0006.severity = error
56+
57+
# suppress warning aboud unused methods
58+
dotnet_diagnostic.IDE0051.severity = none
59+
60+
# Missing required header
61+
dotnet_diagnostic.IDE0073.severity = error
62+
63+
# Remove unnecessary parenthesis
64+
dotnet_diagnostic.IDE0047.severity = warning
65+
66+
# Parenthesis added for clarity
67+
dotnet_diagnostic.IDE0048.severity = warning
68+
5169
# Naming styles
5270

5371
## Constants are PascalCase
5472
dotnet_naming_style.pascal_case.capitalization = pascal_case
5573

56-
dotnet_naming_symbols.constants.applicable_kinds = *
57-
dotnet_naming_symbols.constants.required_modifiers = const
74+
dotnet_naming_symbols.const.applicable_kinds = field, property
75+
dotnet_naming_symbols.const.applicable_accessibilities = *
76+
dotnet_naming_symbols.const.required_modifiers = const
5877

59-
dotnet_naming_rule.constants_should_be_pascale_case.symbols = constants
78+
dotnet_naming_rule.constants_should_be_pascale_case.symbols = const
6079
dotnet_naming_rule.constants_should_be_pascale_case.style = pascal_case
6180
dotnet_naming_rule.constants_should_be_pascale_case.severity = error
6281

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
3232
<WarningsNotAsErrors>$(WarningsNotAsErrors);1591</WarningsNotAsErrors>
3333
<LangVersion>9.0</LangVersion>
34+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
3435
<Nullable>annotations</Nullable>
3536
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)src\StrongName.snk</AssemblyOriginatorKeyFile>
3637
<SignAssembly>true</SignAssembly>

src/CommandLineUtils/Abstractions/ParseResult.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.ComponentModel;
65

76
namespace McMaster.Extensions.CommandLineUtils.Abstractions
87
{

src/CommandLineUtils/Abstractions/ValueParserProvider.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace McMaster.Extensions.CommandLineUtils.Abstractions
1414
/// </summary>
1515
public class ValueParserProvider
1616
{
17-
private readonly Dictionary<Type, IValueParser> _parsers = new Dictionary<Type, IValueParser>(10);
18-
private readonly TypeDescriptorValueParserFactory _defaultValueParserFactory = new TypeDescriptorValueParserFactory();
17+
private readonly Dictionary<Type, IValueParser> _parsers = new(10);
18+
private readonly TypeDescriptorValueParserFactory _defaultValueParserFactory = new();
1919

2020
internal ValueParserProvider()
2121
{
@@ -48,7 +48,7 @@ internal ValueParserProvider()
4848
/// </remarks>
4949
public CultureInfo ParseCulture { get; set; } = CultureInfo.CurrentCulture;
5050

51-
private static readonly MethodInfo s_GetParserGeneric
51+
private static readonly MethodInfo s_getParserGeneric
5252
= typeof(ValueParserProvider)
5353
.GetMethods(BindingFlags.Instance | BindingFlags.Public)
5454
.Single(m => m.Name == nameof(GetParser) && m.IsGenericMethod);
@@ -60,7 +60,7 @@ private static readonly MethodInfo s_GetParserGeneric
6060
/// <returns></returns>
6161
public IValueParser GetParser(Type type)
6262
{
63-
var method = s_GetParserGeneric.MakeGenericMethod(type);
63+
var method = s_getParserGeneric.MakeGenericMethod(type);
6464
return (IValueParser)method.Invoke(this, Util.EmptyArray<object>());
6565
}
6666

@@ -221,9 +221,11 @@ public GenericParserAdapter(IValueParser inner)
221221

222222
public Type TargetType => _inner.TargetType;
223223

224-
public T Parse(string? argName, string? value, CultureInfo culture) => (T)_inner.Parse(argName, value, culture)!;
224+
public T Parse(string? argName, string? value, CultureInfo culture)
225+
=> (T)_inner.Parse(argName, value, culture)!;
225226

226-
object? IValueParser.Parse(string? argName, string? value, CultureInfo culture) => _inner.Parse(argName, value, culture);
227+
object? IValueParser.Parse(string? argName, string? value, CultureInfo culture)
228+
=> _inner.Parse(argName, value, culture);
227229
}
228230
}
229231
}

src/CommandLineUtils/Attributes/AllowedValuesAttribute.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,12 @@ private static string GetDefaultError(string[] allowedValues)
5757
/// </summary>
5858
public bool IgnoreCase
5959
{
60-
get
61-
{
62-
return Comparer == StringComparison.CurrentCultureIgnoreCase
63-
|| Comparer == StringComparison.InvariantCultureIgnoreCase
64-
|| Comparer == StringComparison.OrdinalIgnoreCase;
65-
}
66-
set
67-
{
68-
Comparer = value
60+
get => Comparer is StringComparison.CurrentCultureIgnoreCase
61+
or StringComparison.InvariantCultureIgnoreCase
62+
or StringComparison.OrdinalIgnoreCase;
63+
set => Comparer = value
6964
? StringComparison.CurrentCultureIgnoreCase
7065
: StringComparison.CurrentCulture;
71-
}
7266
}
7367

7468
/// <inheritdoc />

src/CommandLineUtils/Attributes/CommandAttribute.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.ComponentModel;
76
using System.Globalization;
87
using System.Linq;
98

src/CommandLineUtils/Attributes/FilePathExistsAttributeBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal FilePathExistsAttributeBase(FilePathType filePathType)
2929
/// <inheritdoc />
3030
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
3131
{
32-
if (!(value is string path) || path.Length == 0 || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
32+
if (value is not string path || path.Length == 0 || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
3333
{
3434
return new ValidationResult(FormatErrorMessage(value as string));
3535
}

src/CommandLineUtils/Attributes/FilePathNotExistsAttributeBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal FilePathNotExistsAttributeBase(FilePathType filePathType)
2929
/// <inheritdoc />
3030
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
3131
{
32-
if (!(value is string path) || path.Length == 0 || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
32+
if (value is not string path || path.Length == 0 || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
3333
{
3434
return new ValidationResult(FormatErrorMessage(value as string));
3535
}
@@ -50,7 +50,7 @@ protected override ValidationResult IsValid(object value, ValidationContext vali
5050
return ValidationResult.Success;
5151
}
5252

53-
if ((_filePathType == FilePathType.Any) && (!File.Exists(path) && !Directory.Exists(path)))
53+
if ((_filePathType == FilePathType.Any) && !File.Exists(path) && !Directory.Exists(path))
5454
{
5555
return ValidationResult.Success;
5656
}

src/CommandLineUtils/Attributes/SubcommandAttribute.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.ComponentModel;
65

76
#pragma warning disable 618
87

@@ -15,7 +14,7 @@ namespace McMaster.Extensions.CommandLineUtils
1514
public sealed class SubcommandAttribute : Attribute
1615
{
1716
/// <summary>
18-
/// Initializes a new instance of <see cref="McMaster.Extensions.CommandLineUtils.SubcommandAttribute" />.
17+
/// Initializes a new instance of <see cref="SubcommandAttribute" />.
1918
/// </summary>
2019
/// <param name="subcommands">The subcommand types.</param>
2120
public SubcommandAttribute(params Type[] subcommands)

src/CommandLineUtils/CommandArgument.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Nate McMaster.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
34
// This file has been modified from the original form. See Notice.txt in the project root for more information.
45

56
using System;
@@ -16,7 +17,7 @@ namespace McMaster.Extensions.CommandLineUtils
1617
/// <seealso cref="CommandOption"/>
1718
public class CommandArgument
1819
{
19-
private protected List<string?> _values = new List<string?>();
20+
private protected List<string?> _values = new();
2021

2122
/// <summary>
2223
/// The name of the argument.

0 commit comments

Comments
 (0)