From 9d9ee4fecb6286b09e20970764d50e7fd34b54c1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 14 Sep 2023 04:51:41 +0200 Subject: [PATCH 1/4] Composer: add dependency on PHPCSUtils By starting to use PHPCSUtils, we make YoastCS less dependent on WordPressCS. PHPCSUtils brings added benefits of more stable, thoroughly tested utility methods, which all support modern PHP. Along those lines, the utility functions in PHPCSUtils which mirror PHPCS native utility functions are generally compatible with new PHP syntaxes well before there is a PHPCS release available with such support for these utility functions. This commit adds the dependency and updates relevant documentation and CI. Includes removing the explicit dependency on the Composer PHPCS Installer plugin. This dependency will now be inherited from PHPCSUtils. Letting PHPCSUtils manage the supported versions prevents conflicts. Closes 157 --- .github/workflows/basics.yml | 1 + .github/workflows/quicktest.yml | 2 ++ .github/workflows/test.yml | 5 +++++ composer.json | 2 +- phpunit-bootstrap.php | 3 ++- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/basics.yml b/.github/workflows/basics.yml index 2ef7146a..344c629c 100644 --- a/.github/workflows/basics.yml +++ b/.github/workflows/basics.yml @@ -54,6 +54,7 @@ jobs: run: > composer require --no-update --no-scripts --no-interaction squizlabs/php_codesniffer:"dev-master" + phpcsstandards/phpcsutils:"dev-develop" phpcsstandards/phpcsextra:"dev-develop" # Install dependencies and handle caching in one go. diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 47e25929..91216b62 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -63,6 +63,7 @@ jobs: run: > composer require --no-update --no-scripts --no-interaction --ignore-platform-req=php+ squizlabs/php_codesniffer:"dev-master" + phpcsstandards/phpcsutils:"dev-develop" # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies @@ -86,6 +87,7 @@ jobs: run: > composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+ squizlabs/php_codesniffer + phpcsstandards/phpcsutils wp-coding-standards/wpcs - name: Verify installed standards diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 05715330..434d353a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,7 @@ concurrency: # Once support for WPCS 3.0.0 has been added, the matrix should switch (back) using `dev-develop`. env: PHPCS_HIGHEST: 'dev-master' + UTILS_HIGHEST: 'dev-develop' WPCS_HIGHEST: '2.3.0' jobs: @@ -96,6 +97,7 @@ jobs: run: > composer require --no-update --no-scripts --no-interaction --ignore-platform-req=php+ squizlabs/php_codesniffer:"${{ env.PHPCS_HIGHEST }}" + phpcsstandards/phpcsutils:"${{ env.UTILS_HIGHEST }}" # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies @@ -119,6 +121,7 @@ jobs: run: > composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+ squizlabs/php_codesniffer + phpcsstandards/phpcsutils wp-coding-standards/wpcs - name: Verify installed versions @@ -191,6 +194,7 @@ jobs: run: > composer require --no-update --no-scripts --no-interaction squizlabs/php_codesniffer:"${{ env.PHPCS_HIGHEST }}" + phpcsstandards/phpcsutils:"${{ env.UTILS_HIGHEST }}" # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies @@ -205,6 +209,7 @@ jobs: run: > composer update --prefer-lowest --no-scripts --no-interaction squizlabs/php_codesniffer + phpcsstandards/phpcsutils wp-coding-standards/wpcs - name: Verify installed versions diff --git a/composer.json b/composer.json index 3874d100..13539cdf 100644 --- a/composer.json +++ b/composer.json @@ -25,11 +25,11 @@ "require": { "php": ">=5.4", "ext-tokenizer": "*", - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/phpcompatibility-wp": "^2.1.4", "phpcsstandards/phpcsextra": "^1.1.2", + "phpcsstandards/phpcsutils": "^1.0.8", "squizlabs/php_codesniffer": "^3.7.2", "wp-coding-standards/wpcs": "^2.3.0" }, diff --git a/phpunit-bootstrap.php b/phpunit-bootstrap.php index c75a99e7..50bc6a59 100644 --- a/phpunit-bootstrap.php +++ b/phpunit-bootstrap.php @@ -49,7 +49,8 @@ If you use Composer, please run `composer install`. Otherwise, make sure you set a `PHPCS_DIR` environment variable in your phpunit.xml file -pointing to the PHPCS directory. +pointing to the PHPCS directory and that PHPCSUtils is included in the `installed_paths` +for that PHPCS install. '; die( 1 ); From b680180e1de3ae9feb2cfefee9b996718fcc9bce Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 14 Sep 2023 04:59:27 +0200 Subject: [PATCH 2/4] YoastCS: add PHPCSUtils requirement PHPCSUtils does not contain any sniffs, so adding this rule isn't strictly necessary, but by having the rule in the ruleset anyway, if PHPCSUtils is missing, the user will get a descriptive error message during the loading of the ruleset instead of a fatal "class not found" error once the sniffs start running. --- Yoast/ruleset.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Yoast/ruleset.xml b/Yoast/ruleset.xml index 82a53fc3..4788adfc 100644 --- a/Yoast/ruleset.xml +++ b/Yoast/ruleset.xml @@ -26,6 +26,16 @@ add configuration for a sniff. ############################################################################# --> + + + +