Skip to content

Formatting twice changes result of mathematical expression #1421

Description

@sgruetter

@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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions