Skip to content

Commit

Permalink
Solve 200 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Nov 10, 2024
1 parent a520886 commit 9fe24aa
Show file tree
Hide file tree
Showing 28 changed files with 249 additions and 242 deletions.
6 changes: 5 additions & 1 deletion src/SheepTools.Moq/MoqGenericLoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
#pragma warning disable RCS1036 // Remove unnecessary blank line

using Microsoft.Extensions.Logging;
using Moq;

namespace SheepTools.Moq;
Expand Down Expand Up @@ -142,3 +144,5 @@ public static void VerifyLog<T, TException>(this Mock<ILogger<T>> loggerMock, Lo

#endregion
}

#pragma warning restore RCS1036 // Remove unnecessary blank line
6 changes: 5 additions & 1 deletion src/SheepTools.Moq/MoqLoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
#pragma warning disable RCS1036 // Remove unnecessary blank line

using Microsoft.Extensions.Logging;
using Moq;

namespace SheepTools.Moq;
Expand Down Expand Up @@ -142,3 +144,5 @@ public static void VerifyLog<TException>(this Mock<ILogger> loggerMock, LogLevel

#endregion
}

#pragma warning restore RCS1036 // Remove unnecessary blank line
14 changes: 8 additions & 6 deletions src/SheepTools/Extensions/AssemblyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IEnumerable<Type> GetTypes<TAttribute>()
/// <returns></returns>
public static IEnumerable<Type> GetTypes<TAttribute>(this Assembly? assembly)
{
return (assembly?.GetTypes() ?? Array.Empty<Type>())
return (assembly?.GetTypes() ?? [])
.Where(type => type.IsDefined(typeof(TAttribute), true));
}

