prettier-plugin-multiline-arrays
prettier-plugin-multiline-arrays copied to clipboard
Support wrapping in parameter lists
Is it going to support function parameters and arguments?
function greet(
param0,
param1,
param2,
) {}
greet(
'arg 0',
'arg 1',
'arg 2',
);
Originally posted by @monim67 in https://github.com/electrovir/prettier-plugin-multiline-arrays/issues/4#issuecomment-1060837141
that would be amazing
the way prettier collapses function arguments is currently preventing me from adopting it at work
I'd be willing to work on it with a little bit of guidance from the author. Seems like most of the logic should be already in place in this plugin, what do you think @electrovir?
I actually have a branch where this is being worked on, but I haven't given it any attention for a while. Just made some great progress after giving it some more time (after seeing your interest @adrian-gierakowski). Give me a few days and I should be able to get this going! 😁
@electrovir amazing, thanks!
@adrian-gierakowski I've added and released experimental support for this feature in v1.1.0. You can enable it by setting multilineFunctionArguments to true in your prettier config.
It currently doesn't work on all use cases (for example, in const stuff = process.argv.some((arg2, index3) => arg1);, arg2 and index3 won't wrap) and for some reason actual behavior in other code bases does not match the behavior I'm seeing in this repo's test files (specifically, in other code base function calls with just one argument will wrap but in tests they don't, even if the wrap threshold is not modified).
@adrian-gierakowski feel free to poke around and fix these issues if you like, the code in question is in src/printer/insert-new-lines-into-arguments.ts (warning: it's not very pretty code). I'll try to address these issues at some point in the future.
Thank you for responding to my request so quickly @electrovir. We gave the new feature a spin at work, but unfortunately ran into many cases where function calls (with single argument) where unnecessarily split into multiple lines. Ideally we’d like the functions which are already on single line to remain so (as long as the line doesn’t exceed printWidth). If that’s not possible then at least it would be good to have an equivalent of multilineArraysWrapThreshold for function calls. Thanks again for your great work!
Yeah... it's not very good yet, sorry 😕. At the moment I don't have the time to address this further.