@prettier/plugin-php v0.14.0
Playground link
Input:
<?php
// The first time formatted the braces are removed (fine).
$number = 5;
$result = (2 ** $number) - 1;
// When taking the result form the first formatting and pasting it,
// Prettier adds braces in the wrong place, changing the result (bad).
$number = 5;
$result = 2 ** $number - 1;
Output:
<?php
// The first time formatted the braces are removed (fine).
$number = 5;
$result = 2 ** $number - 1;
// When taking the result form the first formatting and pasting it,
// Prettier adds braces in the wrong place, changing the result (bad).
$number = 5;
$result = 2 ** ($number - 1);
As written in the comments above, Prettier changes the result when formatting an initial piece of code twice or more times.
Adding // prettier-ignore a line before works temporarily if (!) the change is noticed.
As this issue might have very serious implications, a quick fix would be appreciated highly.
If you need some more information or if I can be of assistance, please let me know.
Thanks for the bug report!
No problem, thanks for Prettier for PHP :-)
I took a closer look - this turns out to be an issue with operator precedence in the parser.
We just released v0.14.2 which fixes this :tada:
Awesome, it works like a charm. Thanks a lot @czosel!