Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add analyzer and fix warnings #25

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,32 @@ dotnet_naming_style.pascal_case.capitalization = pascal_case

# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = none
#################################################### SYSLIB Style

# SYSLIB1006: Multiple logging methods are using event id x in class y
dotnet_diagnostic.SYSLIB1006.severity = error

#################################################### xUnit Style

# xUnit1048: Support for 'async void' unit tests is being removed from xUnit.net v3. To simplify upgrading, convert the test to 'async Task' instead.
dotnet_diagnostic.xUnit1048.severity = error

#################################################### Project Style

# MA0016: Prefer using collection abstraction instead of implementation
dotnet_diagnostic.MA0016.severity = none
dotnet_diagnostic.MA0016.severity = silent

# MA0017: Abstract types should not have public or internal constructors
dotnet_diagnostic.MA0017.severity = none

# MA0018: Do not declare static members on generic types (deprecated; use CA1000 instead)
dotnet_diagnostic.MA0018.severity = none

# MA0048: File name must match type name
dotnet_diagnostic.MA0048.severity = silent

# MA0051: Method is too long (80 lines; maximum allowed: 60)
dotnet_diagnostic.MA0051.severity = suggestion

# MA0154: Use langword in XML comment
dotnet_diagnostic.MA0154.severity = none
dotnet_diagnostic.MA0154.severity = none
47 changes: 45 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PropertyGroup>

<PropertyGroup Label="Env">
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<IsUnitTestProject>$(MSBuildProjectName.EndsWith('UnitTests'))</IsUnitTestProject>
<IsBenchmarkProject>$(MsBuildProjectName.Contains('Benchmark'))</IsBenchmarkProject>
</PropertyGroup>

Expand Down Expand Up @@ -48,7 +48,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' != 'true' AND '$(IsBenchmarkProject)' != 'true'">
<PropertyGroup Condition="'$(IsUnitTestProject)' != 'true' AND '$(IsBenchmarkProject)' != 'true'">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Expand All @@ -65,4 +65,47 @@
1e91649c
</PublicKey>
</PropertyGroup>

<ItemGroup Label="Analyzers">
<PackageReference Include="Roslynator.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Formatting.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Meziantou.Analyzer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(IsUnitTestProject)' == 'true'">
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="NSubstitute.Analyzers.CSharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.v3.extensibility.core"/>
<PackageReference Include="xunit.v3.assert" />
<PackageReference Include="xunit.runner.console">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentValidation" />
</ItemGroup>
</Project>
41 changes: 28 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,48 @@
</PackageVersion>
</ItemGroup>

<ItemGroup Label="Tests">
<PackageVersion Include="FluentValidation" Version="11.10.0" />
<ItemGroup Label="Benchmark">
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.console" Version="2.9.2">
</ItemGroup>

<ItemGroup Label="Tests">
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="9.1.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageVersion>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageVersion Include="xunit.v3" Version="1.0.1" />
<PackageVersion Include="xunit.v3.extensibility.core" Version="1.0.1" />
<PackageVersion Include="xunit.v3.assert" Version="1.0.1" />
<PackageVersion Include="xunit.runner.console" Version="2.9.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="coverlet.msbuild" Version="6.0.2">
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="NSubstitute" Version="5.0.0" />
<PackageVersion Include="FluentValidation" Version="11.10.0" />
</ItemGroup>

<ItemGroup Label="Analyzers">
<PackageVersion Include="Roslynator.Analyzers" Version="4.3.0">
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Roslynator.Formatting.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.5.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.179">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "9.0.100"
"version": "9.0.200"
}
}
Binary file removed public.snk
Binary file not shown.
7 changes: 0 additions & 7 deletions src/StrongOf.AspNetCore/StrongOf.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
<AssemblyName>$(GlobalAssemblyNamePrefix).AspNetCore</AssemblyName>
</PropertyGroup>

