WIP: PHPCS 4.x changes#3
Open
rodrigoprimo wants to merge 47 commits intodevelopfrom
Open
Conversation
f04e071 to
c78b598
Compare
50244fd to
4d6533c
Compare
3e1ea76 to
9aeec04
Compare
f7ad57e to
9e2a835
Compare
8113034 to
cd42bc6
Compare
b2a138a to
bb822fe
Compare
a4c6ab1 to
b4d3fb3
Compare
d8fd190 to
d20de47
Compare
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization of fully qualified function calls when checking if a nonce verification function is used in the code.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when skipping over function calls while checking the hook name.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking if a given fully qualified function is a target function. In those cases, the leading backslash is removed from the token content to allow for the function name comparisons to continue working as they worked in PHPCS 3.x.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking for calls to `define()` and hook functions to handle fully qualified calls correctly.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking if a given token is a target token.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking function calls after the `T_ASPERAND` token.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when determining the name of the function being called.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking if a WP time constant was used and when checking the name of a first-class callable. It also updates a few test expectation to account for the difference in the sniff behavior when running with PHPCS 3.x and 4.x.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking if a PHP native array key exists function was used.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when determining if a constant is global or not.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when checking the name of a given constants to see if it is one of the discouraged constants and when checking if `define()` was called.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization to this sniff.
Correctly handle changing fully qualified `\current_time()` function name.
Update the README.md file to document the limitations of running the sniff together with PHPCS >= 4.0. Remember to pull the corresponding PR to update the wiki.
PHPCS 4.x removed special test-specific code from the Ruleset class that handled `Config::$sniffs` restrictions differently when `PHP_CODESNIFFER_IN_TESTS` was defined (see PHPCSStandards/PHP_CodeSniffer/ 996).
This caused `testStdIn()` tests that used `$config->standards = array('WordPress')` to attempt loading the entire WordPress standard with all dependencies, resulting in errors about missing standards.
The fix uses minimal ruleset XML files that only include the specific sniff being tested making the test pass with both PHPCS 3.x and 4.x.
Add support for the new namespaced name tokenization used in PHPCS 4.0. Since the tokenization changed between PHPCS 3 and 4, different logic is used depending on the PHPCS version.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization when searching for the function name in the ContextHelper::$arrayCompareFunctions array.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization of fully qualified function calls and static method calls to this sniff. It also updates a few of the test expectations as the number of errors vary depending on whether running PHPCS 3.x or 4.x.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization to this method.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization of fully qualified calls to `\wpdb::prepare()`, `\sprintf()`, `\implode()` and `\array_fill()`.
The tokenization of (namespaced) "names" has changed in PHP 8.0, and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0. This commit adds handling for the new tokenization of fully qualified calls to WPDB methods and also ensure that the method bails when handling `T_NAME_QUALIFIED` and `T_NAME_RELATIVE` tokens. As a side effect, this also fixes a bug where the method would not bail early when the token is not T_STRING, T_VARIABLE, or T_NAME_FULLY_QUALIFIED, which could cause it to return true for any token followed by an object operator and a target method call.
Update the expectation for three test cases as they are different between PHPCS 3.x and PHPCS 4.x (see 2665).
The `is_escaping_function()` and `is_auto_escaped_function()` methods now use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
… 4.0 Use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
Use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
Use `ltrim()` to strip the leading backslash from fully qualified function names, ensuring they are correctly recognized when tokenized as `T_NAME_FULLY_QUALIFIED` in PHPCS 4.0.
PHPCS 4.0 introduced a change where empty string values in array properties are converted to `null`. This is documented in the Version 4.0 Developer Upgrade Guide (https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Version-4.0-Developer-Upgrade-Guide#property-type-casting-has-been-made-more-consistent): > Array elements can now no longer contain an empty string value > as that value will be cast to `null`. This affected the sniffs PrefixAllGlobals and NoSilencedErrors. Both pass array values to `strtolower()`, which triggers a PHP 8.5 deprecation warning when `null` is passed. The fix is different for each sniff: - PrefixAllGlobals: Convert `null` back to empty string at the start of the validation loop. This preserves the "prefix too short" error that alerts users about invalid configuration. - NoSilencedErrors: Filter out `null` values before processing. Unlike PrefixAllGlobals, this sniff has no validation that provides user feedback for invalid entries, so filtering is cleaner. A test case was added to safeguard against the deprecation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Creating this PR to test the GH action changes.