Skip to content

Commit

Permalink
Merge pull request #33 from atc-net/feature/improve_validation
Browse files Browse the repository at this point in the history
Improve validation
  • Loading branch information
perkops authored Jun 13, 2024
2 parents 47dc10b + 2e11cf2 commit 944feae
Show file tree
Hide file tree
Showing 29 changed files with 230 additions and 118 deletions.
39 changes: 37 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ATC coding rules - https://github.com/atc-net/atc-coding-rules
# Version: 1.0.0
# Updated: 25-09-2023
# Version: 1.0.1
# Updated: 03-06-2024
# Location: Root
# Distribution: DotNet8
# Inspired by: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options
Expand Down Expand Up @@ -464,10 +464,45 @@ dotnet_diagnostic.MA0048.severity = error # https://github.com/atc-net
dotnet_diagnostic.CA1014.severity = none # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA1014.md
dotnet_diagnostic.CA1068.severity = error # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA1068.md
dotnet_diagnostic.CA1305.severity = error
dotnet_diagnostic.CA1510.severity = suggestion # Use ArgumentNullException throw helper
dotnet_diagnostic.CA1511.severity = suggestion # Use ArgumentException throw helper
dotnet_diagnostic.CA1512.severity = suggestion # Use ArgumentOutOfRangeException throw helper
dotnet_diagnostic.CA1513.severity = suggestion # Use ObjectDisposedException throw helper
dotnet_diagnostic.CA1514.severity = error # Avoid redundant length argument
dotnet_diagnostic.CA1707.severity = error # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA1707.md
dotnet_diagnostic.CA1812.severity = none
dotnet_diagnostic.CA1822.severity = suggestion
dotnet_diagnostic.CA1849.severity = error # Call async methods when in an async method
dotnet_diagnostic.CA1854.severity = suggestion # Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method
dotnet_diagnostic.CA1855.severity = suggestion # Prefer 'Clear' over 'Fill'
dotnet_diagnostic.CA1856.severity = error # Incorrect usage of ConstantExpected attribute
dotnet_diagnostic.CA1857.severity = suggestion # A constant is expected for the parameter
dotnet_diagnostic.CA1858.severity = suggestion # Use 'StartsWith' instead of 'IndexOf'
dotnet_diagnostic.CA1859.severity = suggestion # Use concrete types when possible for improved performance
dotnet_diagnostic.CA1860.severity = suggestion # Avoid using 'Enumerable.Any()' extension method
dotnet_diagnostic.CA1861.severity = suggestion # Avoid constant arrays as arguments
dotnet_diagnostic.CA1862.severity = error # Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
dotnet_diagnostic.CA1863.severity = suggestion # Use 'CompositeFormat'
dotnet_diagnostic.CA1864.severity = suggestion # Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1865.severity = suggestion # Use char overload
dotnet_diagnostic.CA1866.severity = suggestion # Use char overload
dotnet_diagnostic.CA1867.severity = suggestion # Use char overload
dotnet_diagnostic.CA1868.severity = suggestion # Unnecessary call to 'Contains(item)'
dotnet_diagnostic.CA1869.severity = suggestion # Cache and reuse 'JsonSerializerOptions' instances
dotnet_diagnostic.CA1870.severity = suggestion # Use a cached 'SearchValues' instance
dotnet_diagnostic.CA2007.severity = suggestion # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/CA2007.md
dotnet_diagnostic.CA2017.severity = error # Parameter count mismatch
dotnet_diagnostic.CA2018.severity = error # The count argument to Buffer.BlockCopy should specify the number of bytes to copy
dotnet_diagnostic.CA2019.severity = error # ThreadStatic fields should not use inline initialization
dotnet_diagnostic.CA2021.severity = error # Don't call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types
dotnet_diagnostic.CA2250.severity = suggestion # Use ThrowIfCancellationRequested
dotnet_diagnostic.CA2252.severity = suggestion # Opt-in to preview features should be used with caution
dotnet_diagnostic.CA2253.severity = error # Named placeholders should not be numeric values
dotnet_diagnostic.CA2254.severity = suggestion # Template should be a static expression
dotnet_diagnostic.CA2255.severity = suggestion # The ModuleInitializer attribute should not be used in libraries
dotnet_diagnostic.CA2259.severity = error # Ensure ThreadStatic is only used with static fields
dotnet_diagnostic.CA2260.severity = error # Implement generic math interfaces correctly
dotnet_diagnostic.CA2261.severity = error # Do not use ConfigureAwaitOptions.SuppressThrowing with Task<TResult>
dotnet_diagnostic.IDE0005.severity = warning # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/IDE0005.md
dotnet_diagnostic.IDE0058.severity = none # https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/MicrosoftCodeAnalysis/IDE0058.md

