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

multi-line comment duplicated, leaking outside PHP blocks

Open joemaller opened this issue 6 years ago • 7 comments

The obvious problem is that the multi-line comment is being duplicated and jumping outside the PHP block. But it's weirder, variations are below the main report example.

@prettier/plugin-php v0.11.2 Playground link

Input:

<?php ?>
<?php ?>

<?php
/**
 * comment
 */

$var = 0;
$var = 1;
?>
<?php ?>

Output:


<?php  ?>

 /**
 * comment
 */<?php
/**
 * comment
 */
?>
$var = 0;
$var = 1;
?>

Additional examples (links go to playground variations):

  • Add a blank line between the first two <?php ?> blocks: Works correctly.
  • Remove all blank lines between <?php ?> blocks: Works correctly (mostly, whitespace)
  • Add a single character to the comment (comments): Works correctly (mostly, whitespace)
  • Add two characters to the comment (commentss): Broken

I didn't run into this with empty PHP blocks, here's the are some examples with code in the PHP blocks, behavior appears to be the same:

joemaller avatar Nov 20 '19 14:11 joemaller

Same problem here

davidfilat avatar Dec 23 '19 08:12 davidfilat

Same happened to me. This bug made me disable prettier for my php files. Such a shame :(.

But still loving prettier! Hopefully this gets fixed soon...

reik-stiebeling avatar Jan 30 '20 15:01 reik-stiebeling

Here's another example that's hapenning for me:

<?php /* Template Name: Printable Page */ ?>
<?php
/**
 * The template for displaying printable pages. This is like the default page.php but adds a prominent print button.
 *
 * @package Polyfoaming
 */
get_header();
set_query_var('show-print-button', true);
?>

is changed to

<?php
/* Template Name: Printable Page */
?>
 /**
 * The template for displaying printable pages. This is like the default page.php but adds a prominent print button.
 *
 * @package Polyfoaming
 */<?php
/**
 * The template for displaying printable pages. This is like the default page.php but adds a prominent print button.
 *
 * @package Polyfoaming
 */
?>
get_header();
set_query_var('show-print-button', true);
?>

thewebsitetherapist avatar Jun 11 '20 06:06 thewebsitetherapist

Yep, bug :disappointed:

alexander-akait avatar Jun 11 '20 11:06 alexander-akait

We need to find a way to handle <?php and ?> in parser, it is not easy, so any help welcome

alexander-akait avatar Apr 29 '21 20:04 alexander-akait

We need to find a way to handle <?php and ?> in parser, it is not easy, so any help welcome

@alexander-akait

Wouldn't that be easy using a regex? I don't know what technique you are using.

But a regex can do this pretty easily, if you are using DFA for parsing however you should chnage your way to PDA therefore you'll be able to handle all those pretty easily.

If you are not using any of this I have no idea then.

Stevemoretz avatar May 02 '21 05:05 Stevemoretz

Feeling hopeful about this one, didn't realize it was happening upstream too. https://prettier.io/blog/2021/05/09/2.3.0.html#fix-unstable-multiple-comments-on-the-same-line-9672httpsgithubcomprettierprettierpull9672-by-fiskerhttpsgithubcomfisker

joemaller avatar May 11 '21 14:05 joemaller