Skip to content

Commit

Permalink
Fix style errors: IDE0028, IDE0290, IDE0300 & IDE0301
Browse files Browse the repository at this point in the history
- bld\ExtensionsGenerator\Program.cs(394,15,394,35): error IDE0290: Use primary constructor
- bld\ExtensionsGenerator\Program.cs(386,81,386,86): error IDE0301: Collection initialization can be simplified
- bld\ExtensionsGenerator\Program.cs(362,15,362,22): error IDE0290: Use primary constructor
- MoreLinq\FullGroupJoin.cs(165,67,165,72): error IDE0301: Collection initialization can be simplified
- MoreLinq\Maxima.cs(243,37,243,42): error IDE0301: Collection initialization can be simplified
- MoreLinq\Maxima.cs(293,89,293,94): error IDE0301: Collection initialization can be simplified
- MoreLinq\Maxima.cs(323,28,323,31): error IDE0028: Collection initialization can be simplified
- MoreLinq\Maxima.cs(235,37,235,42): error IDE0301: Collection initialization can be simplified
- MoreLinq\Partition.cs(356,28,356,33): error IDE0301: Collection initialization can be simplified
- MoreLinq\Partition.cs(357,28,357,33): error IDE0301: Collection initialization can be simplified
- MoreLinq\Partition.cs(358,28,358,33): error IDE0301: Collection initialization can be simplified
- MoreLinq\TakeLast.cs(57,43,57,48): error IDE0301: Collection initialization can be simplified
- MoreLinq.Test\TestExtensions.cs(41,69,41,72): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\TestExtensions.cs(36,67,36,70): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\TestExtensions.cs(36,67,36,72): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\TestExtensions.cs(41,69,41,74): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\TestExtensions.cs(47,63,47,66): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\TestExtensions.cs(47,63,47,68): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\SampleData.cs(33,71,33,74): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\SampleData.cs(33,71,33,76): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\SampleData.cs(28,75,28,78): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\SampleData.cs(28,75,28,80): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\AggregateTest.cs(100,57,100,60): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\AggregateTest.cs(100,57,100,69): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\BacksertTest.cs(35,64,35,67): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\BacksertTest.cs(35,64,35,69): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\EndsWithTest.cs(55,45,55,48): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\EndsWithTest.cs(55,45,55,55): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\EndsWithTest.cs(61,45,61,48): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\EndsWithTest.cs(61,45,61,50): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\CountDownTest.cs(157,27,157,35): error IDE0290: Use primary constructor
- MoreLinq.Test\Enumerable.cs(148,28,148,33): error IDE0301: Collection initialization can be simplified
- MoreLinq.Test\InsertTest.cs(28,62,28,65): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\InsertTest.cs(28,62,28,67): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\Scope.cs(26,19,26,24): error IDE0290: Use primary constructor
- MoreLinq.Test\ReturnTest.cs(151,53,151,56): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\ReturnTest.cs(151,53,151,65): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\StartsWithTest.cs(55,47,55,50): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\StartsWithTest.cs(55,47,55,57): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\StartsWithTest.cs(61,47,61,50): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\StartsWithTest.cs(61,47,61,52): error IDE0300: Collection initialization can be simplified
- MoreLinq.Test\TraverseTest.cs(41,111,41,116): error IDE0301: Collection initialization can be simplified
- MoreLinq.Test\TraverseTest.cs(49,113,49,118): error IDE0301: Collection initialization can be simplified

See also:

- IDE0028: Use primary constructor
  https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0028

- IDE0290: Use primary constructor
  https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0290

- IDE0300: Collection initialization can be simplified
  https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0300

- IDE0301: Collection initialization can be simplified
  https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0301
  • Loading branch information
atifaziz committed Apr 1, 2024
1 parent 5bf0bbc commit 7ccea7a
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 61 deletions.
4 changes: 3 additions & 1 deletion MoreLinq.Test/AggregateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ from pair in pairs
into t
select new TestCaseData(t.Method, t.Args).SetName(t.Name).Returns(t.Expectation);

