prettier / prettier/plugin-php
Breaks if comments precede an include statement in mixed HTML/PHP files
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
When running the plugin on a Wordpress template file with some commented lines, behaviour is not as expected.
In this example, the comment line (line 22 in the playground) // $feed_section_class = 'has-top-padding grey-bg'; somehow is duplicated and the closing ?> is inserted prematurely.
@prettier/plugin-php v0.15.2
Playground link
Input:
<?php
/*
Template Name: File
*/
get_header(); ?>
<?php
$home_url = home_url();
$theme_path = get_template_directory_uri();
?>
<main>
<?php include locate_template('content-product-secondary-nav.php'); ?>
<section>
<h1>Title</h1>
<p>Some content here</p>
</section>
<?php // $feed_section_class = 'has-top-padding grey-bg';
// include( locate_template( 'content-brilliance-feeds.php' ) );
include locate_template('content-sub-footer.php'); ?>
</main>
<?php get_template_part('content', 'brochure-popup'); ?>
<?php get_template_part('content', 'quote-popup'); ?>
<?php get_footer(); ?>
Output:
<?php
/*
Template Name: File
*/
get_header(); ?>
<?php
$home_url = home_url();
$theme_path = get_template_directory_uri();
?>
<main>
<?php include locate_template('content-product-secondary-nav.php'); ?>
<section>
<h1>Title</h1>
<p>Some content here</p>
</section>
<?php // $feed_section_class = 'has-top-padding grey-bg';
// $feed_section_class = 'has-top-padding grey-bg';
?>// include( locate_template( 'content-brilliance-feeds.php' ) );
include locate_template('content-sub-footer.php'); ?>
</main>
<?php get_template_part('content', 'brochure-popup'); ?>
<?php get_template_part('content', 'quote-popup'); ?>
<?php get_footer(); ?>
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
Reproduce the input in the linked Prettier PHP playground and compare it with the reported output, focusing on comments before include statements in mixed HTML/PHP templates. Trace the formatter entry point for this playground case; done means the comment is not duplicated, the closing PHP delimiter is not inserted prematurely, and the include remains correctly formatted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100