belav / csharpier

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

Excess empty line in combination of switch expression, value tuple, and pattern matching #1271

Closed NonSpicyBurrito closed 5 months ago

NonSpicyBurrito commented 5 months ago

Input:

void Fn()
{
    return x switch
    {
        (true, true) => x,
        (false, false)
        or _
            => Longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg(),
    };
}

Output:

void Fn()
{
    return x switch
    {
        (true, true) => x,

        (false, false)
        or _
            => Longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg(),
    };
}

Output (formatting the previous output again):

void Fn()
{
    return x switch
    {
        (true, true) => x,

        (false, false)
        or _
            => Longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg(),
    };
}

Expected behavior: No excess empty line is created above the last branch.

domn1995 commented 5 months ago

Also running into a nasty related case when there are chained method calls in the switch branch:

Input:

void Fn()
{
    return x switch
    {
        (true, true) => foobar.MethodCall1().MethodCall2().MethodCall3(),
        // ...
    };
}

Output:

void Fn()
{
    return x switch
    {
        (true, true) 
           => foobar
              .MethodCall1()
              .MethodCall2()
              .MethodCall3(),
        // ...
    };
}

Expected:

void Fn()
{
    return x switch
    {
        (true, true) => 
            foobar.MethodCall1()
                .MethodCall2()
                .MethodCall3(),
        // ...
    };
}
belav commented 5 months ago

@domn1995 do you mind creating a new issue for that? Thanks!