prettier / prettier/plugin-php

Comments in attributes (e.g. for an array item) are weirdly moved to somewhere completely else

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

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

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

説明

Various comments inside attributes are moved to really weird places instead of staying where they were.
The example below is not the only one where something like this happens. There are a few other scenarios like e..g for a parameter etc.

Prettier 2.88.0 (but also tried the latest)

PHP Plugin 0.19.6 (but also tried the latest)

# Options (if any):
--no-options

Input:

<?php declare(strict_types=1);

namespace App\Controller\General;

use App\Dto\BarDto;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class EnrollmentController extends AbstractController
{
    #[Route(path: '/foo', name: 'app.foo', methods: [
        Request::METHOD_GET, // GET is required for third party app.
        Request::METHOD_POST,
    ])]
    public function save(): Response
    {
        return $this->json(['foo']);
    }
}

Output:

<?php declare(strict_types=1);

namespace App\Controller\General;

use App\Dto\BarDto;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class EnrollmentController extends AbstractController // GET is required for third party app.
{
    #[Route(path: '/foo', name: 'app.foo', methods: [Request::METHOD_GET, Request::METHOD_POST])]
    public function save(): Response
    {
        return $this->json(['foo']);
    }
}

Expected behavior:

Output should keep the comment where it was. IT definitely should not be moved to the class:

<?php declare(strict_types=1);

namespace App\Controller\General;

use App\Dto\BarDto;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class EnrollmentController extends AbstractController
{
    #[Route(path: '/foo', name: 'app.foo', methods: [
          Request::METHOD_GET, // GET is required for third party app.
          Request::METHOD_POST
    ])]
    public function save(): Response
    {
        return $this->json(['foo']);
    }
}

This seems to be the case for quite some time as even the old version on the playground shows the issue: Link to playground

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

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

はじめの一歩

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

調査の方向性

Issue に記載された PHP の入力と期待される出力、またはリンク先の playground を使用して formatter の動作を再現し、属性配列やその他のパラメータ内のコメントに重点を置いてください。配列項目の横にあるコメントがクラス宣言へ移動されず、そこに保持されるようにフォーマットされれば完了です。レポートではリポジトリのファイルやテストを指定しません。

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

評価

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

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

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