csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

ParenthesizedLambdaExpressions needs some work.

Open belav opened this issue 4 years ago • 3 comments

        var task = Task.Factory.StartNew(async () =>  {
                return await new WebClient().DownloadStringTaskAsync(
                    "http://example.com"
                );
            });
// should probably be
        var task = Task.Factory.StartNew(async () =>
        {
            return await new WebClient().DownloadStringTaskAsync(
                "http://example.com"
            );
        });

belav avatar May 29 '21 23:05 belav

This got mostly resolved, so the only part left is to clean up the indentation.

belav avatar May 31 '21 15:05 belav

You think something like this might look better? To make it clear that the braces aren't for the outer level statement, but rather the lambda being passed in?

        var task = Task.Factory.StartNew(async () =>
            {
                return await new WebClient().DownloadStringTaskAsync(
                    "http://example.com"
                );
            }
        );

shocklateboy92 avatar Jun 01 '21 06:06 shocklateboy92

It actually formats really close to that now

        var task = Task.Factory.StartNew(
            async () =>
            {
                return await new WebClient().DownloadStringTaskAsync(
                    "http://example.comddddddddddddddddddd"
                );
            }
        );

Prettier formats it like this

var task = Task.Factory.StartNew(async () => {
    return await new WebClient().DownloadStringTaskAsync(
        "http://example.comddddddddddddddddddd"
    );
});

But I don't think we want to have the brace on the same line as =>

We could maybe move the ) up, which would be this, but I don't think I love that.

        var task = Task.Factory.StartNew(async () =>
            {
                return await new WebClient().DownloadStringTaskAsync(
                    "http://example.com"
                );
            });

Which leaves us with doing what you said

        var task = Task.Factory.StartNew(async () =>
            {
                return await new WebClient().DownloadStringTaskAsync(
                    "http://example.com"
                );
            }
        );

// however if there are multiple parameters

        var task = Task.Factory.StartNew(
            async () => 
            {
                return await new WebClient().DownloadStringTaskAsync(
                    "http://example.com"
                );
            },
            someOtherParameter
        );

belav avatar Jul 19 '21 16:07 belav