belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.43k stars 99 forks source link

Bugs caused by new formatting of lambda expressions #1077

Closed Rudomitori closed 11 months ago

Rudomitori commented 11 months ago

The new formatting implemented in #1066 have brought several new bugs.

First

An empty argument list is splitted to several lines if the closing bracket is exactly the 100th character of the line

Input:

private static readonly ModelBinderProviderCollection _providers =
    CreateDefaultCollection();

Output:

private static readonly ModelBinderProviderCollection _providers = CreateDefaultCollection(

);

Expected behavior:

private static readonly ModelBinderProviderCollection _providers =
    CreateDefaultCollection();

Second

In an argument list with one lambda the closing bracket is moved to the next line if it's exactly the 100th character of the line

Input:

                            It.Is<ExceptionLoggerContext>(
                                c => c.ExceptionContext == expectedContext
                            )

Output:

                            It.Is<ExceptionLoggerContext>(c => c.ExceptionContext == expectedContext
                            )

Expected behavior:

                            It.Is<ExceptionLoggerContext>(c =>
                                c.ExceptionContext == expectedContext
                            )

Third

An argument list with a lambda is incorecctly formatted if the lambda contains other nested argument list with a lambda

Input:

        this.Where______________________________________(
            selector: static longName_________________ =>
            {
                return Method(x => x.Prop);
            }
        );

Output:

        this.Where______________________________________(
            selector: static longName_________________ =>
            {
                return Method(x => x.Prop);
            });

Expected behavior:

        this.Where______________________________________(
            selector: static longName_________________ =>
            {
                return Method(x => x.Prop);
            }
        );
Rudomitori commented 11 months ago

@belav I've fixed the first and third buhs, but I need more time to fix the second

belav commented 11 months ago

@Rudomitori thanks for taking care of all of these!