prettier / prettier/plugin-php

Wrong indentation in match statements with multiple options

Open
#2,435 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
1.9k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground reproduction and compare the reported input and output for the match statement with multiple options and its nested array. Trace the formatter behavior responsible for line breaks and indentation, then verify that array entries are indented beyond their opening brace and that the closing brace aligns with it without disturbing the surrounding match formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.