prettier / prettier/plugin-php

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

Aperta
#2,282 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
PHP
Stelle
1.9k
Fork
139
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il comportamento del formatter usando l’input PHP e l’output previsto nell’issue, oppure il playground collegato, concentrandoti sui commenti all’interno degli array di attributi e di altri parametri. Il lavoro è completato quando la formattazione conserva il commento accanto all’elemento dell’array invece di spostarlo nella dichiarazione della classe; nel report non viene indicato alcun file o test del repository.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
php
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.