prettier / prettier/plugin-php
Prettier adds incorrect semicolon with nested foreach, for, try/catch
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
@prettier/plugin-php v0.18.8
Playground link
Input:
<?php
foreach( $x as $y)
foreach ($a as $b) {
$a = $x;
}
foreach ($x as $y)
for ($a = 1; $a < 10; a++) {
$a = $x;
};
if( $foo)
foreach($b as $a)
{
$foo = bar;
}
if($foo)
try {
} catch (Exception $e){
}
Output:
<?php
foreach ($x as $y) {
foreach ($a as $b) {
$a = $x;
};
}
foreach ($x as $y) {
for ($a = 1; $a < 10; a++) {
$a = $x;
};
}
if ($foo) {
foreach ($b as $a) {
$foo = bar;
};
}
if ($foo) {
try {
} catch (Exception $e) {
};
}
I think this shows the issue. The expected output should be the same as the output, without the extra semicolons.
If you run prettier on the same file a second time, it will removed the extra semicolons. I know this affects foreach, for, try/catch, but I'm not sure that is a comprehensive list.
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 linked Playground example and compare the first formatting pass with the second pass. Reproduce the nested foreach, for, try/catch, and related cases, then verify that formatting produces no extra semicolons and remains unchanged when run again.
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