Expand Down
11 changes: 10 additions & 1 deletion Atc.Kepware.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{DAC1423F-D
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Kepware.Configuration.CLI", "src\Atc.Kepware.Configuration.CLI\Atc.Kepware.Configuration.CLI.csproj", "{268932F7-56E9-4B76-B488-1F398C71F7DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Kepware.Configuration.Contracts", "src\Atc.Kepware.Configuration.Contracts\Atc.Kepware.Configuration.Contracts.csproj", "{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Kepware.Configuration.Contracts", "src\Atc.Kepware.Configuration.Contracts\Atc.Kepware.Configuration.Contracts.csproj", "{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{34BF79A8-5519-4C9C-94E6-8DBEE2EB2D64}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Kepware.Configuration.Tests", "test\Atc.Kepware.Configuration.Tests\Atc.Kepware.Configuration.Tests.csproj", "{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -34,6 +38,10 @@ Global
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF}.Release|Any CPU.Build.0 = Release|Any CPU
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -42,6 +50,7 @@ Global
{4856D04B-2DA5-4398-90C2-CF13B8FA6191} = {69C84246-AA75-43E8-94B2-66FD555B18B0}
{268932F7-56E9-4B76-B488-1F398C71F7DE} = {69C84246-AA75-43E8-94B2-66FD555B18B0}
{E4E1D746-AFEF-47B6-9CBA-F08E8E1BF8AF} = {69C84246-AA75-43E8-94B2-66FD555B18B0}
{63FD5C0F-70DC-41DF-A539-7E47B4E9D156} = {34BF79A8-5519-4C9C-94E6-8DBEE2EB2D64}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {04120463-05C5-417B-8D7A-2D7D35B71A07}
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.146" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.156" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.321" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.23.1.88495" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.27.0.93347" PrivateAssets="All" />
</ItemGroup>

</Project>
32 changes: 20 additions & 12 deletions src/Atc.Kepware.Configuration.CLI/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# ATC coding rules - https://github.com/atc-net/atc-coding-rules
# Version: 1.0.9
# Updated: 01-02-2022
# Location: app-type=CLI
# Distribution: DotNet6
# Inspired by: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options
# Version: 1.0.0
# Updated: 11-04-2024
# Location: cli
# Distribution: Frameworks

##########################################
# Code Analyzers Rules
##########################################
[*.cs]
[*.{cs}]

dotnet_diagnostic.CA1031.severity = none # Not needed in CLI projects
dotnet_diagnostic.CA1303.severity = none # Not needed in CLI projects
dotnet_diagnostic.CA1819.severity = none # Not needed in CLI projects
dotnet_diagnostic.CA1848.severity = none # Not needed in CLI projects
dotnet_diagnostic.CA2000.severity = none # Not needed in CLI projects
dotnet_diagnostic.CA2254.severity = none # Not needed in CLI projects
dotnet_diagnostic.CA1031.severity = none # Do not catch general exception types
dotnet_diagnostic.CA1303.severity = none # Do not pass literals as localized parameters
dotnet_diagnostic.CA1819.severity = none # Properties should not return arrays
dotnet_diagnostic.CA1848.severity = none # Use the LoggerMessage delegates
dotnet_diagnostic.CA2000.severity = none # Dispose objects before losing scope
dotnet_diagnostic.CA2254.severity = none # Template should be a static expression

dotnet_diagnostic.MA0076.severity = none # Do not use implicit culture-sensitive ToString in interpolated strings

dotnet_diagnostic.S2629.severity = none # Don't use string interpolation in logging message templates.


##########################################
# Custom - Code Analyzers Rules
##########################################
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.465" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.465" />
<PackageReference Include="Atc" Version="2.0.478" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.478" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ public override ValidationResult Validate()
return validationResult;
}

return System.ComponentModel.DataAnnotations.KeyStringAttribute.TryIsValid(
ChannelName,
out var errorMessage)
var isValidName = IsValidName(ChannelName);
return isValidName.Successful
? ValidationResult.Success()
: ValidationResult.Error($"--{ChannelName}: {errorMessage}");
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(Name);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(IotAgentName);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,8 @@ public class IotItemGetCommandSettings : IotItemCommandBaseSettings
public override ValidationResult Validate()
{
var validationResult = base.Validate();
if (!validationResult.Successful)
{
return validationResult;
}

var isValidName = IsValidName(IotAgentName);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return validationResult.Successful
? ValidationResult.Success()
: validationResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ public override ValidationResult Validate()
}

var isValidName = IsValidName(IotAgentName);
if (!isValidName.Successful)
{
return isValidName;
}

return ValidationResult.Success();
return isValidName.Successful
? ValidationResult.Success()
: isValidName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static ValidationResult IsValidName(
string parameterValue)
=> System.ComponentModel.DataAnnotations.KeyStringAttribute.TryIsValid(
parameterValue,
KepwareConfigurationClient.NameKeyStringAttribute,
out var errorMessage)
? ValidationResult.Success()
: ValidationResult.Error($"--{parameterName}: {errorMessage}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.465" />
<PackageReference Include="Atc" Version="2.0.478" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.465" />
<PackageReference Include="Atc" Version="2.0.478" />
<PackageReference Include="Mapster" Version="7.4.0" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 944feae

Please sign in to comment.