<ItemGroup Label="Analyzers">
<PackageReference Include="Meziantou.Analyzer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup Label="Package">
<PackageId>StrongOf.AspNetCore</PackageId>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
<AssemblyName>$(GlobalAssemblyNamePrefix).FluentValidation</AssemblyName>
</PropertyGroup>

<ItemGroup Label="Analyzers">
<PackageReference Include="Meziantou.Analyzer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup Label="Package">
<PackageId>StrongOf.FluentValidation</PackageId>
<IsPackable>true</IsPackable>
Expand Down
7 changes: 0 additions & 7 deletions src/StrongOf.Json/StrongOf.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
<AssemblyName>$(GlobalAssemblyNamePrefix).Json</AssemblyName>
</PropertyGroup>

<ItemGroup Label="Analyzers">
<PackageReference Include="Meziantou.Analyzer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup Label="Package">
<PackageId>StrongOf.Json</PackageId>
<IsPackable>true</IsPackable>
Expand Down
7 changes: 7 additions & 0 deletions src/StrongOf/StrongDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ public static bool TryParse(ReadOnlySpan<char> content, IFormatProvider? provide
/// <returns>A string representation of value of the current StrongDateTime object as specified by format.</returns>
public string ToString(string format, IFormatProvider? provider = null) => Value.ToString(format, provider);

/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <param name="provider">An IFormatProvider that supplies culture-specific formatting information.</param>
/// <returns>A string that represents the current object.</returns>
public string ToString(IFormatProvider? provider) => Value!.ToString(provider)!;

/// <summary>
/// Converts the value of the current StrongDateTime object to its equivalent string representation in ISO 8601 format.
/// </summary>
Expand Down
7 changes: 0 additions & 7 deletions src/StrongOf/StrongOf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
<AssemblyName>$(GlobalAssemblyNamePrefix)</AssemblyName>
</PropertyGroup>

<ItemGroup Label="Analyzers">
<PackageReference Include="Meziantou.Analyzer">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup Label="Package">
<PackageId>StrongOf</PackageId>
<IsPackable>true</IsPackable>
Expand Down
44 changes: 44 additions & 0 deletions src/StrongOf/StrongString.Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,48 @@ public abstract partial class StrongString<TStrong>
{
return (strong == other) is false;
}

/// <summary>
/// Determines whether the specified <see cref="StrongString{TStrong}"/> instance is less than another.
/// </summary>
/// <param name="left">The left-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <param name="right">The right-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> is less than <paramref name="right"/>; otherwise, <c>false</c>.
/// </returns>
public static bool operator <(StrongString<TStrong> left, StrongString<TStrong> right)
=> left.CompareTo(right) < 0;

/// <summary>
/// Determines whether the specified <see cref="StrongString{TStrong}"/> instance is greater than another.
/// </summary>
/// <param name="left">The left-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <param name="right">The right-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> is greater than <paramref name="right"/>; otherwise, <c>false</c>.
/// </returns>
public static bool operator >(StrongString<TStrong> left, StrongString<TStrong> right)
=> left.CompareTo(right) > 0;

/// <summary>
/// Determines whether the specified <see cref="StrongString{TStrong}"/> instance is less than or equal to another.
/// </summary>
/// <param name="left">The left-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <param name="right">The right-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> is less than or equal to <paramref name="right"/>; otherwise, <c>false</c>.
/// </returns>
public static bool operator <=(StrongString<TStrong> left, StrongString<TStrong> right)
=> left.CompareTo(right) <= 0;

/// <summary>
/// Determines whether the specified <see cref="StrongString{TStrong}"/> instance is greater than or equal to another.
/// </summary>
/// <param name="left">The left-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <param name="right">The right-hand <see cref="StrongString{TStrong}"/> instance.</param>
/// <returns>
/// <c>true</c> if <paramref name="left"/> is greater than or equal to <paramref name="right"/>; otherwise, <c>false</c>.
/// </returns>
public static bool operator >=(StrongString<TStrong> left, StrongString<TStrong> right)
=> left.CompareTo(right) >= 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.console">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\StrongOf.FluentValidation\StrongOf.FluentValidation.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void HasMaximumLength_ShouldNotFail_WhenValueIsNull()
[Fact]
public void IsRegexMatch_ShouldFail_WhenValueDoesNotMatchRegex()
{
_validator.RuleFor(x => x.Strong).IsRegexMatch(new Regex(@"^\d+$"));
_validator.RuleFor(x => x.Strong).IsRegexMatch(new Regex(@"^\d+$", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(1)));
TestModel model = new () { Strong = new("test") };
TestValidationResult<TestModel> result = _validator.TestValidate(model);
result.ShouldHaveValidationErrorFor(x => x.Strong);
Expand Down
14 changes: 0 additions & 14 deletions tests/StrongOf.Json.UnitTests/StrongOf.Json.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.console">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\StrongOf.Json\StrongOf.Json.csproj" />
</ItemGroup>
Expand Down
17 changes: 9 additions & 8 deletions tests/StrongOf.UnitTests/StrongDateTimeOffset_Operators_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using Xunit;

namespace StrongOf.Tests;
Expand Down Expand Up @@ -36,8 +37,8 @@ public void OperatorEquals_Null()
public void OperatorLessThan_ReturnsCorrectResult(string value, string other)
{
// Arrange
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other);
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value, CultureInfo.InvariantCulture));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other, CultureInfo.InvariantCulture);

