prettier / prettier/plugin-php

Single line conditions

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

Nobody has claimed this yet.

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

Description

When using simple conditions for early returns / guard statements the current formatting is quite verbose:

function test($arg1) {
  if (!$arg) return;

  for ($i = 0; $i < 10; $i++) {
    if ($i % 2 === 0) continue;
    // do something if the number is odd
  }
}

will be converted to:

function test($arg1) {
  if (!$arg) {
    return;
  }

  for ($i = 0; $i < 10; $i++) {
    if ($i % 2 === 0) {
      continue;
    }
    // do something if the number is odd
  }
}

It would be great if these single line conditions would be preserved. Alot of formatters for c-style languages like prettier for javascript or ClangFormat allow this, resulting in much more concise code.

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 PHP examples in the issue and inspect the formatter's handling of single-line early returns, guard statements, and loop controls. Determine how the current block expansion is implemented and identify the relevant existing tests before defining the expected preserved formatting. Done means these single-line conditions remain concise while other formatting behavior is unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.