prettier / prettier/plugin-php

Issue in conditions followed by comments

Open
#2,380 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

I have such code:

<p>
<?php
    if ($article['shop']['id'] === 10) { // TestShop
?>
        <img alt="" src="test.png">
<?php
    }
    $this->load();
?>
</p>

and it's formatted to:

<p>
<?php
if ($article["shop"]["id"] === 10) {<?php
    // TestShop
    ?>
        <img alt="" src="test.png">
<?php }
$this->load();
?>
</p>

so - an invalid <?php is added

See https://loilo.github.io/prettier-php-playground/#N4IgDgTgpgLjCWUIHkwIPYDsDOIBcok8mMA6vACYwAW+AHAAwA0IMAhgEblW14AsLAK7YoAFU648AMzYAbES2zEA5rKgBFQehhR8M+VBZhqYAGpIlWfCADsAOj4gWMCG3iyVAYXQBbH2wAFAAkA-BdBQxAOVwBjKABlGABPNWswJABaGNwWaABHQXhoANdlfz05BRBiEQgYErYytgqDAF8WKAp4GHQUNHgsSVA2bBgWkXbqzDBBMbwQAB4wAD4AHUwFgH5jMHWAAgO9+Ck9gAoAEjY6+Bi1AG0AcmxqdDAHgF1Hyg+9gF5-vYARgYAEo9sA9gB6SF7URQUbxF67TCbNaYQ4YvYLeA+ZR7OQwX6rEDEvbYCAxImseEwOxgTDKYlorY7faHVpsg7nGjwbAZZaydBsCinEEAbnWqPWC0hKxArSAA

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 with the minimal PHP/HTML reproduction in the issue and compare its output using the linked Prettier PHP playground. Trace how a comment after a conditional opening brace is handled during formatting. Done means the formatter no longer inserts an invalid <?php tag and produces valid PHP/HTML output for this case.

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.