Skip to content

Commit

Permalink
PHPCS/Composer: update PHPCS related dependencies
Browse files Browse the repository at this point in the history
Composer:
* Switches the repo over to use `PHPCompatibilityWP` rather than `PHPCompatibility`.
    As this repo and ruleset is for a WordPress project, using the `PHPCompatibilityWP` ruleset is the better choice to prevent false positives for PHP functions and constants which are back-filled by WP.
    Includes updating the underlying PHPCompatibility dependency. You were missing out on a lot of new checks, including the checks to make sure your code is compatible with the recently released PHP 7.4.
* Use the latest version of the DealerDirect Composer PHPCS plugin.
    Composer treats minors < 1.0 as majors, so you need to explicitly update.
* Use the latest version of WPCS.
* Remove the PHPCS dependency.
    This is not _your_ dependency, but a dependency of WPCS and PHPCompatibility, so let Composer sort out a version supported by both.
* Update the scripts to point to the versions of tooling installed via Composer, rather than presuming there will globally installed versions somewhere on contributor's systems.
* Remove the command line arguments form the PHPCS `lint` command.
    First off, the `inc/*` doesn't work anyway.
    Secondly, this is contained in the ruleset anyway, so no need to pass this information here.
    Includes removing the `-v` as this is only needed when debugging.

PHPCS ruleset:
* Rename the ruleset to `phpcs.xml.dist`. This allows devs to overload the file using `[.]phpcs.xml`.
    Includes adding the file names of the supported overload files to `.gitignore`.
* Do an open-ended check for cross-version compatibility.
    No need to limit this the checks to PHP `5.6-7.2`. Leaving the "up to" open ended will allow for receiving information about incompatibility with any PHP version from 5.6 up.
* Minor ruleset tweak related to long vs short arrays.
    WPCS demands long arrays as of WPCS 2.2.0. This repo uses short arrays, so enforce that instead.
* Updating the excluded error codes for the `WordPress.NamingConventions.ValidVariableName` sniff.
    These were renamed in WPCS 2.0.0.

Ref:
* https://github.com/PHPCompatibility/PHPCompatibilityWP
* PHPCompatibility/PHPCompatibility#688
* https://github.com/WordPress/WordPress-Coding-Standards/releases/
* https://github.com/Dealerdirect/phpcodesniffer-composer-installer/releases/
  • Loading branch information
jrfnl authored and swashata committed Dec 12, 2019
1 parent cb4e420 commit 509d109
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/coverage/
composer.phar
/vendor/
.phpcs.xml
phpcs.xml

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
],
"require": {},
"require-dev": {
"squizlabs/php_codesniffer": "^3.3.1",
"wp-coding-standards/wpcs": "^1.0.0",
"wimg/php-compatibility": "^8.2.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"wp-coding-standards/wpcs": "^2.2",
"phpcompatibility/phpcompatibility-wp": "^2.1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5",
"spatie/phpunit-snapshot-assertions": "^1.3.1",
"phpunit/phpunit": "^7.3.0",
"brain/monkey": "^2.2.0",
Expand All @@ -26,8 +25,8 @@
}
},
"scripts": {
"test": "phpunit --colors=always --testdox",
"lint": "phpcs -v inc/*",
"test": "vendor/bin/phpunit --colors=always --testdox",
"lint": "vendor/bin/phpcs",
"changelog": "npx auto-changelog --template keepachangelog -v"
},
"archive": {
Expand Down
Loading

0 comments on commit 509d109

Please sign in to comment.