-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
Function call wrapping #123
Conversation
|
||
$this->something->method($argument, $this->more->stuff($this->even->more-> | ||
things-> | ||
complicatedMethod())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using a conditionalGroup
to wrap function calls just like the JS printer does - which works generally quite well, but I'm still having issues with this nested call example. I think it should be formatted like this:
$this->something->method($argument, $this->more->stuff(
$this->even->more->things->complicatedMethod()
));
Maybe @azz can point me in the right direction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@czosel do you know where the JS printer does this? I'm mostly just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS actually just does the long form in that example. I'm beginning to wonder if we're actually going to be able to print everything in the way PSR12 outlines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still some cases to work through, but this looks sooo much better
@@ -108,6 +116,30 @@ function printLines(path, options, print) { | |||
return join(hardline, printed); | |||
} | |||
|
|||
function printArgumentsList(path, options, print) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind just adding a comment outlining the overall strategy here?
|
||
$this->something->method($argument, $this->more->stuff($this->even->more-> | ||
things-> | ||
complicatedMethod())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS actually just does the long form in that example. I'm beginning to wonder if we're actually going to be able to print everything in the way PSR12 outlines
Removing |
@mgrip @evilebottnawi I think this is ready for review now 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 👍
This is great! Nice work @czosel 💯 |
Hi! Sorry to be leaving a comment on such an old PR, but I started using this plugin today, and noticed the following format being rendered by Prettier: array_map(function ($entry) {
return $entry * 2;
}, $arr); Through the snapshots I was able to find PR #23, in which a change is pushed that changes the above to this: array_map(
function ($entry) {
return $entry * 2;
},
$arr
); However, about a month after that PR @czosel, the author of both PRs, pushes the changes in this PR reverting that beautiful format to the old. I'm wondering: is this deliberate? If not, would you accept a PR that changes the format to that in the second snippet. |
Hi @harmenjanssen! I think this was not deliberate. In #23 we optimized the printing of long function call expressions, but made the printing of expressions like the one you posted above a little worse, which was an acceptable trade-off at the time. If you find a clever way to optimize the example above that also works for long call expressions, I'd be happy to merge your PR 👍 |
No description provided.