prettier / prettier/plugin-php

Format multiple-catch

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

Nobody has claimed this yet.

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

Description

We're currently not respecting line length limitations in multiple-catch blocks, which we could.


@prettier/plugin-php v0.14.0
Playground link

Input:

<?php

try {
    do_something();
} catch (\Some\Rather\Obscure\Exception | \Another\Obscure\Exception $exception) {
    handle_exception();
}

Current Output:

<?php

try {
    do_something();
} catch (\Some\Rather\Obscure\Exception | \Another\Obscure\Exception $exception) {
    handle_exception();
}

Improved Output:

<?php

try {
    do_something();
} catch (
    \Some\Rather\Obscure\Exception |
    \Another\Obscure\Exception $exception
) {
    handle_exception();
}


To be honest, the improved output is not perfect (the $exception variable is a little bit "obscured" next to the exception class), but it's better than the current behavior IMO.

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 provided Playground reproduction and search the PHP printer for multiple-catch formatting; no file or test is named in the issue. Done means the exception list wraps to respect the configured line length while preserving the shown catch-block structure, with the relevant formatter tests passing.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.