prettier / prettier/plugin-php

Some comment positions inside attributes can result in prettier failing with an exception

Open
#2,283 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.9k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

Not sure which cases these include exactly but some cases result in pretter stopping with an error:

Error: Comment "// abc" was not printed. Please report this error!

I know that i was also able to produce that error with other positions, but various other work fine so it is a bit weird.

Playground also shows it: Link to playground

Prettier 2.88.0 (but also tried latest)

PHP Plugin 0.19.6 (but also tried 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\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;

class EnrollmentController extends AbstractController
{
    public function save(
        #[
            MapRequestPayload(
                serializationContext: [ // abc
                    AbstractNormalizer::CALLBACKS => [
                        'abc' => 'trim',
                    ],
                ],
            ),
        ]
        BarDto $data,
    ): Response {
        return $this->json(['foo']);
    }
}

Output:

None. Errror as mentioned above.

Expected behavior:
No error and correctly formatted.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the exception with the provided PHP input in the linked playground or the latest plugin version, then trace the PHP plugin's comment handling for comments inside attributes. Done means the input formats successfully and preserves the comment without the “Comment was not printed” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.