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

Code doesn't work after formatting

Open mozesa opened this issue 2 years ago • 1 comments

Prettier 2.0.0

PHP Plugin 0.18.4

"prettier": {
  "phpVersion": "8.0",
  "useTabs": true,
  "singleQuote": true
}

Input:

$measurement  = (fn($m): Measurement => $m)(Measurement::query()->find($id, ['time', 'raw_gyro']));

image

Output:

$measurement = fn($m): Measurement => $m(
	Measurement::query()->find($id, ['time', 'raw_gyro']),
);

image

Expected behavior: Won't broke the code.

mozesa avatar Mar 30 '22 07:03 mozesa

Yes, it appears the closure is being unwrapped at some point.

Simpler example

$a = (fn() => 0)(1);

becomes

$a = fn() => 0(1);

This could be a bug in the PHP parser that is used by us

cseufert avatar Jun 03 '22 01:06 cseufert

Seeing this bug as well

{
    "phpVersion": "8.1",
    "printWidth": 80,
    "tabWidth": 4,
    "useTabs": false,
    "singleQuote": false,
    "trailingCommaPHP": true,
    "braceStyle": "psr-2",
    "requirePragma": false,
    "insertPragma": false
}

snake-py avatar Sep 08 '22 12:09 snake-py

Released in 0.19.1 :tada:

czosel avatar Sep 13 '22 16:09 czosel