Expand All @@ -47,7 +47,7 @@ public static IEnumerable<Tuple<Type, TAttribute>> GetTypesAndAttributes<TAttrib
public static IEnumerable<Tuple<Type, TAttribute>> GetTypesAndAttributes<TAttribute>(this Assembly? assembly)
where TAttribute : Attribute
{
return (assembly?.GetTypes() ?? Array.Empty<Type>())
return (assembly?.GetTypes() ?? [])
.Where(type => type.IsDefined(typeof(TAttribute), true))
.SelectMany(type => type.GetCustomAttributes<TAttribute>()
.Select(attribute => Tuple.Create(type, attribute)));
Expand All @@ -61,10 +61,12 @@ public static IEnumerable<Tuple<Type, TAttribute>> GetTypesAndAttributes<TAttrib
/// <returns>string Collection</returns>
public static IEnumerable<string> GetAssemblies<TInterface>()
{
IList<string> validAssemblies = new List<string>();
IList<AssemblyName> assemblies = new List<AssemblyName>();
assemblies.AddRange(Assembly.GetCallingAssembly().GetReferencedAssemblies());
assemblies.Add(Assembly.GetCallingAssembly().GetName());
IList<string> validAssemblies = [];
IList<AssemblyName> assemblies =
[
.. Assembly.GetCallingAssembly().GetReferencedAssemblies(),
Assembly.GetCallingAssembly().GetName(),
];
foreach (var candidate in from assemblyName in assemblies
let candidate = Assembly.Load(assemblyName)
where candidate is not null
Expand Down
2 changes: 1 addition & 1 deletion src/SheepTools/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static bool IsAfter(this DateTime dateTime, DateTime other)
/// <returns></returns>
public static double MillisecondsFromEpoch(this DateTime dateTime)
{
return (dateTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds;
return (dateTime - DateTime.UnixEpoch).TotalMilliseconds;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SheepTools/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static HashSet<T> IntersectAll<T>(this IEnumerable<IEnumerable<T>> enumer
hashSet.IntersectWith(enumerable);
}
}
return hashSet ?? new HashSet<T>();
return hashSet ?? [];
}

public static HashSet<char> IntersectAll(this IEnumerable<string> enumerableOfStrings)
Expand Down
4 changes: 2 additions & 2 deletions src/SheepTools/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static bool IsWhiteSpace(this string? str)
/// <returns></returns>
public static bool HasWhiteSpaces(this string? str)
{
return str?.Contains(" ") == true;
return str?.Contains(' ') == true;
}

/// <summary>
Expand All @@ -43,7 +43,7 @@ public static bool HasWhiteSpaces(this string? str)
public static string? Truncate(this string? str, int maxLength)
{
return (str?.Length > maxLength)
? str.Substring(0, maxLength)
? str[..maxLength]
: str;
}

Expand Down
2 changes: 0 additions & 2 deletions src/SheepTools/Model/IntPointWithValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ public IntPointWithValue(T value, int x, int y) : base(x, y)
Value = value;
}

#pragma warning disable RCS1132 // Remove redundant overriding member - not redundant, https://github.com/JosefPihrt/Roslynator/issues/744
public override string ToString() => base.ToString();
#pragma warning restore RCS1132 // Remove redundant overriding member.
}
4 changes: 2 additions & 2 deletions src/SheepTools/Model/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public virtual Point RotateClockwise(Point pivot, double angle, bool isRadians =

public virtual Point CalculateClosestManhattanPoint(ICollection<Point> candidatePoints)
{
Dictionary<Point, double> pointDistanceDictionary = new();
Dictionary<Point, double> pointDistanceDictionary = [];

foreach (Point point in candidatePoints)
{
Expand All @@ -134,7 +134,7 @@ public virtual Point CalculateClosestManhattanPoint(ICollection<Point> candidate
/// <returns></returns>
public virtual Point? CalculateClosestManhattanPointNotTied(ICollection<Point> candidatePoints)
{
Dictionary<Point, double> pointDistanceDictionary = new();
Dictionary<Point, double> pointDistanceDictionary = [];

foreach (Point point in candidatePoints)
{
Expand Down
12 changes: 5 additions & 7 deletions src/SheepTools/Model/TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public record TreeNode<TKey> : GenericNode<TKey>
/// <inheritdoc/>
public TreeNode(TKey id) : base(id)
{
Children = new HashSet<TreeNode<TKey>>();
Children = [];
}

/// <summary>
Expand All @@ -42,7 +42,7 @@ public TreeNode(TKey id, TreeNode<TKey> child) : base(id)
throw new ArgumentException("A node cannot be its own child");
}

Children = new HashSet<TreeNode<TKey>> { child };
Children = [child];
}

/// <summary>
Expand Down Expand Up @@ -76,7 +76,7 @@ public TreeNode(TreeNode<TKey> parent, TKey id) : base(id)

Parent = parent;
ParentId = parent.Id;
Children = new HashSet<TreeNode<TKey>>();
Children = [];
}

/// <summary>
Expand Down Expand Up @@ -105,8 +105,8 @@ public virtual int DescendantsCount()
public virtual int RelationshipsCount()
{
return Children.Count
+ Children.Select(child => child.DescendantsCount()).Sum()
+ Children.Select(child => child.RelationshipsCount()).Sum();
+ Children.Sum(child => child.DescendantsCount())
+ Children.Sum(child => child.RelationshipsCount());
}

/// <summary>
Expand Down Expand Up @@ -181,9 +181,7 @@ void transverseBackwards(IEnumerable<TreeNode<TKey>> nodes, ref HashSet<TKey> id

public override bool Equals(TreeNode<TKey>? other) => base.Equals(other);

#pragma warning disable RCS1132 // Remove redundant overriding member. - https://github.com/JosefPihrt/Roslynator/issues/744
public override int GetHashCode() => base.GetHashCode();
#pragma warning restore RCS1132 // Remove redundant overriding member.

#endregion
}
14 changes: 1 addition & 13 deletions src/SheepTools/SheepToolsExceptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Runtime.Serialization;
namespace SheepTools;

namespace SheepTools;

[Serializable]
public class ValidationException : Exception
{
public ValidationException()
Expand All @@ -16,13 +13,8 @@ public ValidationException(string message) : base(message)
public ValidationException(string message, Exception innerException) : base(message, innerException)
{
}

protected ValidationException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}

[Serializable]
public class NotFoundException : Exception
{
public NotFoundException()
Expand All @@ -36,8 +28,4 @@ public NotFoundException(string message) : base(message)
public NotFoundException(string message, Exception innerException) : base(message, innerException)
{
}

protected NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
4 changes: 4 additions & 0 deletions tests/SheepTools.Moq.Test/MoqGenericLoggerExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void VerifyLogException()
}
}

#pragma warning disable CA2254 // Template should be a static expression

public class FixtureServiceGenericLogger
{
private readonly ILogger _logger;
Expand All @@ -113,3 +115,5 @@ public void LogException(LogLevel level, Exception e, string message)
_logger.Log(level, e, message);
}
}

#pragma warning restore CA2254 // Template should be a static expression
4 changes: 4 additions & 0 deletions tests/SheepTools.Moq.Test/MoqLoggerExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void VerifyLogException()
}
}

