prettier / prettier/plugin-php
Splitting of long lines with closures and imported use variables
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
The way closure imports ("use" variables) are split when a line is too long is not ideal. I'm wondering if there is a way the priority can be changed so that it prefers to keep use variables together with the function arguments?
@prettier/plugin-php v0.16.1
Playground link
Input:
<?php
function test()
{
expectNotification(VerifyEmail::class)->toBeSentTo(
$user,
function ($notification, $channels, $notifiable) use ($user, &$actionUrl) {
$actionUrl = $notification->toMail($user)->actionUrl;
return $channels === ['mail'] && $notifiable->is($user);
},
);
}
Output:
<?php
function test()
{
expectNotification(VerifyEmail::class)->toBeSentTo($user, function ($notification, $channels, $notifiable) use (
$user,
&$actionUrl
) {
$actionUrl = $notification->toMail($user)->actionUrl;
return $channels === ['mail'] && $notifiable->is($user);
});
}
Of course Javascript doesn't have an equivalent of "use" imports, but I tried to approximate it below, and Prettier does what I would expect/prefer.
Prettier 2.2.1
Playground link
--parser babel
--print-width 120
--single-quote
--tab-width 4
--trailing-comma all
Input:
function test()
{
expectNotification(VerifyEmail.name).toBeSentTo(
$user,
function ($notification, $channels, $notifiable, use, $user, A$actionUrl) {
$actionUrl = $notification.toMail($user).actionUrl;
return $channels === ['mail'] && $notifiable.is($user);
},
);
}
Output:
function test() {
expectNotification(VerifyEmail.name).toBeSentTo(
$user,
function ($notification, $channels, $notifiable, use, $user, A$actionUrl) {
$actionUrl = $notification.toMail($user).actionUrl;
return $channels === ['mail'] && $notifiable.is($user);
},
);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source files or tests. Start by reproducing the supplied PHP input in the linked plugin playground, then locate the formatter logic for closure parameters and use variables; done means the formatted output keeps the use variables with the function arguments in the preferred layout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100