[TestCaseSource(nameof(AccumulatorsTestSource), new object[] { nameof(Accumulators), 10 })]
#pragma warning disable NUnit1018 // Parameter count does not match (false negative)
[TestCaseSource(nameof(AccumulatorsTestSource), [nameof(Accumulators), 10])]
#pragma warning restore NUnit1018 // Parameter count does not match
public object? Accumulators(MethodInfo method, object[] args) =>
method.Invoke(null, args);

Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/BacksertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void BacksertIsLazy()
[Test]
public void BacksertWithNegativeIndex()
{
Assert.That(() => Enumerable.Range(1, 10).Backsert(new[] { 97, 98, 99 }, -1),
Assert.That(() => Enumerable.Range(1, 10).Backsert([97, 98, 99], -1),
Throws.ArgumentOutOfRangeException("index"));
}

Expand Down
7 changes: 2 additions & 5 deletions MoreLinq.Test/CountDownTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,9 @@ public static IReadOnlyCollection<T>
/// for another.
/// </summary>

abstract class Sequence<T> : IEnumerable<T>
abstract class Sequence<T>(Func<IEnumerator<T>, IEnumerator<T>>? em) : IEnumerable<T>
{
readonly Func<IEnumerator<T>, IEnumerator<T>> em;

protected Sequence(Func<IEnumerator<T>, IEnumerator<T>>? em) =>
this.em = em ?? (e => e);
readonly Func<IEnumerator<T>, IEnumerator<T>> em = em ?? (e => e);

public IEnumerator<T> GetEnumerator() =>
this.em(Items.GetEnumerator());
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/EndsWithTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public bool EndsWithWithStrings(string first, string second)
[Test]
public void EndsWithReturnsTrueIfBothEmpty()
{
Assert.That(new int[0].EndsWith(new int[0]), Is.True);
Assert.That(new int[0].EndsWith([]), Is.True);
}

[Test]
public void EndsWithReturnsFalseIfOnlyFirstIsEmpty()
{
Assert.That(new int[0].EndsWith(new[] { 1, 2, 3 }), Is.False);
Assert.That(new int[0].EndsWith([1, 2, 3]), Is.False);
}

[TestCase("", "", ExpectedResult = true)]
Expand Down
2 changes: 2 additions & 0 deletions MoreLinq.Test/Enumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public static TSource ElementAt<TSource>(this IEnumerable<TSource> source, int i
LinqEnumerable.ElementAtOrDefault(source, index);

public static IEnumerable<TResult> Empty<TResult>() =>
#pragma warning disable IDE0301 // Simplify collection initialization
LinqEnumerable.Empty<TResult>();
#pragma warning restore IDE0301 // Simplify collection initialization

public static IEnumerable<TSource> Except<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second) =>
LinqEnumerable.Except(first, second);
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq.Test/InsertTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class InsertTest
[Test]
public void InsertWithNegativeIndex()
{
Assert.That(() => Enumerable.Range(1, 10).Insert(new[] { 97, 98, 99 }, -1),
Assert.That(() => Enumerable.Range(1, 10).Insert([97, 98, 99], -1),
Throws.ArgumentOutOfRangeException("index"));
}

Expand Down
4 changes: 3 additions & 1 deletion MoreLinq.Test/ReturnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ static IEnumerable<ITestCaseData> UnsupportedActions(string testName) =>
}
select new TestCaseData(ma.Action).SetName($"{testName}({ma.MethodName})");

[TestCaseSource(nameof(UnsupportedActions), new object[] { nameof(TestUnsupportedMethodShouldThrow) })]
#pragma warning disable NUnit1018 // Parameter count does not match (false negative)
[TestCaseSource(nameof(UnsupportedActions), [nameof(TestUnsupportedMethodShouldThrow)])]
#pragma warning restore NUnit1018 // Parameter count does not match
public void TestUnsupportedMethodShouldThrow(Action unsupportedAction)
{
Assert.That(() => unsupportedAction(), Throws.InstanceOf<NotSupportedException>());
Expand Down
12 changes: 4 additions & 8 deletions MoreLinq.Test/SampleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ namespace MoreLinq.Test
/// </summary>
static class SampleData
{
internal static readonly ReadOnlyCollection<string> Strings = new(new[]
{
"ax", "hello", "world", "aa", "ab", "ay", "az"
});
internal static readonly ReadOnlyCollection<string>
Strings = new(["ax", "hello", "world", "aa", "ab", "ay", "az"]);

internal static readonly ReadOnlyCollection<int> Values = new(new[]
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
});
internal static readonly ReadOnlyCollection<int>
Values = new([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

internal static readonly Func<int, int, int> Plus = (a, b) => a + b;
internal static readonly Func<int, int, int> Mul = (a, b) => a * b;
Expand Down
7 changes: 2 additions & 5 deletions MoreLinq.Test/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ namespace MoreLinq.Test
{
using System;

abstract class Scope<T> : IDisposable
abstract class Scope<T>(T current) : IDisposable
{
readonly T old;

protected Scope(T current) => this.old = current;
public virtual void Dispose() => Restore(this.old);
public virtual void Dispose() => Restore(current);
protected abstract void Restore(T old);
}
}
4 changes: 2 additions & 2 deletions MoreLinq.Test/StartsWithTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public bool StartsWithWithStrings(string first, string second)
[Test]
public void StartsWithReturnsTrueIfBothEmpty()
{
Assert.That(new int[0].StartsWith(new int[0]), Is.True);
Assert.That(new int[0].StartsWith([]), Is.True);
}

[Test]
public void StartsWithReturnsFalseIfOnlyFirstIsEmpty()
{
Assert.That(new int[0].StartsWith(new[] { 1, 2, 3 }), Is.False);
Assert.That(new int[0].StartsWith([1, 2, 3]), Is.False);
}

[TestCase("", "", ExpectedResult = true)]
Expand Down
17 changes: 7 additions & 10 deletions MoreLinq.Test/TestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,19 @@ public enum SourceKind

static class SourceKinds
{
public static readonly IEnumerable<SourceKind> Sequence = new[]
{
SourceKind.Sequence,
};
public static readonly IEnumerable<SourceKind> Sequence = [
SourceKind.Sequence
];

public static readonly IEnumerable<SourceKind> Collection = new[]
{
public static readonly IEnumerable<SourceKind> Collection = [
SourceKind.BreakingCollection,
SourceKind.BreakingReadOnlyCollection
};
];

public static readonly IEnumerable<SourceKind> List = new[]
{
public static readonly IEnumerable<SourceKind> List = [
SourceKind.BreakingList,
SourceKind.BreakingReadOnlyList
};
];
}

static partial class TestExtensions
Expand Down
4 changes: 2 additions & 2 deletions MoreLinq.Test/TraverseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public void TraverseBreadthFirstIsStreaming()
[Test]
public void TraverseDepthFirstPreservesChildrenOrder()
{
var res = MoreEnumerable.TraverseDepthFirst(0, i => i == 0 ? Enumerable.Range(1, 10) : Enumerable.Empty<int>());
var res = MoreEnumerable.TraverseDepthFirst(0, i => i == 0 ? Enumerable.Range(1, 10) : []);
res.AssertSequenceEqual(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}


[Test]
public void TraverseBreadthFirstPreservesChildrenOrder()
{
var res = MoreEnumerable.TraverseBreadthFirst(0, i => i == 0 ? Enumerable.Range(1, 10) : Enumerable.Empty<int>());
var res = MoreEnumerable.TraverseBreadthFirst(0, i => i == 0 ? Enumerable.Range(1, 10) : []);
res.AssertSequenceEqual(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}

Expand Down
3 changes: 1 addition & 2 deletions MoreLinq/FullGroupJoin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace MoreLinq
{
using System;
using System.Collections.Generic;
using System.Linq;

// Inspiration & credit: http://stackoverflow.com/a/13503860/6682
static partial class MoreEnumerable
Expand Down Expand Up @@ -162,7 +161,7 @@ IEnumerable<TResult> _(IEqualityComparer<TKey> comparer)
if (alookup.Contains(b.Key))
continue;
// We can skip the lookup because we are iterating over keys not found in the first sequence
yield return resultSelector(b.Key, Enumerable.Empty<TFirst>(), b);
yield return resultSelector(b.Key, [], b);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions MoreLinq/Maxima.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ IEnumerator IEnumerable.GetEnumerator() =>
public IEnumerable<T> Take(int count) =>
count switch
{
0 => Enumerable.Empty<T>(),
0 => [],
1 => ExtremaBy(source, Extremum.First, 1 , selector, comparer),
_ => ExtremaBy(source, Extrema.First , count, selector, comparer)
};

public IEnumerable<T> TakeLast(int count) =>
count switch
{
0 => Enumerable.Empty<T>(),
0 => [],
1 => ExtremaBy(source, Extremum.Last, 1 , selector, comparer),
_ => ExtremaBy(source, Extrema.Last , count, selector, comparer)
};
Expand Down Expand Up @@ -290,7 +290,7 @@ sealed class Extremum : Extrema<(bool, T), T>
public override void Restart(ref (bool, T) store) => store = default;

public override IEnumerable<T> GetEnumerable((bool, T) store) =>
store is (true, var item) ? Enumerable.Repeat(item, 1) : Enumerable.Empty<T>();
store is (true, var item) ? [item] : [];

public override void Add(ref (bool, T) store, int? limit, T item)
{
Expand Down Expand Up @@ -320,7 +320,7 @@ IEnumerable<TSource> Extrema()
using var e = source.GetEnumerator();

if (!e.MoveNext())
return new List<TSource>();
return [];

var store = extrema.New();
extrema.Add(ref store, limit, e.Current);
Expand Down
7 changes: 1 addition & 6 deletions MoreLinq/Partition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,7 @@ static TResult PartitionImpl<TKey, TElement, TResult>(IEnumerable<IGrouping<TKey

List<IGrouping<TKey, TElement>>? etc = null;

var groups = new[]
{
Enumerable.Empty<TElement>(),
Enumerable.Empty<TElement>(),
Enumerable.Empty<TElement>(),
};
var groups = new IEnumerable<TElement>[] { [], [], [] };

foreach (var e in source)
{
Expand Down
2 changes: 1 addition & 1 deletion MoreLinq/TakeLast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static IEnumerable<TSource> TakeLast<TSource>(this IEnumerable<TSource> s
{
if (source == null) throw new ArgumentNullException(nameof(source));

return count < 1 ? Enumerable.Empty<TSource>()
return count < 1 ? []
: source.CountDown(count, (e, cd) => (Element: e, Countdown: cd))
.SkipWhile(e => e.Countdown == null)
.Select(e => e.Element);
Expand Down
15 changes: 5 additions & 10 deletions bld/ExtensionsGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,9 @@ select Walk(te.Type))),
// - Each type parameter (recursively)
//

abstract class TypeKey : IComparable<TypeKey>
abstract class TypeKey(string name) : IComparable<TypeKey>
{
protected TypeKey(string name) => Name = name;

public string Name { get; }
public string Name { get; } = name;
public abstract ImmutableList<TypeKey> Parameters { get; }

public virtual int CompareTo(TypeKey? other)
Expand All @@ -383,18 +381,15 @@ protected static int Compare(IEnumerable<TypeKey> a, IEnumerable<TypeKey> b) =>
sealed class SimpleTypeKey(string name) : TypeKey(name)
{
public override string ToString() => Name;
public override ImmutableList<TypeKey> Parameters => ImmutableList<TypeKey>.Empty;
public override ImmutableList<TypeKey> Parameters => [];
}

abstract class ParameterizedTypeKey : TypeKey
abstract class ParameterizedTypeKey(string name, ImmutableList<TypeKey> parameters) : TypeKey(name)
{
protected ParameterizedTypeKey(string name, TypeKey parameter) :
this(name, [parameter]) { }

protected ParameterizedTypeKey(string name, ImmutableList<TypeKey> parameters) :
base(name) => Parameters = parameters;

public override ImmutableList<TypeKey> Parameters { get; }
public override ImmutableList<TypeKey> Parameters { get; } = parameters;
}

sealed class GenericTypeKey(string name, ImmutableList<TypeKey> parameters) :
Expand Down

0 comments on commit 7ccea7a

Please sign in to comment.