-
-
Notifications
You must be signed in to change notification settings - Fork 205
Description
Is your feature request related to a problem?
Discovered while investigating upstream issue PHPCSStandards/PHP_CodeSniffer#529.
It appears there is a change in PHP 8.3 which makes the PHP tokenizer tolerant of comments between the yield and from keywords in a yield from expression.
Prior to PHP 8.3, this was a parse error in PHP. See: https://3v4l.org/2SI2Q#veol
I have not been able to find documentation/changelogs regarding this change. (though haven't searched extensively yet)
Describe the solution you'd like
A new sniff which will flag yield from with a comment between the keywords.
The sniff would need to take into account that the yield and from keywords might be on different lines which would mean that two subsequent T_YIELD_FROM tokens will need to be examined as one.
This new sniff would currently need to search for:
T_YIELD_FROMand check the contents of the token(s) to not contain any comments. I.e.#yield\s+from#iT_YIELDtokens followed by one or more comment tokens, followed by aT_STRINGtoken with a case-insensitive match forfrom.
This may need to be updated/changed, depending on what action is taken on issue PHPCSStandards/PHP_CodeSniffer#529
<?php
function generator()
{
// These are OK.
yield from gen2();
yield
from
gen2();
// These should be flagged.
yield /* comment */ from gen2();
yield // comment
from gen2();
yield
/* comment */
from
gen2();
}Related to #1589
- I intend to create a pull request to implement this feature.