diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b506bc5..f1df0c51 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,20 @@ jobs: - name: Run Tests run: dotnet test --configuration Release --no-build + style: + name: Check Formatting and Style + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-dotnet@v3 + name: Install Current .NET SDK + - name: Restore dependencies + run: dotnet restore + - run: dotnet format style --verify-no-changes --no-restore + name: Style + - run: dotnet format whitespace --verify-no-changes --no-restore + name: Whitespace + trimming-test: name: Trimming Test runs-on: ubuntu-latest diff --git a/Funcky.Analyzers/Funcky.Analyzers/EnumerableRepeatOnceAnalyzer.cs b/Funcky.Analyzers/Funcky.Analyzers/EnumerableRepeatOnceAnalyzer.cs index 8371c1eb..5ae6bdbe 100644 --- a/Funcky.Analyzers/Funcky.Analyzers/EnumerableRepeatOnceAnalyzer.cs +++ b/Funcky.Analyzers/Funcky.Analyzers/EnumerableRepeatOnceAnalyzer.cs @@ -57,7 +57,7 @@ private static bool MatchRepeatOnce( { valueArgument = null; return MatchMethod(operation, enumerableType, nameof(Enumerable.Repeat)) - && MatchArguments(operation, out valueArgument, AnyArgument, out _, ConstantArgument(1)); + && MatchArguments(operation, out valueArgument, AnyArgument, out _, ConstantArgument(1)); } private static Diagnostic CreateDiagnostic(IInvocationOperation operation, IArgumentOperation valueArgument) diff --git a/Funcky.Async/Extensions/AsyncEnumerableExtensions/Interleave.cs b/Funcky.Async/Extensions/AsyncEnumerableExtensions/Interleave.cs index 4919eee7..0e473539 100644 --- a/Funcky.Async/Extensions/AsyncEnumerableExtensions/Interleave.cs +++ b/Funcky.Async/Extensions/AsyncEnumerableExtensions/Interleave.cs @@ -45,9 +45,9 @@ private static async IAsyncEnumerable InterleaveInternal( } } - #pragma warning disable IDISP007 // The entire point of this method is to dispose. +#pragma warning disable IDISP007 // The entire point of this method is to dispose. private static async Task DisposeEnumerator(IAsyncEnumerator enumerator) => await enumerator.DisposeAsync().ConfigureAwait(false); - #pragma warning restore IDISP007 +#pragma warning restore IDISP007 private static ImmutableList> GetInterleaveEnumerators( IEnumerable> source, diff --git a/Funcky.Async/Extensions/AsyncEnumerableExtensions/Pairwise.cs b/Funcky.Async/Extensions/AsyncEnumerableExtensions/Pairwise.cs index 359b03b7..e77ff422 100644 --- a/Funcky.Async/Extensions/AsyncEnumerableExtensions/Pairwise.cs +++ b/Funcky.Async/Extensions/AsyncEnumerableExtensions/Pairwise.cs @@ -33,9 +33,9 @@ private static async IAsyncEnumerable PairwiseInternal resultSelector, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - #pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task await using var enumerator = source.ConfigureAwait(false).WithCancellation(cancellationToken).GetAsyncEnumerator(); - #pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task if (await enumerator.MoveNextAsync() == false) { diff --git a/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithFirst.cs b/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithFirst.cs index c5211987..7166ed26 100644 --- a/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithFirst.cs +++ b/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithFirst.cs @@ -11,9 +11,9 @@ public static partial class AsyncEnumerableExtensions [Pure] public static async IAsyncEnumerable> WithFirst(this IAsyncEnumerable source) { - #pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task await using var enumerator = source.ConfigureAwait(false).GetAsyncEnumerator(); - #pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task if (!await enumerator.MoveNextAsync()) { diff --git a/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithLast.cs b/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithLast.cs index 1624f8e7..3b465e69 100644 --- a/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithLast.cs +++ b/Funcky.Async/Extensions/AsyncEnumerableExtensions/WithLast.cs @@ -11,9 +11,9 @@ public static partial class AsyncEnumerableExtensions [Pure] public static async IAsyncEnumerable> WithLast(this IAsyncEnumerable source) { - #pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task await using var enumerator = source.ConfigureAwait(false).GetAsyncEnumerator(); - #pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task if (!await enumerator.MoveNextAsync()) { diff --git a/Funcky.Async/Extensions/AsyncEnumerableExtensions/ZipLongest.cs b/Funcky.Async/Extensions/AsyncEnumerableExtensions/ZipLongest.cs index 7f284546..5168d482 100644 --- a/Funcky.Async/Extensions/AsyncEnumerableExtensions/ZipLongest.cs +++ b/Funcky.Async/Extensions/AsyncEnumerableExtensions/ZipLongest.cs @@ -33,10 +33,10 @@ public static async IAsyncEnumerable ZipLongest where TLeft : notnull where TRight : notnull { - #pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task await using var leftEnumerator = left.ConfigureAwait(false).GetAsyncEnumerator(); await using var rightEnumerator = right.ConfigureAwait(false).GetAsyncEnumerator(); - #pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task +#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task while ((await MoveNextOrNone(leftEnumerator, rightEnumerator).ConfigureAwait(false)).TryGetValue(out var next)) { diff --git a/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs b/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs index 847e82ef..2287f242 100644 --- a/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs +++ b/Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs @@ -80,9 +80,9 @@ public void GivenAnEnumerableNotAMultipleOfSizeWeHaveASmallerLastSlice() var numbers = Sequence.Return("a", "b", "c", "d", "e", "g", "h", "i", "j").ToList(); const int chunkSize = 4; - #pragma warning disable IDE0007 // False positive +#pragma warning disable IDE0007 // False positive IEnumerable> chunked = numbers.Chunk(chunkSize); - #pragma warning restore IDE0007 +#pragma warning restore IDE0007 Assert.Collection( chunked, diff --git a/Funcky.Xunit/FunctionalAssert/Error.cs b/Funcky.Xunit/FunctionalAssert/Error.cs index fb80d1d1..9d90a13c 100644 --- a/Funcky.Xunit/FunctionalAssert/Error.cs +++ b/Funcky.Xunit/FunctionalAssert/Error.cs @@ -7,11 +7,11 @@ public static partial class FunctionalAssert { /// Asserts that the given is Error. /// Thrown when is Ok. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif [SuppressMessage("Microsoft.Usage", "CA2200", Justification = "Stack trace erasure intentional.")] public static Exception Error(Result result) where TValidResult : notnull diff --git a/Funcky.Xunit/FunctionalAssert/Left.cs b/Funcky.Xunit/FunctionalAssert/Left.cs index 4d4c92f9..1acbf7dc 100644 --- a/Funcky.Xunit/FunctionalAssert/Left.cs +++ b/Funcky.Xunit/FunctionalAssert/Left.cs @@ -8,11 +8,11 @@ public static partial class FunctionalAssert { /// Asserts that the given is Left and contains the given . /// Thrown when is Right. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif public static void Left(TLeft expectedLeft, Either either) where TLeft : notnull where TRight : notnull @@ -33,11 +33,11 @@ public static void Left(TLeft expectedLeft, Either /// Asserts that the given is Left. /// Thrown when is Right. /// Returns the value in if it was Left. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif [SuppressMessage("Microsoft.Usage", "CA2200", Justification = "Stack trace erasure intentional.")] [SuppressMessage("ReSharper", "PossibleIntendedRethrow", Justification = "Stack trace erasure intentional.")] public static TLeft Left(Either either) diff --git a/Funcky.Xunit/FunctionalAssert/None.cs b/Funcky.Xunit/FunctionalAssert/None.cs index fbac3cf6..03db3fed 100644 --- a/Funcky.Xunit/FunctionalAssert/None.cs +++ b/Funcky.Xunit/FunctionalAssert/None.cs @@ -7,11 +7,11 @@ public static partial class FunctionalAssert { /// Asserts that the given is None. /// Thrown when is Some. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif [SuppressMessage("Microsoft.Usage", "CA2200", Justification = "Stack trace erasure intentional.")] [SuppressMessage("ReSharper", "PossibleIntendedRethrow", Justification = "Stack trace erasure intentional.")] public static void None(Option option) diff --git a/Funcky.Xunit/FunctionalAssert/Ok.cs b/Funcky.Xunit/FunctionalAssert/Ok.cs index 3b6efd19..8769d653 100644 --- a/Funcky.Xunit/FunctionalAssert/Ok.cs +++ b/Funcky.Xunit/FunctionalAssert/Ok.cs @@ -8,11 +8,11 @@ public static partial class FunctionalAssert { /// Asserts that the given is Ok and contains the given . /// Thrown when is Error. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif public static void Ok(TValidResult expectedResult, Result result) where TValidResult : notnull { @@ -32,11 +32,11 @@ public static void Ok(TValidResult expectedResult, ResultAsserts that the given is Ok. /// Thrown when is Error. /// Returns the value in if it was Ok. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif [SuppressMessage("Microsoft.Usage", "CA2200", Justification = "Stack trace erasure intentional.")] [SuppressMessage("ReSharper", "PossibleIntendedRethrow", Justification = "Stack trace erasure intentional.")] public static TValidResult Ok(Result result) diff --git a/Funcky.Xunit/FunctionalAssert/Right.cs b/Funcky.Xunit/FunctionalAssert/Right.cs index 505b5d10..76cc668d 100644 --- a/Funcky.Xunit/FunctionalAssert/Right.cs +++ b/Funcky.Xunit/FunctionalAssert/Right.cs @@ -8,11 +8,11 @@ public static partial class FunctionalAssert { /// Asserts that the given is Right and contains the given . /// Thrown when is Left. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif public static void Right(TRight expectedRight, Either either) where TLeft : notnull where TRight : notnull @@ -33,11 +33,11 @@ public static void Right(TRight expectedRight, EitherAsserts that the given is Right. /// Thrown when is Left. /// Returns the value in if it was Right. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif [SuppressMessage("Microsoft.Usage", "CA2200", Justification = "Stack trace erasure intentional.")] [SuppressMessage("ReSharper", "PossibleIntendedRethrow", Justification = "Stack trace erasure intentional.")] public static TRight Right(Either either) diff --git a/Funcky.Xunit/FunctionalAssert/Some.cs b/Funcky.Xunit/FunctionalAssert/Some.cs index bf17666b..f0d846de 100644 --- a/Funcky.Xunit/FunctionalAssert/Some.cs +++ b/Funcky.Xunit/FunctionalAssert/Some.cs @@ -8,11 +8,11 @@ public static partial class FunctionalAssert { /// Asserts that the given is Some and contains the given . /// Thrown when the option is None. - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif public static void Some(TItem expectedValue, Option option) where TItem : notnull { @@ -33,11 +33,11 @@ public static void Some(TItem expectedValue, Option option) /// Thrown when is None. /// Returns the value in if it was Some. [Pure] - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [System.Diagnostics.StackTraceHidden] - #else +#else [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - #endif +#endif [SuppressMessage("Microsoft.Usage", "CA2200", Justification = "Stack trace erasure intentional.")] [SuppressMessage("ReSharper", "PossibleIntendedRethrow", Justification = "Stack trace erasure intentional.")] public static TItem Some(Option option) diff --git a/Funcky/Extensions/EnumerableExtensions/Shuffle.cs b/Funcky/Extensions/EnumerableExtensions/Shuffle.cs index 5d6c9d0c..eb3cdcfa 100644 --- a/Funcky/Extensions/EnumerableExtensions/Shuffle.cs +++ b/Funcky/Extensions/EnumerableExtensions/Shuffle.cs @@ -32,5 +32,5 @@ public static IReadOnlyList Shuffle(this IEnumerable => source .ToList() .ToRandomList(random); - #endif +#endif } diff --git a/Funcky/Internal/Validators/ChunkSizeValidator.cs b/Funcky/Internal/Validators/ChunkSizeValidator.cs index c3ce35da..8dd5a983 100644 --- a/Funcky/Internal/Validators/ChunkSizeValidator.cs +++ b/Funcky/Internal/Validators/ChunkSizeValidator.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace Funcky.Internal.Validators; diff --git a/Funcky/Monads/Result/Result.Core.cs b/Funcky/Monads/Result/Result.Core.cs index 4ff3516e..c023d1e8 100644 --- a/Funcky/Monads/Result/Result.Core.cs +++ b/Funcky/Monads/Result/Result.Core.cs @@ -15,9 +15,9 @@ namespace Funcky.Monads; public readonly partial struct Result : IEquatable> where TValidResult : notnull { - #if !SET_CURRENT_STACK_TRACE_SUPPORTED +#if !SET_CURRENT_STACK_TRACE_SUPPORTED private const int SkipLowestStackFrame = 1; - #endif +#endif private readonly TValidResult _result; private readonly Exception? _error; @@ -49,16 +49,16 @@ private Result(Exception error) /// Creates a new from an and sets /// the stack trace if not already set. /// This method has side effects: It sets the stack trace on if not already set. - #if SET_CURRENT_STACK_TRACE_SUPPORTED +#if SET_CURRENT_STACK_TRACE_SUPPORTED // Methods with AggressiveInlining are always excluded from the stack trace. // This is required for SetCurrentStackTrace to work properly. // See: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs#L347 - #if STACK_TRACE_HIDDEN_SUPPORTED +#if STACK_TRACE_HIDDEN_SUPPORTED [StackTraceHidden] - #else +#else [MethodImpl(MethodImplOptions.AggressiveInlining)] - #endif - #endif +#endif +#endif public static Result Error(Exception exception) { if (exception is null) @@ -68,11 +68,11 @@ public static Result Error(Exception exception) if (exception.StackTrace is null) { - #if SET_CURRENT_STACK_TRACE_SUPPORTED - ExceptionDispatchInfo.SetCurrentStackTrace(exception); - #else +#if SET_CURRENT_STACK_TRACE_SUPPORTED + ExceptionDispatchInfo.SetCurrentStackTrace(exception); +#else exception.SetStackTrace(new StackTrace(SkipLowestStackFrame, true)); - #endif +#endif } return new Result(exception);