From bae471ff3182937a08d78fbf3f47caec46a18a51 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 8 Feb 2018 14:33:50 +0100 Subject: [PATCH 01/12] Composer: add YoastCS * Add YoastCS - not fixed to a specific minor as for this repo any "stable" release should be fine. * Add the Dealerdirect Composer plugin to automatically sort out the PHPCS installed paths. Moved the `require-dev` section down to be directly after the `require` section for improved human-readability of the file. --- composer.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 44944ff..68f1924 100644 --- a/composer.json +++ b/composer.json @@ -2,10 +2,6 @@ "name": "yoast/whip", "description": "A WordPress package to nudge users to upgrade their software versions (starting with PHP)", "type": "library", - "require-dev": { - "phpunit/phpunit": "^3.6.12 | ^4.5 | ^5.7", - "roave/security-advisories": "dev-master" - }, "license": "GPL-3.0-or-later", "authors": [ { @@ -24,6 +20,12 @@ "require": { "xrstf/composer-php52": "^1.0" }, + "require-dev": { + "phpunit/phpunit": "^3.6.12 | ^4.5 | ^5.7", + "roave/security-advisories": "dev-master", + "yoast/yoastcs": "~0.5.0", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3" + }, "scripts": { "post-install-cmd": [ "xrstf\\Composer52\\Generator::onPostInstallCmd" From 54f50afa07c0ec766fece90a80a089bc3e43b52e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 15:43:37 +0200 Subject: [PATCH 02/12] Build/PHPCS: add a basic PHPCS ruleset checking against the `Yoast` standard The file is named `.phpcs.xml.dist` which allows for overruling the file with individual `phpcs.xml` and `.phpcs.xml` files. For that reasons, those files have been added to `.gitignore`. Also: activate checking against PHPCS once per Travis run. --- .gitignore | 2 ++ .phpcs.xml.dist | 38 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 2 ++ 3 files changed, 42 insertions(+) create mode 100644 .phpcs.xml.dist diff --git a/.gitignore b/.gitignore index 4fbb073..472359e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /vendor/ /composer.lock +.phpcs.xml +phpcs.xml diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 0000000..42bfb37 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,38 @@ + + + Yoast WHIP rules for PHP_CodeSniffer + + + + . + + vendor/* + + + + + + + + + + + + + + + + + + + + diff --git a/.travis.yml b/.travis.yml index 7e56b4f..7d8f150 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ matrix: fast_finish: true include: - php: 7.2 + env: PHPCS=1 - php: 5.2 dist: precise - php: 5.3 @@ -44,3 +45,4 @@ script: - find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l - if [[ "$TRAVIS_PHP_VERSION" == "5.2" ]]; then phpunit; else ./vendor/bin/phpunit; fi - if [[ "$TRAVIS_PHP_VERSION" != "5.2" ]]; then composer validate --no-check-all; fi +- if [[ $PHPCS == "1" ]]; then vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi From 7bbd7f2d53deee1b823f67282c88a8163a706d1e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 8 Feb 2018 17:19:19 +0100 Subject: [PATCH 03/12] Build/PHPCS: variable naming consistency (YoastCS exception) Historically, this library uses `camelCaps` for variable names instead of the WP convention of using `snake_case`. There is no need to change this, we just need: * to allow for it, i.e. exclude the WPCS sniff; * make sure it's applied consistently, i.e. include a PHPCS sniff to check for this; * fix up the few exceptions to the rules - done in separate PRs. --- .phpcs.xml.dist | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 42bfb37..5cdf435 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -32,7 +32,16 @@ ############################################################################# --> - + + + + + + + + + + From 7b30f5bf09c16cd46a1d269baae95dbe8811ffe6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 9 Feb 2018 04:49:42 +0100 Subject: [PATCH 04/12] Build/PHPCS: function naming consistency (YoastCS exception) Historically, this library uses `camelCaps` for function names instead of the WP convention of using `snake_case`. There is no need to change this, we just need: * to allow for it, i.e. exclude the WPCS sniff; * make sure it's applied consistently, i.e. include a PHPCS sniff to check for this and configure it; * exclude a few files which are justified exceptions. --- .phpcs.xml.dist | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 5cdf435..9cc8458 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -33,8 +33,9 @@ --> - + + @@ -43,5 +44,19 @@ + + + + + + + + + /src/facades/wordpress\.php$ + + + /tests/doubles/WpCoreFunctionsMock\.php$ + + From 4e87996c21c88f48ea3793da26709afaf51fa629 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 15:14:38 +0200 Subject: [PATCH 05/12] Build/PHPCS: exclude Yoast filename sniff Historically, this library uses a different convention for file names. --- .phpcs.xml.dist | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 9cc8458..dc9784d 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -36,6 +36,9 @@ + + + From 2ce81cafc905aa64f09693ae607779f1ab28eabf Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 15:48:15 +0200 Subject: [PATCH 06/12] Build/PHPCS: specify the minimum supported WP version --- .phpcs.xml.dist | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index dc9784d..92c6208 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -62,4 +62,13 @@ + + + + + From 96a900d981928f7e08f5e97553fc2dc6008b8d42 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 15:49:05 +0200 Subject: [PATCH 07/12] Build/PHPCS: enable checking for globals being prefixed ... and allow for non-prefixed globals in select test situations. --- .phpcs.xml.dist | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 92c6208..d825281 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -71,4 +71,16 @@ + + + + + + + + + /tests/doubles/WPCoreFunctionsMock\.php$ + + + From 3bf4214c6d93a6fb2b83fefb86e95696c2762dd2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 15:52:33 +0200 Subject: [PATCH 08/12] Build/PHPCS: temporarily downgrade the `WP.I18n.NonSingularStringLiteralDomain` error --- .phpcs.xml.dist | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index d825281..e8cabb9 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -83,4 +83,17 @@ + + + + + warning + + From f494f9b6a1a5d8b1a93324847fa1cd822e0b1649 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 16 Mar 2018 16:40:01 +0100 Subject: [PATCH 09/12] Build/PHPCS: exclude a false positive which will be fixed in WPCS 1.0.0 --- .phpcs.xml.dist | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index e8cabb9..bc1b681 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -96,4 +96,13 @@ warning + + + /tests/doubles/WPCoreFunctionsMock\.php$ + + From b4d5acfd05054153ae33d56b7f2fa5b502bca8a7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 16:54:12 +0200 Subject: [PATCH 10/12] Build/PHPCS: temporarily exclude selective warnings about non-prefixed hooks --- .phpcs.xml.dist | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index bc1b681..205be35 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -105,4 +105,10 @@ /tests/doubles/WPCoreFunctionsMock\.php$ + + + /src/Whip_Host\.php$ + + From e085632911839286e2a134839a441dc86f1964d3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 16:56:14 +0200 Subject: [PATCH 11/12] Build/PHPCS: temporarily exclude select documentation rules for the unit test files I've chosen to exclude the errors for the `tests` directory in contrast to downgrading them to `warnings` for the complete plugin to prevent new documentation errors being introduced in the non-test code. --- .phpcs.xml.dist | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 205be35..b6fa885 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -111,4 +111,19 @@ /src/Whip_Host\.php$ + + + /tests/*\.php$ + + + /tests/*\.php$ + + + /tests/*\.php$ + + + /tests/*\.php$ + + From 885655b0771dbc2800ed7b2e37ad764b4e518a97 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 May 2018 17:26:14 +0200 Subject: [PATCH 12/12] Build/Travis: prevent issues with incompatible PHPCS on PHP < 5.4 YoastCS uses PHP_CodeSniffer 3.x which has a minimum requirement of PHP 5.4. As the build check running PHPCS is run on PHP 7.2 and devs generally use a reasonably PHP version as well, this shouldn't be a problem. However, when installing from and/or validating the `composer.json` file during builds, Composer also tests all the scripts defined by the various packages and if this is done on PHP 5.3, the scripts for PHP_CodeSniffer will - predictably - fail. Removing PHPCS as a dependency for the non-PHPCS builds solves this. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7d8f150..5afe972 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,8 @@ before_install: install: - if [[ $TRAVIS_PHP_VERSION == "5.2" || $TRAVIS_PHP_VERSION == "5.3" ]]; then phpenv local 5.3.29; fi -- if [[ "$TRAVIS_PHP_VERSION" == "5.2" ]]; then composer remove --dev phpunit/phpunit; fi +- if [[ $TRAVIS_PHP_VERSION == "5.2" || $TRAVIS_PHP_VERSION == "5.3" ]]; then composer remove --dev yoast/yoastcs dealerdirect/phpcodesniffer-composer-installer; fi +- if [[ $TRAVIS_PHP_VERSION == "5.2" ]]; then composer remove --dev phpunit/phpunit; fi - composer install --prefer-dist --no-interaction - if [[ $TRAVIS_PHP_VERSION == "5.2" || $TRAVIS_PHP_VERSION == "5.3" ]]; then phpenv local --unset; fi