Skip to content

Commit

Permalink
Fix new warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanSaeed committed Oct 3, 2023
1 parent 3880ef1 commit 1fe7f4a
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 101 deletions.
10 changes: 10 additions & 0 deletions Benchmarks/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
##########################################
# .NET
##########################################

[*.cs]
# IDE0005: Remove unnecessary usings/imports.
# Justification: There is a bug in the .NET SDK that requires GenerateDocumentationFile to be enabled for IDE0005 to work.
# https://github.com/dotnet/aspnetcore/issues/47912
dotnet_diagnostic.IDE0005.severity = none

##########################################
# StyleCop
##########################################
Expand Down
2 changes: 1 addition & 1 deletion Source/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########################################
# .NET Formatting Conventions
# .NET
##########################################

[*.cs]
Expand Down
10 changes: 5 additions & 5 deletions Source/Common/HashCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public static HashCode OfEach<T>(IEnumerable<T>? items) =>
/// <typeparam name="T">The type of the item.</typeparam>
/// <param name="item">The item.</param>
/// <returns>The new hash code.</returns>
public HashCode And<T>(T? item) => new(CombineHashCodes(this.value, GetHashCode(item)));
public readonly HashCode And<T>(T? item) => new(CombineHashCodes(this.value, GetHashCode(item)));

/// <summary>
/// Adds the hash code of the specified items in the collection.
/// </summary>
/// <typeparam name="T">The type of the items.</typeparam>
/// <param name="items">The collection.</param>
/// <returns>The new hash code.</returns>
public HashCode AndEach<T>(IEnumerable<T>? items)
public readonly HashCode AndEach<T>(IEnumerable<T>? items)
{
if (items is null)
{
Expand All @@ -98,10 +98,10 @@ public HashCode AndEach<T>(IEnumerable<T>? items)
}

/// <inheritdoc />
public bool Equals(HashCode other) => this.value.Equals(other.value);
public readonly bool Equals(HashCode other) => this.value.Equals(other.value);

/// <inheritdoc />
public override bool Equals(object? obj)
public override readonly bool Equals(object? obj)
{
if (obj is HashCode hashCode)
{
Expand All @@ -119,7 +119,7 @@ public override bool Equals(object? obj)
/// </returns>
/// <exception cref="NotSupportedException">Implicitly convert this struct to an <see cref="int" /> to get the hash code.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() =>
public override readonly int GetHashCode() =>
#pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
throw new NotSupportedException("Implicitly convert this struct to an int to get the hash code.");
#pragma warning restore CA1065 // Do not raise exceptions in unexpected locations
Expand Down
2 changes: 2 additions & 0 deletions Source/Common/Thing.Partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace Schema.NET;
/// <summary>
/// The most generic type of item.
/// </summary>
#pragma warning disable CA1040 // Avoid empty interfaces
public partial interface IThing
#pragma warning restore CA1040 // Avoid empty interfaces
{
}

Expand Down
45 changes: 25 additions & 20 deletions Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
##########################################
# .NET
##########################################

[*.cs]
# CA1014: Mark assemblies with CLSCompliant.
# Justification: Not needed here
# https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1014
dotnet_diagnostic.CA1014.severity = none

# CA1062: Validate arguments of public methods
# Justification: xUnit Theory method parameters don't need to be validated
# https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1062
dotnet_diagnostic.CA1062.severity = none

# CA1707: Identifiers should not contain underscores
# Justification: Test method names contain underscores
# https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1707
dotnet_diagnostic.CA1707.severity = none

# IDE0005: Remove unnecessary usings/imports.
# Justification: There is a bug in the .NET SDK that requires GenerateDocumentationFile to be enabled for IDE0005 to work.
# https://github.com/dotnet/aspnetcore/issues/47912
dotnet_diagnostic.IDE0005.severity = none

##########################################
# StyleCop
##########################################
Expand Down Expand Up @@ -28,23 +53,3 @@ dotnet_diagnostic.SA1602.severity = none
# Justification: Comments turned off
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md
dotnet_diagnostic.SA1633.severity = none

##########################################
# Custom
##########################################

[*.cs]
# CA1014: Mark assemblies with CLSCompliant.
# Justification: Not needed here
# https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1014
dotnet_diagnostic.CA1014.severity = none

# CA1062: Validate arguments of public methods
# Justification: xUnit Theory method parameters don't need to be validated
# https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1062
dotnet_diagnostic.CA1062.severity = none

# CA1707: Identifiers should not contain underscores
# Justification: Test method names contain underscores
# https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1707
dotnet_diagnostic.CA1707.severity = none
2 changes: 1 addition & 1 deletion Tests/Schema.NET.Test/OneOrManyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Constructor_NullList_ThrowsArgumentNullException() =>
public void Count_DefaultStructConstructor_ReturnsZero() => Assert.Empty(default(OneOrMany<int>));

[Fact]
public void Count_DefaultClassConstructor_ReturnsZero() => Assert.Empty(default(OneOrMany<string>));
public void Count_DefaultClassConstructor_ReturnsZero() => Assert.Empty(default(OneOrMany<string>)!);

[Fact]
public void Count_NullItem_ReturnsZero() => Assert.Empty(new OneOrMany<int?>((int?)null));
Expand Down
6 changes: 3 additions & 3 deletions Tests/Schema.NET.Test/Values2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Constructor_Value1Passed_OnlyValue1HasValue()
Assert.True(values.HasValue1);
Assert.Single(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1 }, values.Cast<object>().ToList());
}

Expand Down Expand Up @@ -88,7 +88,7 @@ public void ImplicitConversionOperator_Value1Passed_OnlyValue1HasValue()
Assert.True(values.HasValue1);
Assert.Single(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1 }, values.Cast<object>().ToList());
}

