prettier / prettier/plugin-php

multi-line comment duplicated, leaking outside PHP blocks

Open
#1,228 7 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The obvious problem is that the multi-line comment is being duplicated and jumping outside the PHP block. But it's weirder, variations are below the main report example.

@prettier/plugin-php v0.11.2
Playground link

Input:

<?php ?>
<?php ?>

<?php
/**
 * comment
 */

$var = 0;
$var = 1;
?>
<?php ?>

Output:


<?php  ?>

 /**
 * comment
 */<?php
/**
 * comment
 */
?>
$var = 0;
$var = 1;
?>

Additional examples (links go to playground variations):

  • Add a blank line between the first two <?php ?> blocks: Works correctly.
  • Remove all blank lines between <?php ?> blocks: Works correctly (mostly, whitespace)
  • Add a single character to the comment (comments): Works correctly (mostly, whitespace)
  • Add two characters to the comment (commentss): Broken

I didn't run into this with empty PHP blocks, here's the are some examples with code in the PHP blocks, behavior appears to be the same:

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

Start by reproducing the reported multi-line comment duplication with the linked Playground example, then compare the listed variations involving blank lines, comment length, and code blocks. Trace the PHP formatting path responsible for comments and PHP block boundaries. Done means the comment is emitted once and remains inside the PHP block across the reported cases.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.