plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Breaks if comments precede an include statement in mixed HTML/PHP files

Open josiahwiebe opened this issue 5 years ago • 2 comments

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(); ?>

josiahwiebe avatar Nov 06 '20 17:11 josiahwiebe

Same here. This is crucial.

vielhuber avatar Mar 04 '21 21:03 vielhuber

I wonder if this is a manifestation of this bug: https://github.com/prettier/plugin-php/issues/1736

sgarrity avatar May 26 '21 22:05 sgarrity