Comment of last argument gets replaced
The comment of the last argument gets replaced. This also applies to /* block comments */.
@prettier/plugin-php v0.16.3 Playground link
Input:
<?php
class MyClass {
public static function from(
int $value1, // comment works
int $value2 // comment gets moved down
) {
}
}
Output:
<?php
class MyClass
{
public static function from(
int $value1, // comment works
int $value2
) {
// comment gets moved down
}
}
Thanks for the bug report @sgruetter!
My attempt at a fix for this is in #1764
@cseufert this still seems to be an issue even with #1764 merged.
@czosel Hrmm looks like the parser is doing kinda weird things parsing these.
Looks to me like the trailing comment is not being picked up on the first line correctly in the first place. I suspect it will be quite a breaking change to the parser behaviour, I am not very confident in how the whole comments parsing and handling is done.
Parameter {
"attrGroups": Array [],
"byref": false,
"flags": 0,
"kind": "parameter",
"name": Identifier {
"kind": "identifier",
"name": "value1",
},
"nullable": false,
"type": TypeReference {
"kind": "typereference",
"name": "int",
"raw": "int",
},
"value": null,
"variadic": false,
},
Parameter {
"attrGroups": Array [],
"byref": false,
"flags": 0,
"kind": "parameter",
"leadingComments": Array [
CommentLine {
"kind": "commentline",
"offset": 37,
"value": "// comment 1
",
},
],
"name": Identifier {
"kind": "identifier",
"name": "value2",
},
"nullable": false,
"trailingComments": Array [
CommentLine {
"kind": "commentline",
"offset": 66,
"value": "// comment 2
",
},
],
"type": TypeReference {
"kind": "typereference",
"name": "int",
"raw": "int",
},
"value": null,
"variadic": false,
},
],
That was parsing
function from(
int $value1, // comment 1
int $value2 // comment 2
) { ]