prettier / prettier/plugin-php
Single line conditions
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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