#pragma warning disable CA2254 // Template should be a static expression

internal class FixtureService
{
private readonly ILogger _logger;
Expand All @@ -113,3 +115,5 @@ public void LogException(LogLevel level, Exception e, string message)
_logger.Log(level, e, message);
}
}

#pragma warning restore CA2254 // Template should be a static expression
10 changes: 6 additions & 4 deletions tests/SheepTools.Test/BitArrayComparerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ public class BitArrayComparerTest
[Fact]
public void BitArrayComparer()
{
#pragma warning disable CA1861 // Avoid constant arrays as arguments
var set = new HashSet<BitArray>
{
new BitArray(new[] { true, false }),
new BitArray(new[] { false, true }),
new(new[] { true, false }),
new(new[] { false, true }),
};

var otherSet = new HashSet<BitArray>
{
new BitArray(new[] { true, false }),
new BitArray(new[] { false, true }),
new(new[] { true, false }),
new(new[] { false, true }),
};
#pragma warning restore CA1861 // Avoid constant arrays as arguments

// Without the comparer
Assert.NotEqual(set, otherSet);
Expand Down
16 changes: 8 additions & 8 deletions tests/SheepTools.Test/EnsureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class EnsureTest
[Fact]
public void Equal()
{
var date = new DateTime(1111, 1, 1);
DateTime otherDate(int n = 0) => new(date.Ticks + n);
var date = new DateTime(1111, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
DateTime otherDate(int n = 0) => new(date.Ticks + n, DateTimeKind.Unspecified);

Asssert.DoesNotThrow(() => Ensure.Equal(date, otherDate()));
Assert.Throws<ValidationException>(() => Ensure.Equal(date, otherDate(1)));
Expand All @@ -26,8 +26,8 @@ public void Equal()
[Fact]
public void EqualsTest()
{
var date = new DateTime(1111, 1, 1);
DateTime otherDate(int n = 0) => new(date.Ticks + n);
var date = new DateTime(1111, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
DateTime otherDate(int n = 0) => new(date.Ticks + n, DateTimeKind.Unspecified);

Asssert.DoesNotThrow(() => Ensure.Equals(date, otherDate()));
Assert.Throws<ValidationException>(() => Ensure.Equals(date, otherDate(1)));
Expand All @@ -39,8 +39,8 @@ public void EqualsTest()
[Fact]
public void NotEqual()
{
var date = new DateTime(2222, 1, 1);
DateTime otherDate(int n = 0) => new(date.Ticks + n);
var date = new DateTime(2222, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
DateTime otherDate(int n = 0) => new(date.Ticks + n, DateTimeKind.Unspecified);

Asssert.DoesNotThrow(() => Ensure.NotEqual(date, otherDate(-1)));
Assert.Throws<ValidationException>(() => Ensure.NotEqual(date, otherDate()));
Expand All @@ -52,8 +52,8 @@ public void NotEqual()
[Fact]
public void NotEquals()
{
var date = new DateTime(2222, 1, 1);
DateTime otherDate(int n = 0) => new(date.Ticks + n);
var date = new DateTime(2222, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
DateTime otherDate(int n = 0) => new(date.Ticks + n, DateTimeKind.Unspecified);

Asssert.DoesNotThrow(() => Ensure.NotEquals(date, otherDate(-1)));
Assert.Throws<ValidationException>(() => Ensure.NotEquals(date, otherDate()));
Expand Down
20 changes: 10 additions & 10 deletions tests/SheepTools.Test/Extensions/AttributeFixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ public FooAttribute(Type classInterface, ServiceLifetime serviceLifetime)
}
}

internal interface IScopedBar { }
internal interface IScopedBar;

[Foo(typeof(IScopedBar), ServiceLifetime.Scoped)]
internal class ScopedBar : IScopedBar { }
internal class ScopedBar : IScopedBar;

internal interface ITransientBar { }
internal interface ITransientBar;

[Foo(typeof(ITransientBar), ServiceLifetime.Transient)]
internal class TransientBar : ITransientBar { }
internal class TransientBar : ITransientBar;

internal interface ISingletonBar { }
internal interface ISingletonBar;

internal interface IYetAnotherInterface { }
internal interface IYetAnotherInterface;

[Foo(typeof(ISingletonBar), ServiceLifetime.Singleton)]
[Foo(typeof(IYetAnotherInterface), ServiceLifetime.Scoped)]
internal class SingletonBar : ISingletonBar, IYetAnotherInterface { }
internal class SingletonBar : ISingletonBar, IYetAnotherInterface;

internal interface IAssemblyExtensionTestInterface { }
internal interface IAssemblyExtensionTestInterfaceNotImplemented { }
internal class AssemblyExtensionTest : IAssemblyExtensionTestInterface { }
internal interface IAssemblyExtensionTestInterface;
internal interface IAssemblyExtensionTestInterfaceNotImplemented;
internal class AssemblyExtensionTest : IAssemblyExtensionTestInterface;
10 changes: 5 additions & 5 deletions tests/SheepTools.Test/Extensions/CollectionExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ public void AddRangeCollection()
existingCollection.AddRange(itemsToAdd);

// Assert
Assert.Equal(initialCollection.Concat(itemsToAdd).ToList(), existingCollection);
Assert.Equal([.. initialCollection, .. itemsToAdd], [.. existingCollection]);
}

[Fact]
public void AddRangeList()
{
// Arrange
ICollection<int> existingCollection = new List<int> { 1, 2, 3 };
ICollection<int> existingCollection = [1, 2, 3];
var initialCollection = existingCollection.ToList();
var itemsToAdd = new List<int> { 4, 5, 6 };

// Act
existingCollection.AddRange(itemsToAdd);

// Assert
Assert.Equal(initialCollection.Concat(itemsToAdd).ToList(), existingCollection);
Assert.Equal([.. initialCollection, .. itemsToAdd], existingCollection);
}

[Fact]
public void RemoveAllList()
{
// Arrange
ICollection<int> existingList = new List<int> { 1, 2, 3, 4, 5, 6 };
ICollection<int> existingList = [1, 2, 3, 4, 5, 6];
var initialList = existingList.ToList();
var evens = existingList.Where(n => n % 2 == 0).ToList();

Expand All @@ -62,6 +62,6 @@ public void RemoveAllCollection()
existingCollection.RemoveAll(n => n % 2 == 0);

// Assert
Assert.Equal(initialCollection.Except(evens).ToList(), existingCollection);
Assert.Equal(initialCollection.Except(evens).ToList(), [.. existingCollection]);
}
}
Loading

0 comments on commit 9fe24aa

Please sign in to comment.