prettier / prettier/plugin-php
Prettier duplicates a comment and inserts it somewhere else
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
@prettier/plugin-php v0.25.0
Playground link
Input:
<?php if (have_posts()): ?>
<p>Content if have posts</p>
<?php
/* My comment */
?>
<?php
// Comment in else
// Another comment
// Comment number three
else: ?>
<?php if (true): ?>
<p>This is always true</p>
<?php endif;
// end true check
?>
<?php endif;
// end have_posts() check
?>
Output:
<?php if (have_posts()): ?>
<p>Content if have posts</p>
<?php
/* My comment */
?>
<?php
// Comment in else
// Another comment
// Comment number three
// end true check
else: ?>
<?php if (true): ?>
<p>This is always true</p>
<?php endif;
// end true check
?>
<?php endif;
// end have_posts() check
?>
Notice that the //end true check comment is inserted next to the comments near the else statement.
However, a weirder things happen when I delete the entire /* My comment */ PHP block:
@prettier/plugin-php v0.25.0
Playground link
Input:
<?php if (have_posts()): ?>
<p>Content if have posts</p>
<?php
// Comment in else
// Another comment
// Comment number three
else: ?>
<?php if (true): ?>
<p>This is always true</p>
<?php endif;
// end true check
?>
<?php endif;
// end have_posts() check
?>
Output:
<?php if (have_posts()): ?>
<p>Content if have posts</p>
<?php
// Comment in else
// Another comment
// Comment number three
// end true check
// Comment in else
// Another comment
// Comment number three
// end true check
else: ?>
<?php if (true): ?>
<p>This is always true</p>
<?php endif;
// end true check
?>
<?php endif;
// end have_posts() check
?>
Multiple comments get duplicated
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue from the supplied Playground links and compare the formatter output with the input, especially around the PHP comments near else and endif. Trace the plugin-php comment-handling path; done means comments are neither duplicated nor moved when the surrounding PHP block is present or removed.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100