csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Single collection as method parameter

Open jods4 opened this issue 1 year ago • 4 comments

As formatted by 0.27 in playground

Input:

var dummy = new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers([
        new FirstDestructurer(),
        new SecondDestructurer(),
        new ThirdDestructurer(),
        new FourthDestructurer(),
    ]);

Output:

var dummy = new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(
        [
            new FirstDestructurer(),
            new SecondDestructurer(),
            new ThirdDestructurer(),
            new FourthDestructurer(),
        ]
    );

Expected behavior: Input seems better to me when there's only a single parameter that is a collection. Using two lines for single characters [ and ], and increasing indentation, doesn't seem beneficial in this situation.

I note that this is somewhat similar to the idea that for a single lambda parameter x => ..., it's nicer to keep Method(x => rather than putting x => on a line of its own.

jods4 avatar Jan 18 '24 14:01 jods4

Prettier also formats this way

      await Promise.all([
        queryClient.invalidateQueries(getDoctorProfileInfoQueryKey()),
        queryClient.invalidateQueries(getStudyListQueryKey()),
      ]);

Rudomitori avatar Jan 19 '24 08:01 Rudomitori

When you type such parameters you more likely get code that looks as in the input sample. At least, In Rider it's so

Rudomitori avatar Jan 19 '24 08:01 Rudomitori

Thoughts on applying this to attributes as well? They are constructors, so should probably work the same way.

[AllowedExtensions(
    [
        ".txt",
        ".pdf",
        ".doc",
        ".jpeg",
        ".jpg",
        ".zip",
        ".7z",
        ".png",
        ".xlsx",
        ".xlx",
        ".docx",
        ".csv"
    ]
)]
async Task<FormResultDto> PatchResults(){}
[AllowedExtensions([
    ".txt",
    ".pdf",
    ".doc",
    ".jpeg",
    ".jpg",
    ".zip",
    ".7z",
    ".png",
    ".xlsx",
    ".xlx",
    ".docx",
    ".csv"
])]
async Task<FormResultDto> PatchResults(){}

belav avatar Jan 31 '24 18:01 belav

@belav If there's a single argument (be mindful of named properties in attributes!) then I prefer the latter.

jods4 avatar Jan 31 '24 20:01 jods4