prettier / prettier/plugin-php

Splitting of long lines with closures and imported use variables

Offen
#1,613 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
PHP
Sterne
1.9k
Forks
139
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue nennt keine Quelldateien oder Tests. Beginne damit, die bereitgestellte PHP-Eingabe im verknüpften Plugin-Playground zu reproduzieren, und finde dann die Formatter-Logik für Closure-Parameter und use-Variablen; abgeschlossen ist die Aufgabe, wenn die formatierte Ausgabe die use-Variablen im bevorzugten Layout bei den Funktionsargumenten belässt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.