prettier / prettier/plugin-php

Space before conditional changes closing block

Open
#1,818 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

Having any text characters before the opening <?php causes the closing <?php endif; ?> block to wrap.

@prettier/plugin-php v0.17.4
Playground link

Input:


<?php
$a = 1;
if (true): ?>

text

<?php endif; ?>

Output:


<?php
$a = 1;
if (true): ?>

text

<?php endif;
 ?>

Expected


<?php
$a = 1;
if (true): ?>

text

<?php endif; ?>

As a workaround, putting the opening conditional into it's own block causes the closing block to wrap correctly:


<?php
$a = 1;
?>
<?php if (true): ?>

text

<?php endif; ?>

formats to


<?php $a = 1; ?>
<?php if (true): ?>

text

<?php endif; ?>

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 formatter behavior from the linked Playground using the provided PHP input and compare it with the expected output. Trace the plugin's handling of conditional closing blocks when text precedes the opening PHP tag; done means the closing <?php endif; ?> remains on one line and the workaround still formats as shown.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.