prettier / prettier/plugin-php
Comments in attributes (e.g. for an array item) are weirdly moved to somewhere completely else
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- PHP
- Star
- 1.9k
- Fork
- 139
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện hành vi của formatter bằng cách sử dụng input PHP và output mong đợi trong issue, hoặc playground được liên kết, tập trung vào các comment bên trong các attribute array và các parameter khác. Được xem là hoàn thành khi việc format giữ comment bên cạnh phần tử array thay vì chuyển nó vào phần khai báo class; báo cáo không nêu tên file hay test nào trong repository.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100