// Assert
Assert.Equal((testStrongDateTimeOffset.Value < otherDateTimeOffset), (testStrongDateTimeOffset < otherDateTimeOffset));
Expand All @@ -50,8 +51,8 @@ public void OperatorLessThan_ReturnsCorrectResult(string value, string other)
public void OperatorGreaterThan_ReturnsCorrectResult(string value, string other)
{
// Arrange
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other);
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value, CultureInfo.InvariantCulture));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other, CultureInfo.InvariantCulture);

// Assert
Assert.Equal((testStrongDateTimeOffset.Value > otherDateTimeOffset), (testStrongDateTimeOffset > otherDateTimeOffset));
Expand All @@ -64,8 +65,8 @@ public void OperatorGreaterThan_ReturnsCorrectResult(string value, string other)
public void OperatorLessThanOrEqual_ReturnsCorrectResult(string value, string other)
{
// Arrange
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other);
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value, CultureInfo.InvariantCulture));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other, CultureInfo.InvariantCulture);

// Assert
Assert.Equal((testStrongDateTimeOffset.Value <= otherDateTimeOffset), (testStrongDateTimeOffset <= otherDateTimeOffset));
Expand All @@ -78,8 +79,8 @@ public void OperatorLessThanOrEqual_ReturnsCorrectResult(string value, string ot
public void OperatorGreaterThanOrEqual_ReturnsCorrectResult(string value, string other)
{
// Arrange
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other);
TestDateTimeOffsetOf testStrongDateTimeOffset = new(DateTimeOffset.Parse(value, CultureInfo.InvariantCulture));
DateTimeOffset otherDateTimeOffset = DateTimeOffset.Parse(other, CultureInfo.InvariantCulture);

// Assert
Assert.Equal((testStrongDateTimeOffset.Value >= otherDateTimeOffset), (testStrongDateTimeOffset >= otherDateTimeOffset));
Expand Down
2 changes: 1 addition & 1 deletion tests/StrongOf.UnitTests/StrongDateTime_As_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void TryParseIso8601_WithValidInput_ReturnsTrueAndNonNull()
{
// Arrange
ReadOnlySpan<char> content = "2022-01-02T00:00:00+00:00".AsSpan();
TestDateTimeOf? expected = TestDateTimeOf.From(DateTime.Parse("2022-01-02T00:00:00+00:00"));
TestDateTimeOf? expected = TestDateTimeOf.From(DateTime.Parse("2022-01-02T00:00:00+00:00", CultureInfo.InvariantCulture));

// Act
bool result = TestDateTimeOf.TryParseIso8601(content, out TestDateTimeOf? strong);
Expand Down
Loading
Loading