Expand All @@ -112,7 +112,7 @@ public void ImplicitConversionOperator_Value1ListPassed_OnlyValue1HasValue()
Assert.True(values.HasValue1);
Assert.Equal(2, values.Value1.Count);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1, 2 }, values.Cast<object>().ToList());
}

Expand Down
12 changes: 6 additions & 6 deletions Tests/Schema.NET.Test/Values3Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Constructor_Value1Passed_OnlyValue1HasValue()
Assert.True(values.HasValue1);
Assert.Single(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1 }, values.Cast<object>().ToList());
}

Expand All @@ -39,7 +39,7 @@ public void Constructor_Value3Passed_OnlyValue3HasValue()
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.True(values.HasValue3);
Assert.Single(values.Value3);
Assert.Equal(new List<object>() { DayOfWeek.Friday }, values.Cast<object>().ToList());
Expand Down Expand Up @@ -119,7 +119,7 @@ public void ImplicitConversionOperator_Value1Passed_OnlyValue1HasValue()
Assert.True(values.HasValue1);
Assert.Single(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1 }, values.Cast<object>().ToList());
}

Expand All @@ -143,7 +143,7 @@ public void ImplicitConversionOperator_Value3Passed_OnlyValue3HasValue()
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.True(values.HasValue3);
Assert.Single(values.Value3);
Assert.Equal(new List<object>() { DayOfWeek.Friday }, values.Cast<object>().ToList());
Expand All @@ -157,7 +157,7 @@ public void ImplicitConversionOperator_Value1CollectionPassed_OnlyValue1HasValue
Assert.True(values.HasValue1);
Assert.Equal(2, values.Value1.Count);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1, 2 }, values.Cast<object>().ToList());
}

Expand All @@ -181,7 +181,7 @@ public void ImplicitConversionOperator_Value3CollectionPassed_OnlyValue3HasValue
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.True(values.HasValue3);
Assert.Equal(2, values.Value3.Count);
Assert.Equal(new List<object>() { DayOfWeek.Friday, DayOfWeek.Monday }, values.Cast<object>().ToList());
Expand Down
18 changes: 9 additions & 9 deletions Tests/Schema.NET.Test/Values4Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Constructor_Value1Passed_OnlyValue1HasValue()
Assert.True(values.HasValue1);
Assert.Single(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1 }, values.Cast<object>().ToList());
}

Expand All @@ -39,7 +39,7 @@ public void Constructor_Value3Passed_OnlyValue3HasValue()
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.True(values.HasValue3);
Assert.Single(values.Value3);
Assert.Equal(new List<object>() { DayOfWeek.Friday }, values.Cast<object>().ToList());
Expand All @@ -53,7 +53,7 @@ public void Constructor_Value4Passed_OnlyValue4HasValue()
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.False(values.HasValue3);
Assert.Empty(values.Value3);
Assert.True(values.HasValue4);
Expand Down Expand Up @@ -149,7 +149,7 @@ public void ImplicitConversionOperator_Value1Passed_OnlyValue1HasValue()
Assert.True(values.HasValue1);
Assert.Single(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1 }, values.Cast<object>().ToList());
}

Expand All @@ -173,7 +173,7 @@ public void ImplicitConversionOperator_Value3Passed_OnlyValue3HasValue()
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.True(values.HasValue3);
Assert.Single(values.Value3);
Assert.Equal(new List<object>() { DayOfWeek.Friday }, values.Cast<object>().ToList());
Expand All @@ -187,7 +187,7 @@ public void ImplicitConversionOperator_Value4Passed_OnlyValue4HasValue()
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.False(values.HasValue3);
Assert.Empty(values.Value3);
Assert.True(values.HasValue4);
Expand All @@ -204,7 +204,7 @@ public void ImplicitConversionOperator_Value1CollectionPassed_OnlyValue1HasValue
Assert.True(values.HasValue1);
Assert.Equal(2, values.Value1.Count);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.Equal(new List<object>() { 1, 2 }, values.Cast<object>().ToList());
}

Expand All @@ -228,7 +228,7 @@ public void ImplicitConversionOperator_Value3CollectionPassed_OnlyValue3HasValue
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.True(values.HasValue3);
Assert.Equal(2, values.Value3.Count);
Assert.Equal(
Expand All @@ -244,7 +244,7 @@ public void ImplicitConversionOperator_Value4CollectionPassed_OnlyValue4HasValue
Assert.False(values.HasValue1);
Assert.Empty(values.Value1);
Assert.False(values.HasValue2);
Assert.Empty(values.Value2);
Assert.Empty(values.Value2!);
Assert.False(values.HasValue3);
Assert.Empty(values.Value3);
Assert.True(values.HasValue4);
Expand Down
Loading

0 comments on commit 1fe7f4a

Please sign in to comment.