Commit 749fdd5
committed
Indent the line after a `=>' left at the end of a line
An arrow function whose body starts on the next line fell back to
column zero:
$f = fn($x) =>
$x + 1;
`=>' is deliberately excluded from php-indent--indent-operator-re --- in
PHP it is overwhelmingly the array key operator, and treating every
`'key' => 'value'' as a continuation would be wrong --- so nothing at
all picked up a trailing one, and the body was indented as if it began
a fresh statement.
Property hooks showed the same gap, and worse, an inconsistent one: the
first line after `get =>' stayed put while a following `.' line was
indented by php-indent--statement-continuation-indentation, which does
fire after an identifier:
get =>
$this->a
. ' ';
Treat a trailing `=>' as leaving the statement open, alongside the
identifier / `)' / `):' cases already there. The three shapes now
agree:
$f = fn($x) =>
$x + 1;
$config = [
'key' =>
'a value long enough to wrap',
];
get =>
$this->a
. ' ';
Only `=>' is matched, so `>=', `->' and `<=>' keep the handling they
had. The shape had no fixture at all, which is why the gap went
unnoticed; tests/indent/trailing-arrow.php now covers arrow functions,
array values, the bracket-on-the-same-line case, property hooks, match
arms, and a `>=' left at the end of a line.1 parent c8c5b04 commit 749fdd5
3 files changed
Lines changed: 75 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
468 | | - | |
469 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
470 | 471 | | |
471 | 472 | | |
472 | 473 | | |
| |||
480 | 481 | | |
481 | 482 | | |
482 | 483 | | |
483 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
484 | 493 | | |
485 | 494 | | |
486 | 495 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
660 | 660 | | |
661 | 661 | | |
662 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
663 | 671 | | |
664 | 672 | | |
665 | 673 | | |
| |||
0 commit comments