You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A false positive is reported if a switch case contains an if/else structure where all branches exit the switch, and one of the branches ends with a comment. Minimal example is below; the error is also reported if one or more elseif branches exist, if the comment is on a different branch, if the comment is on the line after the break statement, or if return is used in place of break. No error is reported if the comment is removed, or is on the line before the break.
Create a file called test.php with the code sample above...
Run phpcs test.php ...
See error message displayed
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
4 | ERROR | There must be a comment when fall-through is intentional in a
| | non-empty case body
| | (PSR2.ControlStructures.SwitchDeclaration.TerminatingComment)
--------------------------------------------------------------------------------
Expected behavior
No error should be reported.
Versions:
OS: macOS 12.2.1
PHP: 8.3.1
PHPCS: 3.6.2
Standard: -
Additional context
The text was updated successfully, but these errors were encountered:
gsherwood
changed the title
False positive from PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
False positive from PSR2.ControlStructures.SwitchDeclaration.TerminatingComment when using trailing comment
Mar 18, 2022
Describe the bug
A false positive is reported if a
switch
case contains anif
/else
structure where all branches exit the switch, and one of the branches ends with a comment. Minimal example is below; the error is also reported if one or moreelseif
branches exist, if the comment is on a different branch, if the comment is on the line after thebreak
statement, or ifreturn
is used in place ofbreak
. No error is reported if the comment is removed, or is on the line before thebreak
.Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
No error should be reported.
Versions:
Additional context
The text was updated successfully, but these errors were encountered: