Skip to content

PHP 8.1 - match is formatted into one line if the whole block is short enough - which is weird #1964

Description

@AndreasA

If the used match with not a lot of content, it is formatted as one line which is really tricky to read.

Prettier 2.6.2

PHP Plugin 0.18.4

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

Input:

<?php declare(strict_types=1);

match ($case) { 
     'foo' => ['bar'], 
     'cd' => [],
     default => [],
};

Output:

<?php declare(strict_types=1);

match ($case) { 'foo' => ['bar'],  'cd' => [],  default => [] };

Expected behavior:

To be formatted as it was with input, to put each "case" in a new line.

Playground sample

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions