prettier / prettier/plugin-php
Splitting of long lines with closures and imported use variables
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- PHP
- Star
- 1.9k
- Fork
- 139
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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);
},
);
}
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Issue không nêu tệp mã nguồn hoặc kiểm thử nào. Hãy bắt đầu bằng cách tái hiện đầu vào PHP được cung cấp trong plugin playground được liên kết, sau đó tìm logic formatter cho các tham số closure và các biến use; hoàn tất có nghĩa là đầu ra được định dạng giữ các biến use cùng với các đối số hàm trong bố cục ưu tiên.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- tooling
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100