prettier / prettier/plugin-php
Comments in attributes (e.g. for an array item) are weirdly moved to somewhere completely else
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- PHP
- Estrellas
- 1.9k
- Forks
- 139
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el comportamiento del formateador usando la entrada y la salida esperada de PHP del issue, o el playground enlazado, centrándote en los comentarios dentro de arrays de atributos y otros parámetros. Se considera terminado cuando el formateo conserva el comentario junto al elemento del array en lugar de moverlo a la declaración de la clase; en el informe no se menciona ningún archivo ni prueba del repositorio.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- php
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100