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

Wrong indentation in match statements with multiple options

Open Triqueon opened this issue 6 months ago • 1 comments

@prettier/plugin-php v0.22.4 Playground link

Input:

<?php

echo match ($operation) {
      "short", "really very long option 2" => SomeClass::fairlyLongMethodNameThatRunsOn($variable, ["short", "short"]),
}

Output:

<?php

echo match ($operation) {
    "short",
    "really very long option 2"
        => SomeClass::fairlyLongMethodNameThatRunsOn($variable, [
        "short",
        "short",
    ]),
};

As you can see, the indentation in the output is off. There's arguments for each individual line being ok, but at the very least, the array entries should by indented one more than their braces (now: same as opening, 1 more than closing), and the closing brace for the array should be indented as much as the line with the opening brace.

As far as I can tell, the length of the individual parts is irrelevant, only that they are in total long enough for a line break to be forced.

Triqueon avatar Jul 09 '25 13:07 Triqueon

Thanks for the bug report @Triqueon! PRs welcome.

czosel avatar Jul 09 '25 14:07 czosel