prettier / prettier/plugin-php

Splitting of long lines with closures and imported use variables

オープン
#1,613 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
PHP
スター
1.9k
フォーク
139
PR マージ指標
30日以内にマージされた PR はありません

説明

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);
        },
    );
}

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue にはソースファイルやテストの記載がありません。まず、リンクされた plugin playground で提供された PHP 入力を再現し、次に closure パラメーターと use 変数を処理する formatter ロジックを見つけてください。整形後の出力で、推奨レイアウトにおいて use 変数が関数の引数とともに維持されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
tooling
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。