Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParenthesizedLambdaExpressions needs some work. #238

Open
belav opened this issue May 29, 2021 · 3 comments
Open

ParenthesizedLambdaExpressions needs some work. #238

belav opened this issue May 29, 2021 · 3 comments
Labels

Comments

@belav
Copy link
Owner

belav commented May 29, 2021

        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
Copy link
Owner Author

belav commented May 31, 2021

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

@shocklateboy92
Copy link
Collaborator

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"
                );
            }
        );

@belav
Copy link
Owner Author

belav commented Jul 19, 2021

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
        );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants