belav / csharpier

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

Another very minor issue with the new C# list syntax #1059

Closed fgimian closed 11 months ago

fgimian commented 12 months ago

Hey again, just found another very minor issue.

host.AddSection(
    name: "Kontakt Libraries (Third Party)",
    tags: Tags.SamplesUsed,
    tasks:
    [
        // TODO: Add any used third party instruments below as you discover them.
    ]
);

Is being formatted to:

host.AddSection(
    name: "Kontakt Libraries (Third Party)",
    tags: Tags.SamplesUsed,
    tasks:
    [
    // TODO: Add any used third party instruments below as you discover them.
    ]
);

I think that any code (comments included) inside the square brackets should be indented. What do you think?

Cheers Fotis

belav commented 11 months ago

While looking into a fix for this, I found out this same problem exists in a lot of different cases.

[Attribute
// some comment
]
class Class
{
    void Method()
    {
        CallMethod(
            [
            // some comment
            ]
        );

        CallMethod(
        // some comment
        );

        var x = Array[
            1
        // some comment
        ];
    }
}

I'm sure there are more, close brackets also exist in these other node types. I didn't figure out how many places closing parenthesis exists.

ArrayRankSpecifierSyntax
FunctionPointerUnmanagedCallingConventionListSyntax
ImplicitArrayCreationExpressionSyntax
ImplicitStackAllocArrayCreationExpressionSyntax
ListPatternSyntax
BracketedParameterListSyntax
CrefBracketedParameterListSyntax

Some of these are unlikely to occur in real code, so instead of trying to address them all I'm thinking just fix them as they come up.

fgimian commented 11 months ago

Thank you so much for your help! 😊