Skip to content

Commit

Permalink
Check formatting and style with dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Apr 11, 2024
1 parent f84b25f commit 8e75914
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 56 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ private static async IAsyncEnumerable<TSource> InterleaveInternal<TSource>(
}
}

#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<T>(IAsyncEnumerator<T> enumerator) => await enumerator.DisposeAsync().ConfigureAwait(false);
#pragma warning restore IDISP007
#pragma warning restore IDISP007

private static ImmutableList<IAsyncEnumerator<TSource>> GetInterleaveEnumerators<TSource>(
IEnumerable<IAsyncEnumerable<TSource>> source,
Expand Down
4 changes: 2 additions & 2 deletions Funcky.Async/Extensions/AsyncEnumerableExtensions/Pairwise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ private static async IAsyncEnumerable<TResult> PairwiseInternal<TSource, TResult
Func<TSource, TSource, TResult> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public static partial class AsyncEnumerableExtensions
[Pure]
public static async IAsyncEnumerable<ValueWithFirst<TSource>> WithFirst<TSource>(this IAsyncEnumerable<TSource> 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())
{
Expand Down
4 changes: 2 additions & 2 deletions Funcky.Async/Extensions/AsyncEnumerableExtensions/WithLast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public static partial class AsyncEnumerableExtensions
[Pure]
public static async IAsyncEnumerable<ValueWithLast<TSource>> WithLast<TSource>(this IAsyncEnumerable<TSource> 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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public static async IAsyncEnumerable<TResult> ZipLongest<TLeft, TRight, TResult>
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))
{
Expand Down
4 changes: 2 additions & 2 deletions Funcky.Test/Extensions/EnumerableExtensions/ChunkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnlyList<string>> chunked = numbers.Chunk(chunkSize);
#pragma warning restore IDE0007
#pragma warning restore IDE0007

Assert.Collection(
chunked,
Expand Down
6 changes: 3 additions & 3 deletions Funcky.Xunit/FunctionalAssert/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public static partial class FunctionalAssert
{
/// <summary>Asserts that the given <paramref name="result"/> is <c>Error</c>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="result"/> is <c>Ok</c>.</exception>
#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<TValidResult>(Result<TValidResult> result)
where TValidResult : notnull
Expand Down
12 changes: 6 additions & 6 deletions Funcky.Xunit/FunctionalAssert/Left.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public static partial class FunctionalAssert
{
/// <summary>Asserts that the given <paramref name="either"/> is <c>Left</c> and contains the given <paramref name="expectedLeft"/>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="either"/> is <c>Right</c>.</exception>
#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, TRight>(TLeft expectedLeft, Either<TLeft, TRight> either)
where TLeft : notnull
where TRight : notnull
Expand All @@ -33,11 +33,11 @@ public static void Left<TLeft, TRight>(TLeft expectedLeft, Either<TLeft, TRight>
/// <summary>Asserts that the given <paramref name="either"/> is <c>Left</c>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="either"/> is <c>Right</c>.</exception>
/// <returns>Returns the value in <paramref name="either"/> if it was <c>Left</c>.</returns>
#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<TLeft, TRight>(Either<TLeft, TRight> either)
Expand Down
6 changes: 3 additions & 3 deletions Funcky.Xunit/FunctionalAssert/None.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public static partial class FunctionalAssert
{
/// <summary>Asserts that the given <paramref name="option"/> is <c>None</c>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="option"/> is <c>Some</c>.</exception>
#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<TItem>(Option<TItem> option)
Expand Down
12 changes: 6 additions & 6 deletions Funcky.Xunit/FunctionalAssert/Ok.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public static partial class FunctionalAssert
{
/// <summary>Asserts that the given <paramref name="result"/> is <c>Ok</c> and contains the given <paramref name="expectedResult"/>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="result"/> is <c>Error</c>.</exception>
#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>(TValidResult expectedResult, Result<TValidResult> result)
where TValidResult : notnull
{
Expand All @@ -32,11 +32,11 @@ public static void Ok<TValidResult>(TValidResult expectedResult, Result<TValidRe
/// <summary>Asserts that the given <paramref name="result"/> is <c>Ok</c>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="result"/> is <c>Error</c>.</exception>
/// <returns>Returns the value in <paramref name="result"/> if it was <c>Ok</c>.</returns>
#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<TValidResult>(Result<TValidResult> result)
Expand Down
12 changes: 6 additions & 6 deletions Funcky.Xunit/FunctionalAssert/Right.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public static partial class FunctionalAssert
{
/// <summary>Asserts that the given <paramref name="either"/> is <c>Right</c> and contains the given <paramref name="expectedRight"/>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="either"/> is <c>Left</c>.</exception>
#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<TLeft, TRight>(TRight expectedRight, Either<TLeft, TRight> either)
where TLeft : notnull
where TRight : notnull
Expand All @@ -33,11 +33,11 @@ public static void Right<TLeft, TRight>(TRight expectedRight, Either<TLeft, TRig
/// <summary>Asserts that the given <paramref name="either"/> is <c>Right</c>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="either"/> is <c>Left</c>.</exception>
/// <returns>Returns the value in <paramref name="either"/> if it was <c>Right</c>.</returns>
#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<TLeft, TRight>(Either<TLeft, TRight> either)
Expand Down
12 changes: 6 additions & 6 deletions Funcky.Xunit/FunctionalAssert/Some.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public static partial class FunctionalAssert
{
/// <summary>Asserts that the given <paramref name="option"/> is <c>Some</c> and contains the given <paramref name="expectedValue"/>.</summary>
/// <exception cref="AssertActualExpectedException">Thrown when the option is <c>None</c>.</exception>
#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>(TItem expectedValue, Option<TItem> option)
where TItem : notnull
{
Expand All @@ -33,11 +33,11 @@ public static void Some<TItem>(TItem expectedValue, Option<TItem> option)
/// <exception cref="AssertActualExpectedException">Thrown when <paramref name="option"/> is <c>None</c>.</exception>
/// <returns>Returns the value in <paramref name="option"/> if it was <c>Some</c>.</returns>
[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<TItem>(Option<TItem> option)
Expand Down
2 changes: 1 addition & 1 deletion Funcky/Extensions/EnumerableExtensions/Shuffle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public static IReadOnlyList<TSource> Shuffle<TSource>(this IEnumerable<TSource>
=> source
.ToList()
.ToRandomList(random);
#endif
#endif
}
2 changes: 1 addition & 1 deletion Funcky/Internal/Validators/ChunkSizeValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;

namespace Funcky.Internal.Validators;

Expand Down
22 changes: 11 additions & 11 deletions Funcky/Monads/Result/Result.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace Funcky.Monads;
public readonly partial struct Result<TValidResult> : IEquatable<Result<TValidResult>>
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;
Expand Down Expand Up @@ -49,16 +49,16 @@ private Result(Exception error)
/// <summary>Creates a new <see cref="Result{TValidResult}"/> from an <see cref="Exception"/> and sets
/// the stack trace if not already set.</summary>
/// <remarks>This method has side effects: It sets the stack trace on <paramref name="exception"/> if not already set.</remarks>
#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 <c>SetCurrentStackTrace</c> 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<TValidResult> Error(Exception exception)
{
if (exception is null)
Expand All @@ -68,11 +68,11 @@ public static Result<TValidResult> 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<TValidResult>(exception);
Expand Down

0 comments on commit 8e75914

Please sign in to comment.