diff --git a/Funcky.Analyzers/Funcky.Analyzers.CodeFixes/OptionSomeWhereToFromBooleanRefactoring.cs b/Funcky.Analyzers/Funcky.Analyzers.CodeFixes/OptionSomeWhereToFromBooleanRefactoring.cs index b1b1cc9f..b742cc66 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.CodeFixes/OptionSomeWhereToFromBooleanRefactoring.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.CodeFixes/OptionSomeWhereToFromBooleanRefactoring.cs @@ -122,7 +122,7 @@ private static InvocationExpressionSyntax CreateFromBooleanInvocation( (ExpressionSyntax)generator.TypeExpressionForStaticMemberAccess(symbols.OptionType), GetFromBooleanName(returnInvocation)) .WithAdditionalAnnotations(Simplifier.Annotation), - ArgumentList(SeparatedList(new[] { Argument(condition), Argument(returnValue) }))) + ArgumentList(SeparatedList([Argument(condition), Argument(returnValue)]))) .WithLeadingTrivia(returnInvocation.GetLeadingTrivia()); private static SimpleNameSyntax GetFromBooleanName(InvocationExpressionSyntax returnInvocation) diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.ToNullable.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.ToNullable.cs index 6ee3c6ac..3b0b6a40 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.ToNullable.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.ToNullable.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1118 // StyleCop support for collection expressions is missing using Xunit; using static Funcky.Analyzers.AlternativeMonadAnalyzer; using VerifyCS = Funcky.Analyzers.Test.CSharpCodeFixVerifier; @@ -57,8 +58,7 @@ public static void M(Option optionOfReferenceType, Option optionOfV """; await VerifyCS.VerifyCodeFixAsync( inputCode + Environment.NewLine + OptionStubCode, - new[] - { + [ VerifyCS.Diagnostic(PreferToNullable).WithSpan(10, 9, 10, 71), VerifyCS.Diagnostic(PreferToNullable).WithSpan(11, 9, 11, 77), VerifyCS.Diagnostic(PreferToNullable).WithSpan(12, 9, 12, 77), @@ -68,7 +68,7 @@ await VerifyCS.VerifyCodeFixAsync( VerifyCS.Diagnostic(PreferToNullable).WithSpan(16, 9, 16, 70), VerifyCS.Diagnostic(PreferToNullable).WithSpan(17, 13, 17, 69), VerifyCS.Diagnostic(PreferToNullable).WithSpan(18, 13, 18, 69), - }, + ], fixedCode + Environment.NewLine + OptionStubCode); } @@ -109,10 +109,9 @@ public static void M(Option optionOfValueType) """; await VerifyCS.VerifyCodeFixAsync( inputCode + Environment.NewLine + OptionStubCode, - new[] - { + [ VerifyCS.Diagnostic(PreferToNullable).WithSpan(11, 14, 11, 63), - }, + ], fixedCode + Environment.NewLine + OptionStubCode); } } diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.cs index 26549fba..4cb25564 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/AlternativeMonadAnalyzerTest.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1118 // StyleCop support for collection expressions is missing using Xunit; using static Funcky.Analyzers.AlternativeMonadAnalyzer; using VerifyCS = Funcky.Analyzers.Test.CSharpCodeFixVerifier; @@ -83,8 +84,7 @@ public static void M3(Result resultOfInt) """; await VerifyCS.VerifyCodeFixAsync( inputCode + Environment.NewLine + OptionStubCode, - new[] - { + [ VerifyCS.Diagnostic(PreferGetOrElse).WithSpan(10, 9, 10, 50), VerifyCS.Diagnostic(PreferGetOrElse).WithSpan(11, 9, 11, 50), VerifyCS.Diagnostic(PreferGetOrElse).WithSpan(12, 9, 12, 52), @@ -94,7 +94,7 @@ await VerifyCS.VerifyCodeFixAsync( VerifyCS.Diagnostic(PreferGetOrElse).WithSpan(21, 9, 21, 51), VerifyCS.Diagnostic(PreferGetOrElse).WithSpan(26, 9, 26, 56), VerifyCS.Diagnostic(PreferGetOrElse).WithSpan(31, 9, 31, 54), - }, + ], fixedCode + Environment.NewLine + OptionStubCode); } @@ -177,8 +177,7 @@ public static void M3(Result resultOfInt, Result fallback) """; await VerifyCS.VerifyCodeFixAsync( inputCode + Environment.NewLine + OptionStubCode, - new[] - { + [ VerifyCS.Diagnostic(PreferOrElse).WithSpan(10, 9, 10, 71), VerifyCS.Diagnostic(PreferOrElse).WithSpan(11, 9, 11, 69), VerifyCS.Diagnostic(PreferOrElse).WithSpan(12, 9, 12, 56), @@ -189,7 +188,7 @@ await VerifyCS.VerifyCodeFixAsync( VerifyCS.Diagnostic(PreferOrElse).WithSpan(22, 9, 22, 58), VerifyCS.Diagnostic(PreferOrElse).WithSpan(27, 9, 27, 77), VerifyCS.Diagnostic(PreferOrElse).WithSpan(32, 9, 32, 67), - }, + ], fixedCode + Environment.NewLine + OptionStubCode); } @@ -262,14 +261,13 @@ public static void M3(Result resultOfInt) """; await VerifyCS.VerifyCodeFixAsync( inputCode + Environment.NewLine + OptionStubCode, - new[] - { + [ VerifyCS.Diagnostic(PreferSelectMany).WithSpan(10, 9, 10, 84), VerifyCS.Diagnostic(PreferSelectMany).WithSpan(11, 9, 11, 84), VerifyCS.Diagnostic(PreferSelectMany).WithSpan(17, 9, 17, 63), VerifyCS.Diagnostic(PreferSelectMany).WithSpan(22, 9, 22, 100), VerifyCS.Diagnostic(PreferSelectMany).WithSpan(27, 9, 27, 83), - }, + ], fixedCode + Environment.NewLine + OptionStubCode); } diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatNeverTest.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatNeverTest.cs index 9200c4f3..844e1bf5 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatNeverTest.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatNeverTest.cs @@ -1,3 +1,4 @@ +using Microsoft.CodeAnalysis.Testing; using Xunit; using VerifyCS = Funcky.Analyzers.Test.CSharpCodeFixVerifier; @@ -60,12 +61,12 @@ public async Task UsingEnumerableRepeatNeverWorksWithDifferentTypes() [Fact] public async Task CodeFixWorksWithDifferentUsingStyles() { - var expectedDiagnostics = new[] - { + DiagnosticResult[] expectedDiagnostics = + [ VerifyCS.Diagnostic(EnumerableRepeatNeverAnalyzer.DiagnosticId).WithSpan(9, 17, 9, 35).WithArguments("\"value\"", "string"), VerifyCS.Diagnostic(EnumerableRepeatNeverAnalyzer.DiagnosticId).WithSpan(20, 17, 20, 58).WithArguments("\"value\"", "string"), VerifyCS.Diagnostic(EnumerableRepeatNeverAnalyzer.DiagnosticId).WithSpan(33, 17, 33, 39).WithArguments("\"value\"", "string"), - }; + ]; await VerifyWithSourceExample.VerifyDiagnosticAndCodeFix(expectedDiagnostics, "RepeatNeverQualification"); } diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatOnceTest.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatOnceTest.cs index ada5b80f..fb17183d 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatOnceTest.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/EnumerableRepeatOnceTest.cs @@ -1,3 +1,4 @@ +using Microsoft.CodeAnalysis.Testing; using Xunit; using VerifyCS = Funcky.Analyzers.Test.CSharpCodeFixVerifier; @@ -56,12 +57,12 @@ public async Task UsingEnumerableRepeatOnceViaConstantShowsTheSequenceReturnDiag [Fact] public async Task CodeFixWorksWithDifferentUsingStyles() { - var expectedDiagnostics = new[] - { + DiagnosticResult[] expectedDiagnostics = + [ VerifyCS.Diagnostic(EnumerableRepeatOnceAnalyzer.DiagnosticId).WithSpan(17, 17, 17, 53).WithArguments("10"), VerifyCS.Diagnostic(EnumerableRepeatOnceAnalyzer.DiagnosticId).WithSpan(28, 17, 28, 53).WithArguments("10"), VerifyCS.Diagnostic(EnumerableRepeatOnceAnalyzer.DiagnosticId).WithSpan(41, 17, 41, 53).WithArguments("10"), - }; + ]; await VerifyWithSourceExample.VerifyDiagnosticAndCodeFix(expectedDiagnostics, "RepeatOnceQualification"); } diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/OptionNoneInvocationCodeFixTest.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/OptionNoneInvocationCodeFixTest.cs index d7eccce4..b6741f2a 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/OptionNoneInvocationCodeFixTest.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/OptionNoneInvocationCodeFixTest.cs @@ -1,3 +1,5 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing +#pragma warning disable SA1118 // StyleCop support for collection expressions is missing using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; @@ -88,11 +90,10 @@ public static void M() await VerifyCS.VerifyCodeFixAsync( inputCode + Environment.NewLine + OptionCode, - new[] - { + [ DiagnosticResult.CompilerError("CS1955").WithSpan(7, 47, 7, 51).WithArguments("Funcky.Monads.Option.None"), DiagnosticResult.CompilerError("CS1955").WithSpan(8, 47, 8, 51).WithArguments("Funcky.Monads.Option.None"), - }, + ], fixedCode + Environment.NewLine + OptionCode); } @@ -129,7 +130,7 @@ public static void M() [SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1001:Missing diagnostic analyzer attribute")] internal sealed class NullDiagnosticAnalyzer : DiagnosticAnalyzer { - public override ImmutableArray SupportedDiagnostics => ImmutableArray.Empty; + public override ImmutableArray SupportedDiagnostics => []; [SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1025:Configure generated code analysis")] [SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1026:Enable concurrent execution")] diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.Setup.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.Setup.cs index 831fa44c..664a2bee 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.Setup.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.Setup.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using Funcky.Extensions; using VerifyCS = Funcky.Analyzers.Test.CSharpCodeRefactoringVerifier; @@ -45,7 +46,7 @@ public static class Option } """; - private static readonly IEnumerable DefaultUsings = Sequence.Return("using Funcky.Monads;"); + private static readonly IEnumerable DefaultUsings = ["using Funcky.Monads;"]; private static async Task VerifyRefactoring(string source, string fixedSource, string supportSource, IEnumerable? usings = null) { diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.cs index 25669a1e..ce48750c 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/OptionSomeWhereToFromBooleanRefactoringTest.cs @@ -1,3 +1,5 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing +#pragma warning disable SA1118 // StyleCop support for collection expressions is missing using Xunit; namespace Funcky.Analyzers.Test; @@ -42,7 +44,7 @@ await VerifyRefactoring( "Option> x = Option.Return>(\"foo\").[||]Where(_ => true);", "Option> x = Option.FromBoolean>(true, \"foo\");", OptionCode, - usings: Sequence.Return("using Funcky.Monads;", "using System.Collections.Generic;")); + usings: ["using Funcky.Monads;", "using System.Collections.Generic;"]); } [Fact] @@ -88,7 +90,7 @@ await VerifyRefactoring( "var x = Return(10).[||]Where(_ => true);", "var x = FromBoolean(true, 10);", OptionCode, - usings: Sequence.Return("using static Funcky.Monads.Option;")); + usings: ["using static Funcky.Monads.Option;"]); } [Fact] @@ -98,7 +100,7 @@ await VerifyRefactoring( "var x = Funcky.Monads.Option.Return(10).[||]Where(_ => true);", "var x = Funcky.Monads.Option.FromBoolean(true, 10);", OptionCode, - usings: Enumerable.Empty()); + usings: []); } [Fact] diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/UseWithArgumentNamesTest.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/UseWithArgumentNamesTest.cs index 60371b1c..b91e3880 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/UseWithArgumentNamesTest.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/UseWithArgumentNamesTest.cs @@ -1,3 +1,4 @@ +using Microsoft.CodeAnalysis.Testing; using Xunit; using VerifyCS = Funcky.Analyzers.Test.CSharpCodeFixVerifier; @@ -110,8 +111,8 @@ private void MethodWithKeywordAsArgument(int @int) { } } """; - var expectedDiagnostics = new[] - { + DiagnosticResult[] expectedDiagnostics = + [ VerifyCS.Diagnostic().WithSpan(7, 23, 7, 25).WithArguments("y"), VerifyCS.Diagnostic().WithSpan(8, 16, 8, 18).WithArguments("x"), VerifyCS.Diagnostic().WithSpan(8, 20, 8, 22).WithArguments("y"), @@ -120,7 +121,7 @@ private void MethodWithKeywordAsArgument(int @int) { } VerifyCS.Diagnostic().WithSpan(12, 13, 12, 15).WithArguments("x"), VerifyCS.Diagnostic().WithSpan(13, 13, 13, 15).WithArguments("y"), VerifyCS.Diagnostic().WithSpan(14, 37, 14, 39).WithArguments("int"), - }; + ]; await VerifyCS.VerifyAnalyzerAsync(inputCode + AttributeSource, expectedDiagnostics); await VerifyCS.VerifyCodeFixAsync(inputCode + AttributeSource, expectedDiagnostics, fixedCode + AttributeSource); diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs index f753692d..6a4f1fff 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeFixVerifier`2.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Testing; @@ -41,7 +42,7 @@ public static async Task VerifyCodeFixAsync(string source, string fixedSource) /// public static async Task VerifyCodeFixAsync(string source, DiagnosticResult expected, string fixedSource) - => await VerifyCodeFixAsync(source, new[] { expected }, fixedSource); + => await VerifyCodeFixAsync(source, [expected], fixedSource); /// public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource) diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1.cs index 4204f4d3..2b31a05b 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpCodeRefactoringVerifier`1.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.Testing; @@ -15,7 +16,7 @@ public static async Task VerifyRefactoringAsync(string source, string fixedSourc /// public static async Task VerifyRefactoringAsync(string source, DiagnosticResult expected, string fixedSource) { - await VerifyRefactoringAsync(source, new[] { expected }, fixedSource); + await VerifyRefactoringAsync(source, [expected], fixedSource); } /// diff --git a/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpVerifierHelper.cs b/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpVerifierHelper.cs index ebc621dc..db5be4fe 100644 --- a/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpVerifierHelper.cs +++ b/Funcky.Analyzers/Funcky.Analyzers.Test/Verifiers/CSharpVerifierHelper.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -17,7 +18,7 @@ internal static class CSharpVerifierHelper private static ImmutableDictionary GetNullableWarningsFromCompiler() { - string[] args = { "/warnaserror:nullable" }; + string[] args = ["/warnaserror:nullable"]; var commandLineArguments = CSharpCommandLineParser.Default.Parse(args, baseDirectory: Environment.CurrentDirectory, sdkDirectory: Environment.CurrentDirectory); var nullableWarnings = commandLineArguments.CompilationOptions.SpecificDiagnosticOptions; diff --git a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionEitherTest.cs b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionEitherTest.cs index 6bfc8d72..35996331 100644 --- a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionEitherTest.cs +++ b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionEitherTest.cs @@ -19,8 +19,8 @@ public async Task PartitionsItemsIntoLeftAndRight() Either.Right("b"), Either.Left(20)); var (left, right) = await input.PartitionAsync(); - Assert.Equal(new[] { 10, 20 }, left); - Assert.Equal(new[] { "a", "b" }, right); + Assert.Equal([10, 20], left); + Assert.Equal(["a", "b"], right); } [Fact] @@ -32,5 +32,6 @@ public async Task PartitionsItemsIntoLeftAndRightWithSelector() Assert.Equal(input.Where(IsEven), right); } - private static bool IsEven(int n) => n % 2 == 0; + private static bool IsEven(int n) + => n % 2 is 0; } diff --git a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionTest.cs b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionTest.cs index f9e477df..8cd5d234 100644 --- a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionTest.cs +++ b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/PartitionTest.cs @@ -14,31 +14,31 @@ public async Task ReturnsTwoEmptyListsWhenSourceIsEmpty() public async Task PartitionsItemsIntoTruesAndFalses() { var (evens, odds) = await AsyncEnumerable.Range(0, 6).PartitionAsync(IsEven); - Assert.Equal(new[] { 0, 2, 4 }, evens); - Assert.Equal(new[] { 1, 3, 5 }, odds); + Assert.Equal([0, 2, 4], evens); + Assert.Equal([1, 3, 5], odds); } [Fact] public async Task PartitionsItemsIntoTruesAndFalsesWithAsyncPredicate() { var (evens, odds) = await AsyncEnumerable.Range(0, 6).PartitionAwaitAsync(x => ValueTask.FromResult(IsEven(x))); - Assert.Equal(new[] { 0, 2, 4 }, evens); - Assert.Equal(new[] { 1, 3, 5 }, odds); + Assert.Equal([0, 2, 4], evens); + Assert.Equal([1, 3, 5], odds); } [Fact] public async Task PartitionsItemsIntoTruesAndFalsesWithAsyncCancellablePredicate() { var (evens, odds) = await AsyncEnumerable.Range(0, 6).PartitionAwaitWithCancellationAsync((x, _) => ValueTask.FromResult(IsEven(x))); - Assert.Equal(new[] { 0, 2, 4 }, evens); - Assert.Equal(new[] { 1, 3, 5 }, odds); + Assert.Equal([0, 2, 4], evens); + Assert.Equal([1, 3, 5], odds); } [Fact] public async Task RightItemsAreEmptyWhenPredicateMatchesAllItems() { var (left, right) = await AsyncEnumerable.Range(0, 6).PartitionAsync(True); - Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, left); + Assert.Equal([0, 1, 2, 3, 4, 5], left); Assert.Empty(right); } @@ -47,7 +47,7 @@ public async Task LeftItemsAreEmptyWhenPredicateMatchesNoItems() { var (left, right) = await AsyncEnumerable.Range(0, 6).PartitionAsync(False); Assert.Empty(left); - Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, right); + Assert.Equal([0, 1, 2, 3, 4, 5], right); } private static bool IsEven(int n) => n % 2 == 0; diff --git a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TakeEveryTest.cs b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TakeEveryTest.cs index 3be063f4..65610f3e 100644 --- a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TakeEveryTest.cs +++ b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TakeEveryTest.cs @@ -41,6 +41,6 @@ public async Task TakeEveryWithLessThanIntervalElementsReturnsOnlyFirstElement() [Fact] public async Task TakeEveryWithASourceWith5ElementsAndInterval4Returns2Elements() { - Assert.Equal(new[] { 1, 5 }, await OneToFive.TakeEvery(4).ToListAsync()); + Assert.Equal([1, 5], await OneToFive.TakeEvery(4).ToListAsync()); } } diff --git a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TransposeTest.cs b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TransposeTest.cs index a2105f04..0b26b1d8 100644 --- a/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TransposeTest.cs +++ b/Funcky.Async.Test/Extensions/AsyncEnumerableExtensions/TransposeTest.cs @@ -37,10 +37,10 @@ public async Task TransposingAMatrixResultsInATransposedMatrixAsync() await AsyncAssert.Collection( transposed, - row => { Assert.Equal(new[] { 1, 5, 9 }, row); }, - row => { Assert.Equal(new[] { 2, 6, 10 }, row); }, - row => { Assert.Equal(new[] { 3, 7, 11 }, row); }, - row => { Assert.Equal(new[] { 4, 8, 12 }, row); }); + row => { Assert.Equal([1, 5, 9], row); }, + row => { Assert.Equal([2, 6, 10], row); }, + row => { Assert.Equal([3, 7, 11], row); }, + row => { Assert.Equal([4, 8, 12], row); }); } [Fact] @@ -65,29 +65,35 @@ public async Task GivenAJaggedArrayTheTransposeDoesNotWorkAsExpected() await AsyncAssert.Collection( transposed, - row => { Assert.Equal(new[] { 1, 6, 5, 10 }, row); }, - row => { Assert.Equal(new[] { 2, 9, 3, 42 }, row); }, - row => { Assert.Equal(new[] { 4 }, row); }); + row => { Assert.Equal([1, 6, 5, 10], row); }, + row => { Assert.Equal([2, 9, 3, 42], row); }, + row => { Assert.Equal([4], row); }); } - private static IEnumerable> MagicSquare() => - Sequence.Return( + private static IEnumerable> MagicSquare() + => + [ AsyncSequence.Return(4, 9, 2), AsyncSequence.Return(3, 5, 7), - AsyncSequence.Return(8, 1, 6)); + AsyncSequence.Return(8, 1, 6), + ]; - private static IEnumerable> MatrixExample() => - Sequence.Return( + private static IEnumerable> MatrixExample() + => + [ AsyncSequence.Return(1, 2, 3, 4), AsyncSequence.Return(5, 6, 7, 8), - AsyncSequence.Return(9, 10, 11, 12)); + AsyncSequence.Return(9, 10, 11, 12) + ]; - private static IEnumerable> JaggedMatrixExample() => - Sequence.Return( + private static IEnumerable> JaggedMatrixExample() + => + [ AsyncSequence.Return(1, 2, 3, 4), AsyncSequence.Return(6, 9, 42), AsyncSequence.Return(5), - AsyncSequence.Return(10)); + AsyncSequence.Return(10) + ]; private static IEnumerable> LazyMatrix(int rows, int columns) => from row in Enumerable.Range(0, rows) diff --git a/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs b/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs index 882509db..59bebd9b 100644 --- a/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs +++ b/Funcky.Async/AsyncSequence/AsyncSequence.CycleRange.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing namespace Funcky; public static partial class AsyncSequence @@ -20,7 +21,7 @@ public static AsyncCycleBuffer Create(IAsyncEnumerable(IAsyncEnumerable source, Option maxCycles = default) : IAsyncBuffer { - private readonly List _buffer = new(); + private readonly List _buffer = []; private readonly IAsyncEnumerator _source = source.GetAsyncEnumerator(); private bool _disposed; diff --git a/Funcky.Async/Extensions/AsyncEnumerableExtensions/Memoize.cs b/Funcky.Async/Extensions/AsyncEnumerableExtensions/Memoize.cs index 61478d5c..58f7b2a8 100644 --- a/Funcky.Async/Extensions/AsyncEnumerableExtensions/Memoize.cs +++ b/Funcky.Async/Extensions/AsyncEnumerableExtensions/Memoize.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing namespace Funcky.Extensions; public static partial class AsyncEnumerableExtensions @@ -51,7 +52,7 @@ private void ThrowIfDisposed() private sealed class MemoizedAsyncBuffer(IAsyncEnumerable source) : IAsyncBuffer { - private readonly List _buffer = new(); + private readonly List _buffer = []; private readonly IAsyncEnumerator _source = source.GetAsyncEnumerator(); private bool _disposed; diff --git a/Funcky.Test/Extensions/EnumerableExtensions/AdjacentGroupByTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/AdjacentGroupByTest.cs index ae1acb1f..4db91192 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/AdjacentGroupByTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/AdjacentGroupByTest.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using Funcky.Test.TestUtils; namespace Funcky.Test.Extensions.EnumerableExtensions; @@ -112,7 +113,7 @@ private static IEnumerable DateGenerator(int startYear, Option en } private static IEnumerable DaysInMonthsOfAYear() - => Sequence.Return(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); + => [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; private static IEnumerable DaysInMonthsOfALeapYear() => DaysInMonthsOfAYear() diff --git a/Funcky.Test/Extensions/EnumerableExtensions/FirstSingleLastOrNoneTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/FirstSingleLastOrNoneTest.cs index 7465e83c..3a526666 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/FirstSingleLastOrNoneTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/FirstSingleLastOrNoneTest.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using System.Collections; namespace Funcky.Test.Extensions.EnumerableExtensions; @@ -26,9 +27,9 @@ public void GivenAnEnumerableSingleOrNoneGivesTheCorrectOption(List valueEn public static TheoryData, List> ValueReferenceEnumerables() => new() { - { new List(), new List() }, - { new List { 1 }, new List { "a" } }, - { new List { 1, 2, 3 }, new List { "a", "b", "c" } }, + { [], [] }, + { [1], ["a"] }, + { [1, 2, 3], ["a", "b", "c"] }, }; private static bool ExpectedOptionValue(ICollection valueEnumerable) => diff --git a/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs index 735ad8b8..1a75f00b 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/InterleaveTest.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using Funcky.Test.TestUtils; namespace Funcky.Test.Extensions.EnumerableExtensions; @@ -15,7 +16,7 @@ public void InterleaveIsEnumeratedLazily() [Fact] public void GivenAnEmptySequenceOfSequencesInterleaveReturnsAnEmptySequence() { - IEnumerable> emptySequence = Enumerable.Empty>(); + IEnumerable> emptySequence = []; IEnumerable interleaved = emptySequence.Interleave(); @@ -25,11 +26,11 @@ public void GivenAnEmptySequenceOfSequencesInterleaveReturnsAnEmptySequence() [Fact] public void GivenTwoSequencesOfEqualLengthIGetAnInterleavedResult() { - IEnumerable odds = new List { 1, 3, 5, 7, 9, 11 }; - IEnumerable evens = new List { 2, 4, 6, 8, 10, 12 }; - IEnumerable expected = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + IEnumerable odds = [1, 3, 5, 7, 9, 11]; + IEnumerable evens = [2, 4, 6, 8, 10, 12]; + IEnumerable expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; - IEnumerable interleaved = odds.Interleave(evens); + var interleaved = odds.Interleave(evens); Assert.Equal(expected, interleaved); } @@ -37,9 +38,9 @@ public void GivenTwoSequencesOfEqualLengthIGetAnInterleavedResult() [Fact] public void GivenTwoSequencesOfUnequalLengthIGetAnInterleavedResult() { - IEnumerable odds = new List { 1, 3, 5, 7, 9, 11 }; - IEnumerable evens = new List { 2, 4, 6 }; - IEnumerable expected = new List { 1, 2, 3, 4, 5, 6, 7, 9, 11 }; + IEnumerable odds = [1, 3, 5, 7, 9, 11]; + IEnumerable evens = [2, 4, 6]; + IEnumerable expected = [1, 2, 3, 4, 5, 6, 7, 9, 11]; IEnumerable interleaved = odds.Interleave(evens); @@ -55,13 +56,13 @@ public void GivenTwoSequencesOfUnequalLengthIGetAnInterleavedResult() [InlineData("c", "b", "a")] public void GivenMultipleSequencesTheOrderIsPreserved(string first, string second, string third) { - IEnumerable one = Sequence.Return(first); - IEnumerable two = Sequence.Return(second); - IEnumerable three = Sequence.Return(third); + IEnumerable one = [first]; + IEnumerable two = [second]; + IEnumerable three = [third]; var interleaved = one.Interleave(two, three); - Assert.Equal(new List { first, second, third }, interleaved); + Assert.Equal([first, second, third], interleaved); } [Fact] @@ -73,14 +74,14 @@ public void GivenASequenceOfSequenceTheInnerSequencesGetInterleaved() Enumerable.Repeat(42, 2), }; - Assert.Equal(new List { 1, 42, 1, 42 }, sequences.Interleave()); + Assert.Equal([1, 42, 1, 42], sequences.Interleave()); } [Fact] public void GivenOneSequenceWithElementsAndAllTheOtherSequencesEmptyWeGetTheFirstSequence() { - IEnumerable sequence = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; - IEnumerable emptySequence = Enumerable.Empty(); + IEnumerable sequence = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; + IEnumerable emptySequence = []; Assert.Equal(sequence, emptySequence.Interleave(emptySequence, sequence, emptySequence)); } diff --git a/Funcky.Test/Extensions/EnumerableExtensions/MemoizeTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/MemoizeTest.cs index f2e0f4e3..c4870b78 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/MemoizeTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/MemoizeTest.cs @@ -69,7 +69,7 @@ public void OutOfOrderMoveNextReturnsItemsInTheRightOrder() [Fact] public void DisposingAMemoizedBufferDoesNotDisposeOriginalBuffer() { - var source = EnumerateOnce.Create(Enumerable.Empty()); + var source = EnumerateOnce.Create([]); using var firstMemoization = source.Memoize(); using (firstMemoization.Memoize()) @@ -82,7 +82,7 @@ public void DisposingAMemoizedBufferDoesNotDisposeOriginalBuffer() [Fact] public void MemoizingAMemoizedBufferTwiceReturnsTheOriginalObject() { - var source = EnumerateOnce.Create(Enumerable.Empty()); + var source = EnumerateOnce.Create([]); using var memoized = source.Memoize(); using var memoizedBuffer = memoized.Memoize(); using var memoizedBuffer2 = memoizedBuffer.Memoize(); diff --git a/Funcky.Test/Extensions/EnumerableExtensions/PartitionEitherTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/PartitionEitherTest.cs index 0de9f027..e812e3f0 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/PartitionEitherTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/PartitionEitherTest.cs @@ -19,8 +19,8 @@ public void PartitionsItemsIntoLeftAndRight() Either.Right("b"), Either.Left(20)); var (left, right) = input.Partition(); - Assert.Equal(new[] { 10, 20 }, left); - Assert.Equal(new[] { "a", "b" }, right); + Assert.Equal([10, 20], left); + Assert.Equal(["a", "b"], right); } [Fact] diff --git a/Funcky.Test/Extensions/EnumerableExtensions/PartitionTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/PartitionTest.cs index 9902ea28..3d83476e 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/PartitionTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/PartitionTest.cs @@ -14,15 +14,15 @@ public void ReturnsTwoEmptyEnumerablesWhenSourceIsEmpty() public void PartitionsItemsIntoTruesAndFalses() { var (evens, odds) = Enumerable.Range(0, 6).Partition(IsEven); - Assert.Equal(new[] { 0, 2, 4 }, evens); - Assert.Equal(new[] { 1, 3, 5 }, odds); + Assert.Equal([0, 2, 4], evens); + Assert.Equal([1, 3, 5], odds); } [Fact] public void RightItemsAreEmptyWhenPredicateMatchesAllItems() { var (left, right) = Enumerable.Range(0, 6).Partition(True); - Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, left); + Assert.Equal([0, 1, 2, 3, 4, 5], left); Assert.Empty(right); } @@ -31,7 +31,7 @@ public void LeftItemsAreEmptyWhenPredicateMatchesNoItems() { var (left, right) = Enumerable.Range(0, 6).Partition(False); Assert.Empty(left); - Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, right); + Assert.Equal([0, 1, 2, 3, 4, 5], right); } private static bool IsEven(int n) => n % 2 == 0; diff --git a/Funcky.Test/Extensions/EnumerableExtensions/TakeEveryTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/TakeEveryTest.cs index eb0a604f..c78ca05d 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/TakeEveryTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/TakeEveryTest.cs @@ -56,6 +56,6 @@ public void TakeEveryWithASourceWith5ElementsAndInterval4Returns2Elements() { var numbers = new List { 1, 2, 3, 4, 5 }; - Assert.Equal(new[] { 1, 5 }, numbers.TakeEvery(4)); + Assert.Equal([1, 5], numbers.TakeEvery(4)); } } diff --git a/Funcky.Test/Extensions/EnumerableExtensions/TransposeTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/TransposeTest.cs index f454c67c..5b43a970 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/TransposeTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/TransposeTest.cs @@ -37,10 +37,10 @@ public void TransposingAMatrixResultsInATransposedMatrix() Assert.Collection( transposed, - row => { Assert.Equal(new[] { 1, 5, 9 }, row); }, - row => { Assert.Equal(new[] { 2, 6, 10 }, row); }, - row => { Assert.Equal(new[] { 3, 7, 11 }, row); }, - row => { Assert.Equal(new[] { 4, 8, 12 }, row); }); + row => { Assert.Equal([1, 5, 9], row); }, + row => { Assert.Equal([2, 6, 10], row); }, + row => { Assert.Equal([3, 7, 11], row); }, + row => { Assert.Equal([4, 8, 12], row); }); } [Fact] @@ -65,9 +65,9 @@ public void GivenAJaggedArrayTheTransposeDoesNotWorkAsExpected() Assert.Collection( transposed, - row => { Assert.Equal(new[] { 1, 6, 5, 10 }, row); }, - row => { Assert.Equal(new[] { 2, 9, 3, 42 }, row); }, - row => { Assert.Equal(new[] { 4 }, row); }); + row => { Assert.Equal([1, 6, 5, 10], row); }, + row => { Assert.Equal([2, 9, 3, 42], row); }, + row => { Assert.Equal([4], row); }); } private static IEnumerable> MagicSquare() diff --git a/Funcky.Test/Extensions/EnumerableExtensions/WhereNotNullTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/WhereNotNullTest.cs index 6e2d7444..2feb4eb3 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/WhereNotNullTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/WhereNotNullTest.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using Funcky.Test.TestUtils; namespace Funcky.Test.Extensions.EnumerableExtensions; @@ -15,38 +16,18 @@ public void WhereNotNullIsEnumeratedLazily() [Fact] public void WhereNotNullRemovesNullReferenceValues() { - var input = new[] - { - null, - "foo", - null, - "bar", - null, - }; - var expectedResult = new[] - { - "foo", - "bar", - }; + IEnumerable input = [null, "foo", null, "bar", null]; + IEnumerable expectedResult = ["foo", "bar"]; + Assert.Equal(expectedResult, input.WhereNotNull()); } [Fact] public void WhereNotNullRemovesNullValueTypeValues() { - var input = new int?[] - { - null, - 10, - null, - 20, - null, - }; - var expectedResult = new[] - { - 10, - 20, - }; + IEnumerable input = [null, 10, null, 20, null]; + IEnumerable expectedResult = [10, 20]; + Assert.Equal(expectedResult, input.WhereNotNull()); } } diff --git a/Funcky.Test/Extensions/ListExtensionsTest.cs b/Funcky.Test/Extensions/ListExtensionsTest.cs index 3b8ea3ff..ce56a517 100644 --- a/Funcky.Test/Extensions/ListExtensionsTest.cs +++ b/Funcky.Test/Extensions/ListExtensionsTest.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing namespace Funcky.Test.Extensions; public sealed class ListExtensionsTest @@ -5,7 +6,7 @@ public sealed class ListExtensionsTest [Fact] public void GivenAListIndexOfOrNoneReturnsNoneIfTheElementIsNotInTheList() { - IList list = new List { "Alpha", "Gamma", "Epsilon" }; + IList list = ["Alpha", "Gamma", "Epsilon"]; FunctionalAssert.None(list.IndexOfOrNone("Beta")); } @@ -13,7 +14,7 @@ public void GivenAListIndexOfOrNoneReturnsNoneIfTheElementIsNotInTheList() [Fact] public void GivenAListIndexOfOrNoneReturnsSomeIndexIfTheElementIsInTheList() { - IList list = new List { "Alpha", "Gamma", "Epsilon" }; + IList list = ["Alpha", "Gamma", "Epsilon"]; FunctionalAssert.Some(2, list.IndexOfOrNone("Epsilon")); } diff --git a/Funcky.Test/Extensions/StringExtensions/IndexOfTest.cs b/Funcky.Test/Extensions/StringExtensions/IndexOfTest.cs index 1aa64436..d43b18ba 100644 --- a/Funcky.Test/Extensions/StringExtensions/IndexOfTest.cs +++ b/Funcky.Test/Extensions/StringExtensions/IndexOfTest.cs @@ -37,9 +37,9 @@ public static TheoryData> InvalidIndexes() Haystack.IndexOfOrNone(NonExistingNeedle, StringComparison.InvariantCulture), Haystack.IndexOfOrNone(NonExistingNeedle, startIndex: 0, StringComparison.InvariantCulture), Haystack.IndexOfOrNone(NonExistingNeedle, startIndex: 0, count: 1, StringComparison.InvariantCulture), - Haystack.IndexOfAnyOrNone(new[] { NonExistingNeedleChar }), - Haystack.IndexOfAnyOrNone(new[] { NonExistingNeedleChar }, startIndex: 0), - Haystack.IndexOfAnyOrNone(new[] { NonExistingNeedleChar }, startIndex: 0, count: 1), + Haystack.IndexOfAnyOrNone([NonExistingNeedleChar]), + Haystack.IndexOfAnyOrNone([NonExistingNeedleChar], startIndex: 0), + Haystack.IndexOfAnyOrNone([NonExistingNeedleChar], startIndex: 0, count: 1), Haystack.LastIndexOfOrNone(NonExistingNeedleChar), Haystack.LastIndexOfOrNone(NonExistingNeedleChar, startIndex: 0), Haystack.LastIndexOfOrNone(NonExistingNeedleChar, startIndex: 0, count: 1), @@ -49,9 +49,9 @@ public static TheoryData> InvalidIndexes() Haystack.LastIndexOfOrNone(NonExistingNeedle, StringComparison.InvariantCulture), Haystack.LastIndexOfOrNone(NonExistingNeedle, startIndex: 0, StringComparison.InvariantCulture), Haystack.LastIndexOfOrNone(NonExistingNeedle, startIndex: 0, count: 1, StringComparison.InvariantCulture), - Haystack.LastIndexOfAnyOrNone(new[] { NonExistingNeedleChar }), - Haystack.LastIndexOfAnyOrNone(new[] { NonExistingNeedleChar }, startIndex: 0), - Haystack.LastIndexOfAnyOrNone(new[] { NonExistingNeedleChar }, startIndex: 0, count: 1), + Haystack.LastIndexOfAnyOrNone([NonExistingNeedleChar]), + Haystack.LastIndexOfAnyOrNone([NonExistingNeedleChar], startIndex: 0), + Haystack.LastIndexOfAnyOrNone([NonExistingNeedleChar], startIndex: 0, count: 1), }; [Theory] @@ -77,9 +77,9 @@ public static TheoryData> ValidIndexes() Haystack.IndexOfOrNone(ExistingNeedle, StringComparison.InvariantCulture), Haystack.IndexOfOrNone(ExistingNeedle, startIndex: 0, StringComparison.InvariantCulture), Haystack.IndexOfOrNone(ExistingNeedle, startIndex: 0, count: Haystack.Length, StringComparison.InvariantCulture), - Haystack.IndexOfAnyOrNone(new[] { ExistingNeedleChar }), - Haystack.IndexOfAnyOrNone(new[] { ExistingNeedleChar }, startIndex: 0), - Haystack.IndexOfAnyOrNone(new[] { ExistingNeedleChar }, startIndex: 0, count: Haystack.Length), + Haystack.IndexOfAnyOrNone([ExistingNeedleChar]), + Haystack.IndexOfAnyOrNone([ExistingNeedleChar], startIndex: 0), + Haystack.IndexOfAnyOrNone([ExistingNeedleChar], startIndex: 0, count: Haystack.Length), Haystack.LastIndexOfOrNone(ExistingNeedleChar), Haystack.LastIndexOfOrNone(ExistingNeedleChar, startIndex: Haystack.Length - 1), Haystack.LastIndexOfOrNone(ExistingNeedleChar, startIndex: Haystack.Length - 1, count: Haystack.Length), @@ -89,9 +89,9 @@ public static TheoryData> ValidIndexes() Haystack.LastIndexOfOrNone(ExistingNeedle, StringComparison.InvariantCulture), Haystack.LastIndexOfOrNone(ExistingNeedle, startIndex: Haystack.Length - 1, StringComparison.InvariantCulture), Haystack.LastIndexOfOrNone(ExistingNeedle, startIndex: Haystack.Length - 1, count: Haystack.Length, StringComparison.InvariantCulture), - Haystack.LastIndexOfAnyOrNone(new[] { ExistingNeedleChar }), - Haystack.LastIndexOfAnyOrNone(new[] { ExistingNeedleChar }, startIndex: Haystack.Length - 1), - Haystack.LastIndexOfAnyOrNone(new[] { ExistingNeedleChar }, startIndex: Haystack.Length - 1, count: Haystack.Length), + Haystack.LastIndexOfAnyOrNone([ExistingNeedleChar]), + Haystack.LastIndexOfAnyOrNone([ExistingNeedleChar], startIndex: Haystack.Length - 1), + Haystack.LastIndexOfAnyOrNone([ExistingNeedleChar], startIndex: Haystack.Length - 1, count: Haystack.Length), }; [SkipOnMonoFact] diff --git a/Funcky.Test/Extensions/StringExtensions/LazySplitTest.cs b/Funcky.Test/Extensions/StringExtensions/LazySplitTest.cs index 8ceb1922..46c77967 100644 --- a/Funcky.Test/Extensions/StringExtensions/LazySplitTest.cs +++ b/Funcky.Test/Extensions/StringExtensions/LazySplitTest.cs @@ -23,7 +23,7 @@ public Property SplitLazyWithMultipleCharactersWorksTheSameAsSplit(StringNoNulls .SequenceEqual(text.Get.SplitLazy(separator, separator2, separator3))) .ToProperty(); - #if SPLIT_ACCEPTS_STRING_SEPARATOR +#if SPLIT_ACCEPTS_STRING_SEPARATOR [Property] public Property SplitLazyWithSingleStringWorksTheSameAsSplit(StringNoNulls text, StringNoNulls separator) => (text.Get is null @@ -33,14 +33,14 @@ public Property SplitLazyWithSingleStringWorksTheSameAsSplit(StringNoNulls text, .Split(separator.Get) .SequenceEqual(text.Get.SplitLazy(separator.Get))) .ToProperty(); - #endif +#endif [Fact] public void SplitLazyWithSingleStringSplitsWithAMultiCharacterSeparator() { var text = "Picard and Kirk and Janeway and Archer"; - Assert.Equal(new[] { "Picard", "Kirk", "Janeway", "Archer" }, text.SplitLazy("and").Select(Trim)); + Assert.Equal(["Picard", "Kirk", "Janeway", "Archer"], text.SplitLazy("and").Select(Trim)); } [Fact] @@ -49,7 +49,7 @@ public void SplitLazyWithMultipleStringsSplitsWithMultipleMultiCharacterSeparato // there is no equivalent Split on string which supports multiple strings as separators... var text = "Alpha and Beta or Gamma"; - Assert.Equal(new[] { "Alpha", "Beta", "Gamma" }, text.SplitLazy("and", "or").Select(Trim)); + Assert.Equal(["Alpha", "Beta", "Gamma"], text.SplitLazy("and", "or").Select(Trim)); } [Fact] @@ -57,7 +57,7 @@ public void SplitLazyWithMultipleStringsDoesWorkWithEmptySeparator() { var text = "Something"; - Assert.Equal(new[] { "Something" }, text.SplitLazy("and", "or", string.Empty).Select(Trim)); + Assert.Equal(["Something"], text.SplitLazy("and", "or", string.Empty).Select(Trim)); } [Fact] @@ -65,7 +65,7 @@ public void SplitLazyWithMultipleStringsWorksWithSpecialUnicodeCharactersCorrect { var text = "Something"; - Assert.Equal(new[] { "Something" }, text.SplitLazy("and", "\u0003")); + Assert.Equal(["Something"], text.SplitLazy("and", "\u0003")); } [Fact] @@ -73,7 +73,7 @@ public void SplitLazyWithMultipleStringsWorksWithAnEmptySource() { var text = string.Empty; - Assert.Equal(new[] { string.Empty }, text.SplitLazy("and", "or")); + Assert.Equal([string.Empty], text.SplitLazy("and", "or")); } private static string Trim(string s) diff --git a/Funcky.Test/Monads/ReaderTest.cs b/Funcky.Test/Monads/ReaderTest.cs index 14857100..6658427a 100644 --- a/Funcky.Test/Monads/ReaderTest.cs +++ b/Funcky.Test/Monads/ReaderTest.cs @@ -20,7 +20,7 @@ public void YouCanApplyEnvironmentToReaderMonad() [Fact] public void ReaderMonadImplementsSelect() { - var quoteReader = QuotedList(new[] { "Alpha", "Beta" }); + var quoteReader = QuotedList(["Alpha", "Beta"]); Assert.Equal("`Alpha`, `Beta`", quoteReader(new Configuration('`'))); } diff --git a/Funcky.Test/Monads/ResultTest.cs b/Funcky.Test/Monads/ResultTest.cs index 7f6c18e7..aa3c3afd 100644 --- a/Funcky.Test/Monads/ResultTest.cs +++ b/Funcky.Test/Monads/ResultTest.cs @@ -238,7 +238,7 @@ private static void IsInterestingStackTraceFirst(Exception exception) { Assert.NotNull(exception.StackTrace); - var lines = exception.StackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None); + var lines = exception.StackTrace.Split([Environment.NewLine], StringSplitOptions.None); Assert.Matches(@"^\s+(\w+) Funcky\.Test\.Monads\.ResultTest\.InterestingStackTrace\s*\((System\.)?Int32 n\)", lines.First()); } diff --git a/Funcky/Compatibility/ExceptionUtilities.cs b/Funcky/Compatibility/ExceptionUtilities.cs index e543f29b..77dbbc87 100644 --- a/Funcky/Compatibility/ExceptionUtilities.cs +++ b/Funcky/Compatibility/ExceptionUtilities.cs @@ -1,4 +1,5 @@ #if !SET_CURRENT_STACK_TRACE_SUPPORTED +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using System.Diagnostics; using System.Linq.Expressions; using System.Reflection; @@ -15,7 +16,7 @@ internal static class ExceptionUtilities private static Func CompileSetStackTrace() { var traceFormatType = typeof(StackTrace).GetNestedType("TraceFormat", BindingFlags.NonPublic)!; - var toString = typeof(StackTrace).GetMethod("ToString", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { traceFormatType }, null)!; + var toString = typeof(StackTrace).GetMethod("ToString", BindingFlags.NonPublic | BindingFlags.Instance, null, [traceFormatType], null)!; var stackTraceStringField = typeof(Exception).GetField("_stackTraceString", BindingFlags.NonPublic | BindingFlags.Instance)!; var target = Expression.Parameter(typeof(Exception)); diff --git a/Funcky/Extensions/EnumerableExtensions/Interleave.cs b/Funcky/Extensions/EnumerableExtensions/Interleave.cs index 316b9731..6763331d 100644 --- a/Funcky/Extensions/EnumerableExtensions/Interleave.cs +++ b/Funcky/Extensions/EnumerableExtensions/Interleave.cs @@ -13,7 +13,7 @@ public static partial class EnumerableExtensions /// one sequences with all the elements interleaved. [Pure] public static IEnumerable Interleave(this IEnumerable source, params IEnumerable[] otherSources) - => ImmutableList.Create(source).AddRange(otherSources).Interleave(); + => Interleave([source, .. otherSources]); /// /// Interleaves the elements of a sequence of sequences by consuming the heads of each subsequence in the same order as the given subsequences. This repeats until all the sequences are completley consumed. diff --git a/Funcky/Extensions/EnumerableExtensions/Memoize.cs b/Funcky/Extensions/EnumerableExtensions/Memoize.cs index d98335a6..765a9a84 100644 --- a/Funcky/Extensions/EnumerableExtensions/Memoize.cs +++ b/Funcky/Extensions/EnumerableExtensions/Memoize.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using System.Collections; using System.Diagnostics.CodeAnalysis; @@ -53,7 +54,7 @@ private void ThrowIfDisposed() private sealed class MemoizedBuffer(IEnumerable source) : IBuffer { - private readonly List _buffer = new(); + private readonly List _buffer = []; private readonly IEnumerator _source = source.GetEnumerator(); private bool _disposed; diff --git a/Funcky/Extensions/EnumerableExtensions/Merge.cs b/Funcky/Extensions/EnumerableExtensions/Merge.cs index 0e1764a1..3e049549 100644 --- a/Funcky/Extensions/EnumerableExtensions/Merge.cs +++ b/Funcky/Extensions/EnumerableExtensions/Merge.cs @@ -17,7 +17,7 @@ public static partial class EnumerableExtensions /// The merged sequences in the same order as the given sequences. [Pure] public static IEnumerable Merge(this IEnumerable source1, IEnumerable source2, Option> comparer = default) - => ImmutableList.Create(source1, source2).Merge(comparer); + => Merge([source1, source2], comparer); /// /// Merges three ordered sequences into one and preserves the ordering. The merged sequences has exactly the same number of elements as the inputs combined. @@ -31,7 +31,7 @@ public static IEnumerable Merge(this IEnumerable sour /// The merged sequences in the same order as the given sequences. [Pure] public static IEnumerable Merge(this IEnumerable source1, IEnumerable source2, IEnumerable source3, Option> comparer = default) - => ImmutableList.Create(source1, source2, source3).Merge(comparer); + => Merge([source1, source2, source3], comparer); /// /// Merges three ordered sequences into one and preserves the ordering. The merged sequences has exactly the same number of elements as the inputs combined. @@ -46,7 +46,7 @@ public static IEnumerable Merge(this IEnumerable sour /// The merged sequences in the same order as the given sequences. [Pure] public static IEnumerable Merge(this IEnumerable source1, IEnumerable source2, IEnumerable source3, IEnumerable source4, Option> comparer = default) - => ImmutableList.Create(source1, source2, source3, source4).Merge(comparer); + => Merge([source1, source2, source3, source4], comparer); /// /// Merges a sequence of ordered sequences into one and preserves the ordering. The merged sequences has exactly the same number of elements as the inputs combined. @@ -75,7 +75,7 @@ public static IEnumerable Merge(this IEnumerable> GetMergeEnumerators(IEnumerable> sources) - => ImmutableList.Create>().AddRange(sources.Select(s => s.GetEnumerator())); + => sources.Select(s => s.GetEnumerator()).ToImmutableList(); private static IComparer GetMergeComparer(Option> comparer = default) => comparer.GetOrElse(Comparer.Default); diff --git a/Funcky/Extensions/EnumerableExtensions/Transpose.cs b/Funcky/Extensions/EnumerableExtensions/Transpose.cs index 1962acca..29f85f77 100644 --- a/Funcky/Extensions/EnumerableExtensions/Transpose.cs +++ b/Funcky/Extensions/EnumerableExtensions/Transpose.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using System.Diagnostics.CodeAnalysis; namespace Funcky.Extensions; @@ -17,5 +18,5 @@ public static partial class EnumerableExtensions public static IEnumerable> Transpose(this IEnumerable> source) => source.Any() ? source.Interleave().Chunk(source.Count()) - : Enumerable.Empty>(); + : []; } diff --git a/Funcky/Extensions/StringExtensions/SplitLines.cs b/Funcky/Extensions/StringExtensions/SplitLines.cs index 19e07b2e..ebf49d83 100644 --- a/Funcky/Extensions/StringExtensions/SplitLines.cs +++ b/Funcky/Extensions/StringExtensions/SplitLines.cs @@ -16,7 +16,7 @@ public static IEnumerable SplitLines(this string text) private static Option GetNextLine(string text, int startIndex) => text - .IndexOfAnyOrNone(new[] { CarriageReturn, LineFeed }, startIndex) + .IndexOfAnyOrNone([CarriageReturn, LineFeed], startIndex) .Match( none: EndOfString(startIndex, text), some: NewLine(text, startIndex)); diff --git a/Funcky/Monads/Option/Option.Convenience.cs b/Funcky/Monads/Option/Option.Convenience.cs index 80deeb59..f36d2b3a 100644 --- a/Funcky/Monads/Option/Option.Convenience.cs +++ b/Funcky/Monads/Option/Option.Convenience.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing namespace Funcky.Monads; public readonly partial struct Option @@ -67,6 +68,6 @@ public Option InspectNone(Action inspector) [Pure] public IEnumerable ToEnumerable() => Match( - none: Enumerable.Empty, + none: [], some: Sequence.Return); } diff --git a/Funcky/Sequence/Sequence.CycleRange.cs b/Funcky/Sequence/Sequence.CycleRange.cs index de09042b..912da0e4 100644 --- a/Funcky/Sequence/Sequence.CycleRange.cs +++ b/Funcky/Sequence/Sequence.CycleRange.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing using System.Collections; namespace Funcky; @@ -22,7 +23,7 @@ public static CycleBuffer Create(IEnumerable source, private sealed class CycleBuffer(IEnumerable source, Option maxCycles = default) : IBuffer { - private readonly List _buffer = new(); + private readonly List _buffer = []; private readonly IEnumerator _source = source.GetEnumerator(); private bool _disposed; diff --git a/Funcky/Sequence/Sequence.FromNullable.cs b/Funcky/Sequence/Sequence.FromNullable.cs index 84ffb515..1ec14ff5 100644 --- a/Funcky/Sequence/Sequence.FromNullable.cs +++ b/Funcky/Sequence/Sequence.FromNullable.cs @@ -1,3 +1,4 @@ +#pragma warning disable SA1010 // StyleCop support for collection expressions is missing namespace Funcky; public static partial class Sequence @@ -6,11 +7,11 @@ public static partial class Sequence [Pure] public static IEnumerable FromNullable(TResult? element) where TResult : class - => element is null ? Enumerable.Empty() : Return(element); + => element is null ? [] : [element]; /// [Pure] public static IEnumerable FromNullable(TResult? element) where TResult : struct - => element.HasValue ? Return(element.Value) : Enumerable.Empty(); + => element.HasValue ? [element.Value] : []; }