Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 25, 2024

. In addition to whitespace characters, now comments are allowed between
yield and from. The whole "construct" (e.g. yield /* comment */ from)
is reported as a single T_YIELD_FROM token by the tokenizer.

This commit adds a new sniff which detects this in a PHPCS cross-version compatible manner.

Once support for PHPCS < 3.11.0 has been dropped, this sniff can be simplified, but IMO, this sniff alone is not enough reason to raise the minimum supported PHPCS version, especially as working around the different tokenizations isn't that complicated.

Includes tests.
Includes documentation.

Refs:

Related to #1589
Fixes #1720

> . In addition to whitespace characters, now comments are allowed between
>   `yield` and `from`. The whole "construct" (e.g. `yield /* comment */ from`)
>   is reported as a single `T_YIELD_FROM` token by the tokenizer.

This commit adds a new sniff which detects this in a PHPCS cross-version compatible manner.

Once support for PHPCS < 3.11.0 has been dropped, this sniff can be simplified, but IMO, this sniff alone is not enough reason to raise the minimum supported PHPCS version, especially as working around the different tokenizations isn't that complicated.

Includes tests.
Includes documentation.

Refs:
* php/php-src 14926
* https://github.com/php/php-src/blob/e4010fcf957c62ddb70f8d3296d52c5486a84d4d/UPGRADING#L48-L50
* php/php-src 10125
* php/php-src@f291d37

Related to 1589
Fixes 1720
@jrfnl
Copy link
Member Author

jrfnl commented Nov 2, 2024

⚠️ The PR should not be merged though until upstream PR PHPCSStandards/PHP_CodeSniffer#647 has been merged and the PHPCompatibility tests for this PR have been re-run (to ensure this PR is compatible with the upcoming PHPCS 3.11.0 release). ⚠️

I've just re-ran the tests after the merge of the upstream PR. The tests pass, so marking this PR ready for review/merge.

@jrfnl jrfnl marked this pull request as ready for review November 2, 2024 10:59
@wimg wimg merged commit eac0093 into develop Nov 29, 2024
45 checks passed
@wimg wimg deleted the feature/new-newyieldfromcomment-sniff branch November 29, 2024 23:41
@jrfnl jrfnl added the PHP: 8.3 label Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8.3: sniff to detect comment between yield and from

3 participants