Describe the bug
The Generic.ControlStructures.InlineControlStructure sniff removes a newline from the code when adding braces to an inline control structure without body and with a trailing comment.
Code sample
if ($emptyBody); // comment
$unrelatedCode = 1;
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php with the code sample above.
- Run
phpcbf --standard=Generic --sniffs=Generic.ControlStructures.InlineControlStructure test.php
- Check the modified file
Expected behavior
I would expect the modified file to be:
if ($emptyBody) {
// comment
}
$unrelatedCode = 1;
But instead it is:
if ($emptyBody) {
// comment
}
$unrelatedCode = 1;
Note there is no newline between the if and the variable assignment.
Versions (please complete the following information)
|
|
| Operating System |
Ubuntu 24.04 |
| PHP version |
8.3 |
| PHP_CodeSniffer version |
master |
| Standard |
Generic |
| Install type |
git clone |
Additional context
I found this while working on finalizing the items discussed in #482 (review), specifically the sections about commits 6 and 7. I can work on a PR to fix this small issue. Since @jrfnl mentioned the current behavior of the sniff regarding how to handle inline control structures without body, I'm not planning to change it anymore as I did in commit 6 or remove part of the fixer code as I did in commit 7.
Please confirm
Describe the bug
The
Generic.ControlStructures.InlineControlStructuresniff removes a newline from the code when adding braces to an inline control structure without body and with a trailing comment.Code sample
To reproduce
Steps to reproduce the behavior:
test.phpwith the code sample above.phpcbf --standard=Generic --sniffs=Generic.ControlStructures.InlineControlStructure test.phpExpected behavior
I would expect the modified file to be:
But instead it is:
Note there is no newline between the
ifand the variable assignment.Versions (please complete the following information)
Additional context
I found this while working on finalizing the items discussed in #482 (review), specifically the sections about commits 6 and 7. I can work on a PR to fix this small issue. Since @jrfnl mentioned the current behavior of the sniff regarding how to handle inline control structures without body, I'm not planning to change it anymore as I did in commit 6 or remove part of the fixer code as I did in commit 7.
Please confirm
masterbranch of PHP_CodeSniffer.