Skip to content

Commit 724efa9

Browse files
Update analyzers and address new warnings
1 parent b3e126b commit 724efa9

29 files changed

+119
-97
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<GlobalPackageReference Include="Meziantou.Analyzer" Version="2.0.226" />
26+
<GlobalPackageReference Include="Meziantou.Analyzer" Version="2.0.250" />
2727
<GlobalPackageReference Include="PolySharp" Version="1.15.0" />
2828
</ItemGroup>
2929
</Project>

Generators/SuperLinq.Generator/ArgumentNames.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace SuperLinq.Generator;
33
/// <summary>
44
/// int->string translations of different types.
55
/// </summary>
6-
public record ArgumentNames(IReadOnlyList<string> Arity, IReadOnlyList<string> Ordinals, IReadOnlyList<string> Cardinals)
6+
public sealed record ArgumentNames(IReadOnlyList<string> Arity, IReadOnlyList<string> Ordinals, IReadOnlyList<string> Cardinals)
77
{
88
/// <summary>
99
/// int->string translations of different types.
@@ -44,6 +44,7 @@ public record ArgumentNames(IReadOnlyList<string> Arity, IReadOnlyList<string> O
4444
"Sixth",
4545
"Seventh",
4646
"Eighth",
47-
]);
47+
]
48+
);
4849
}
4950

Source/SuperLinq.Async/AssertCount.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace SuperLinq.Async;
1+
namespace SuperLinq.Async;
22

33
public static partial class AsyncSuperEnumerable
44
{
@@ -40,7 +40,13 @@ static async IAsyncEnumerable<TSource> Core(
4040
yield return item;
4141
}
4242

43-
ArgumentOutOfRangeException.ThrowIfNotEqual(c, count, $"{nameof(source)}.Count()");
43+
AssertSequenceCount(count, c);
4444
}
4545
}
46+
47+
private static void AssertSequenceCount(int expected, int actual)
48+
{
49+
if (expected != actual)
50+
ThrowHelper.ThrowInvalidOperationException($"Sequence contains too {(actual < expected ? "few" : "many")} elements when exactly '{expected:N0}' {(expected == 1 ? "was" : "were")} expected.");
51+
}
4652
}

Source/SuperLinq.Async/Catch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ static async IAsyncEnumerable<TSource> Core(
146146
// make it outside of the inner `while (true)`
147147
while (true)
148148
{
149-
ArgumentNullException.ThrowIfNull(source);
150149
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken);
151150

152151
while (true)

Source/SuperLinq.Async/Memoize.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void InitializeEnumerator(CancellationToken cancellationToken)
9898

9999
if (_exceptionIndex == -1)
100100
{
101-
ArgumentNullException.ThrowIfNull(_exception);
101+
Debug.Assert(_exception is not null);
102102
_exception.Throw();
103103
}
104104

Source/SuperLinq.Async/OnErrorResumeNext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ static async IAsyncEnumerable<TSource> Core(
6969
{
7070
await foreach (var source in sources.WithCancellation(cancellationToken).ConfigureAwait(false))
7171
{
72-
ArgumentNullException.ThrowIfNull(source);
7372
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken);
7473

7574
while (true)

Source/SuperLinq.Async/Timeout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static partial class AsyncSuperEnumerable
4040
public static IAsyncEnumerable<TSource> Timeout<TSource>(this IAsyncEnumerable<TSource> source, TimeSpan timeout)
4141
{
4242
ArgumentNullException.ThrowIfNull(source);
43-
ArgumentOutOfRangeException.ThrowIfNegative(timeout.Milliseconds);
43+
ArgumentOutOfRangeException.ThrowIfNegative(timeout.Milliseconds, nameof(timeout));
4444

4545
return Core(source, timeout);
4646

Source/SuperLinq/AssertCount.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ static IEnumerable<TSource> Core(IEnumerable<TSource> source, int count)
5454
yield return item;
5555
}
5656

57-
ArgumentOutOfRangeException.ThrowIfNotEqual(c, count, $"{nameof(source)}.Count()");
57+
AssertSequenceCount(count, c);
5858
}
5959
}
6060

61+
private static void AssertSequenceCount(int expected, int actual)
62+
{
63+
if (expected != actual)
64+
ThrowHelper.ThrowInvalidOperationException($"Sequence contains too {(actual < expected ? "few" : "many")} elements when exactly '{expected:N0}' {(expected == 1 ? "was" : "were")} expected.");
65+
}
66+
6167
private sealed class AssertCountCollectionIterator<T>(
6268
IEnumerable<T> source,
6369
int count
@@ -67,14 +73,14 @@ public override int Count
6773
{
6874
get
6975
{
70-
ArgumentOutOfRangeException.ThrowIfNotEqual(source.GetCollectionCount(), count, "source.Count()");
76+
AssertSequenceCount(count, source.GetCollectionCount());
7177
return count;
7278
}
7379
}
7480

7581
protected override IEnumerable<T> GetEnumerable()
7682
{
77-
ArgumentOutOfRangeException.ThrowIfNotEqual(source.GetCollectionCount(), count, "source.Count()");
83+
AssertSequenceCount(count, source.GetCollectionCount());
7884

7985
foreach (var item in source)
8086
yield return item;
@@ -99,15 +105,16 @@ public override int Count
99105
{
100106
get
101107
{
102-
ArgumentOutOfRangeException.ThrowIfNotEqual(source.Count, count, "source.Count()");
108+
AssertSequenceCount(count, source.Count);
103109
return count;
104110
}
105111
}
106112

107113
protected override IEnumerable<T> GetEnumerable()
108114
{
109-
var cnt = (uint)Count;
110-
for (var i = 0; i < cnt; i++)
115+
AssertSequenceCount(count, source.Count);
116+
117+
for (var i = 0; i < (uint)source.Count; i++)
111118
yield return source[i];
112119
}
113120

Source/SuperLinq/Case.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace SuperLinq;
1+
namespace SuperLinq;
22

33
public static partial class SuperEnumerable
44
{
@@ -101,7 +101,6 @@ static IEnumerable<TResult> Core(
101101
if (!sources.TryGetValue(selector(), out var source))
102102
source = defaultSource;
103103

104-
ArgumentNullException.ThrowIfNull(source);
105104
foreach (var el in source)
106105
yield return el;
107106
}

Source/SuperLinq/Catch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ static IEnumerable<TSource> Core(IEnumerable<IEnumerable<TSource>> sources)
172172
// make it outside of the inner `while (true)`
173173
while (true)
174174
{
175-
ArgumentNullException.ThrowIfNull(source);
176175
using var e = source.GetEnumerator();
177176

178177
while (true)

0 commit comments

Comments
 (0)