Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Splitting of long lines with closures and imported use variables

未關閉
#1,613 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
45/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
php
領域
tooling

研究方向

這個 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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

prettier/plugin-php 的其他 Issue

查看 prettier/plugin-php 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。