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
Using the sniff PSR2.ControlStructures.SwitchDeclaration brings in an edge case for the error code TerminatingComment when trying to ignore it for a case token, it generates an error for another case token
Create a file called test.php with the code sample above...
Run phpcs test.php ...
With the existing phpcs:ignore its reported an error for the "case 0:" line (which is not expected from my point of view). Without the phpcs:ignore its reported an error for "case 2:" line (which is expected)
Workaround
Adding the phpcs:ignore behind "case 2:" works or another phpcs:ignore for "case 0:"
Expected behavior
The use of phpcs:ignore (or other phpcs comments) should not trigger the error code
Versions (please complete the following information):
OS: Windows 10
PHP: 8.0
PHPCS: 3.6.0
Standard: -
Additional context
From my understand of the code here, it just checks for T_COMMENT, which does not include phpcs:ignore comments like this, not sure if Tokens::$commentTokens is what you want here instead
[Off Topic: When first looking at the line number I was assuming the comment was required between the case before the reported line and the reported case, but that was completly wrong - but my switch/case was very long and that's why I missed the right location to add the missing comment on the first spot]
The text was updated successfully, but these errors were encountered:
gsherwood
changed the title
PSR2.ControlStructures.SwitchDeclaration.TerminatingComment takes phpcs:ignore as content of case body
PSR2.ControlStructures.SwitchDeclaration takes phpcs:ignore as content of case body
Apr 16, 2021
Describe the bug
Using the sniff
PSR2.ControlStructures.SwitchDeclaration
brings in an edge case for the error codeTerminatingComment
when trying to ignore it for a case token, it generates an error for another case tokenCode sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Workaround
Adding the phpcs:ignore behind "case 2:" works or another phpcs:ignore for "case 0:"
Expected behavior
The use of phpcs:ignore (or other phpcs comments) should not trigger the error code
Versions (please complete the following information):
Additional context
From my understand of the code here, it just checks for
T_COMMENT
, which does not include phpcs:ignore comments like this, not sure ifTokens::$commentTokens
is what you want here instead[Off Topic: When first looking at the line number I was assuming the comment was required between the case before the reported line and the reported case, but that was completly wrong - but my switch/case was very long and that's why I missed the right location to add the missing comment on the first spot]
The text was updated successfully, but these errors were encountered: