-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic.ControlStructures.InlineControlStructure fixer moves new PHPCS annotations #1932
Comments
I have some hacked up code that may produce better results. But I'm about to rush out, so I Note: this is a mess, but it took a while to figure out how the fixer was even working here. |
I've had a shot at a complete fix. It's not 100% consistent but I don't really want to work on this sniff any more - it's taken too many hours already. It is better though, but could use more testing if you are able to help. Your sample code block is now fixed like this: while (!$this->readLine($tokens, $tag)) {} //phpcs:ignore Standard.Category.Sniff
foreach ($stringParade as $hit) {
$hitParade[] = $hit + 0; // phpcs:disable Standard.Category.Sniff
}
if ($bar) {
if ($foo) { echo 'hi'; /* @phpcs:ignore Standard.Category.Sniff */
}
} |
@gsherwood You're a star! I'll try and have a look at this over the weekend, but have total confidence in your fix ;-) |
Closing this as I haven't had any additional problems reported. |
This is one of the last few sniffs in which I know there are still issues with the PHPCS annotations.
In this case, the fixer moves trailing PHPCS annotations down to subsequent lines which changes their meaning completely.
Example code for the unit tests:
Expected fix:
Fix currently being made by the sniff as it is now:
Changing conditions which look for
T_COMMENT
, to ones which also takeTokens::$phpcsCommentTokens
into account, does not really help all that much (the first one is worse, the second better, the third still just as bad):I've stared at this one way too long by now and haven't figured out a solution yet.
I'm pretty sure the issue is somewhere in these lines:
PHP_CodeSniffer/src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php
Lines 220 to 239 in 1dede21
The text was updated successfully, but these errors were encountered: