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

Support wrapping in parameter lists #5

Open
electrovir opened this issue Mar 11, 2022 · 7 comments
Open

Support wrapping in parameter lists #5

electrovir opened this issue Mar 11, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@electrovir
Copy link
Owner

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 #4 (comment)

@adrian-gierakowski
Copy link

that would be amazing

the way prettier collapses function arguments is currently preventing me from adopting it at work

@adrian-gierakowski
Copy link

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?

@electrovir
Copy link
Owner Author

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! 😁

@adrian-gierakowski
Copy link

@electrovir amazing, thanks!

@electrovir
Copy link
Owner Author

electrovir commented Jul 4, 2022

@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.

@adrian-gierakowski
Copy link

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!

@electrovir
Copy link
Owner Author

Yeah... it's not very good yet, sorry 😕. At the moment I don't have the time to address this further.

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

No branches or pull requests

2 participants