Splitting of long lines with closures and imported use variables
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
這個 issue 沒有指出來源檔案或測試。先在連結的 plugin playground 中重現提供的 PHP 輸入,然後找出處理 closure 參數和 use 變數的 formatter 邏輯;完成的標準是,格式化後的輸出在偏好的版面配置中將 use 變數與函式引數保留在一起。
由索引模型根據 Issue 內容生成。
描述
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);
},
);
}
- 主要語言
- PHP
- 星號
- 1.9k
- 分支
- 139
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
prettier/plugin-php 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 62/100
prettier/plugin-php#2416 · 2 則留言 · 6 個 reaction ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 64/100
prettier/plugin-php#2498 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 55/100
prettier/plugin-php#2495 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 55/100
prettier/plugin-php#2494 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 48/100
prettier/plugin-php#2490 ·
維護者通常 1 天內回覆
查看 prettier/plugin-php 的全部 Issue
相似的 Issue
-
sync-en
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 2 天內回覆
-
UX
難度 2/5 1-3 小時 新手友好度 72/100
ProfessionalWiki/NeoWiki#1573 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 68/100