Comments in match statement throw error
@prettier/plugin-php v0.18.3 Playground link
Input:
<?php
function fizzbuzz(int $i)
{
print match (0) {
/* this is a comment */
$i % 15 => "fizzbuzz",
$i % 3 => "fizz",
$i % 5 => "buzz",
default => $i,
} . PHP_EOL;
}
Output:
Comment "/* this is a comment */" was not printed. Please report this error!
Of note, it doesn't matter what kind of comment, or where the comment is (end of line, before/after a pattern, etc.). Every scenario throws an exception.
Yep, can confirm the same from my side.
Yep, same here
While not ideal, I addressed this in the meantime by moving the comment to either before the entire statement or after one of the arrows:
<?php
function fizzbuzz(int $i)
{
/* this is a comment */
print match (0) {
$i % 15 => "fizzbuzz",
$i % 3 => "fizz",
$i % 5 => /* this is another comment */ "buzz",
default => $i,
} . PHP_EOL;
}
That way Prettier won't fail on statements like these and you can still keep the comment fairly close to the desired statement.
Fixed in v0.19.7 :tada: