belav / csharpier

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

Improve printing for lambda arguments #672

Open belav opened 2 years ago

belav commented 2 years ago

There are improvements that could be made to printing arguments, namely with lambdas as parameters. #669 stuck to just improving some simple cases (single arguments or parenthesized lambdas with no arguments). Prettier has more complicated logic that we should look into.

A simple lambda with too long of an argument name + a block doesn't break when it should. Simple lambdas with no block. Parenthesized lambdas with no block. Parenthesized lambdas with arguments.

belav commented 1 year ago

Some examples


            builder.Entity<IdentityUserToken<string>>(b =>
            {
                b.HasKey(
                    l =>
                        new
                        {
                            l.UserId,
                            l.LoginProvider,
                            l.Name
                        }
                );
                b.ToTable("AspNetUserTokens");
            });

                table.PrimaryKey(
                    "PK_AspNetUserTokens",
                    x =>
                        new
                        {
                            x.UserId,
                            x.LoginProvider,
                            x.Name
                        }
                );
belav commented 1 year ago

this may be more because of breaking with the new { } stuff that came from #755


builder.Entity<EntityWithThreeProperties>(e =>
                {
                    e.HasIndex(
                        t =>
                            new
                            {
                                t.X,
                                t.Y,
                                t.Z
                            },
                        "IX_unspecified"
                    );
                    e.HasIndex(
                            t =>
                                new
                                {
                                    t.X,
                                    t.Y,
                                    t.Z
                                },
                            "IX_empty"
                        )
                        .IsDescending();
                    e.HasIndex(
                            t =>
                                new
                                {
                                    t.X,
                                    t.Y,
                                    t.Z
                                },
                            "IX_all_ascending"
                        )
                        .IsDescending(false, false, false);
                    e.HasIndex(
                            t =>
                                new
                                {
                                    t.X,
                                    t.Y,
                                    t.Z
                                },
                            "IX_all_descending"
                        )
                        .IsDescending(true, true, true);
                    e.HasIndex(
                            t =>
                                new
                                {
                                    t.X,
                                    t.Y,
                                    t.Z
                                },
                            "IX_mixed"
                        )
                        .IsDescending(false, true, false);
                });
belav commented 1 year ago
class ClassName
{
    void MethodName()
    {
        var searchRequest = new SearchDescriptor<ElasticsearchProduct>().WithAggregations(
            o =>
                o.WithFilter(
                    key,
                    f =>
                        f.WithFilter(fd => filter)
                            .WithAggregations(
                                ad =>
                                    ad.WithTerm(
                                        key,
                                        cd =>
                                            cd.WithField(facetField).WithSize(MaximumCategoryFacets)
                                    )
                            )
                )
        );
    }
}
aradalvand commented 4 months ago

This keeps getting postponed... :(