Build/Tools: Update PHPCS ruleset for WP Core and related Composer setup.

`.gitignore` + `svn:ignore`:
* Add the typical filenames of overloaded PHPCS configs to `.gitignore`.

Composer:
* Use the `develop` (Packagist `dev-master`) version of WPCS as it contains lots of bugfixes.
* Remove the PHPCS dependency. This is a dependency of WPCS, not of WP Core itself. This will also make sure that the PHPCS version used is always one which is supported by WPCS.
* Refreshed the `composer.lock` file.

PHPCS ruleset:
* Removed a reference to a sniff which doesn't exist in WPCS yet.
* Use the PHPCS 3.x `basepath` option to clean up the file paths PHPCS shows in the reports.
* Use the PHPCS 3.x `parallel` option to enable parallel scanning whenever possible to speed up the scans.
* Whitelist the `wp-includes/l10n.php` file from issues being reported by the `WordPress.WP.I18n` sniff.

Fixes #44366.

git-svn-id: https://develop.svn.wordpress.org/trunk@43348 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
jrf 2018-06-15 15:56:58 +00:00
parent 78f2b0e731
commit 3581d34bb0
4 changed files with 26 additions and 14 deletions

2
.gitignore vendored
View File

@ -7,6 +7,8 @@ wp-tests-config.php
# Files and folders related to build/test tools # Files and folders related to build/test tools
/phpunit.xml /phpunit.xml
/.phpcs.xml
/phpcs.xml
/tests/phpunit/data/plugins/wordpress-importer /tests/phpunit/data/plugins/wordpress-importer
/tests/phpunit/data/.trac-ticket-cache* /tests/phpunit/data/.trac-ticket-cache*
/tests/qunit/compiled.html /tests/qunit/compiled.html

View File

@ -11,8 +11,7 @@
}, },
"require-dev": { "require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"squizlabs/php_codesniffer": "^3.2.3", "wp-coding-standards/wpcs": "dev-master"
"wp-coding-standards/wpcs": "dev-feature/new-multi-line-comment-formatting-sniffs"
}, },
"scripts": { "scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source", "format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",

22
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "4b409623b2bc5d8e87b7f45d57a60990", "content-hash": "9c2c871b813e89682ef445611d2f5363",
"packages": [], "packages": [],
"packages-dev": [ "packages-dev": [
{ {
@ -77,16 +77,16 @@
}, },
{ {
"name": "squizlabs/php_codesniffer", "name": "squizlabs/php_codesniffer",
"version": "3.2.3", "version": "3.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "4842476c434e375f9d3182ff7b89059583aa8b27" "reference": "d86873af43b4aa9d1f39a3601cc0cfcf02b25266"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/d86873af43b4aa9d1f39a3601cc0cfcf02b25266",
"reference": "4842476c434e375f9d3182ff7b89059583aa8b27", "reference": "d86873af43b4aa9d1f39a3601cc0cfcf02b25266",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -124,20 +124,20 @@
"phpcs", "phpcs",
"standards" "standards"
], ],
"time": "2018-02-20T21:35:23+00:00" "time": "2018-06-06T23:58:19+00:00"
}, },
{ {
"name": "wp-coding-standards/wpcs", "name": "wp-coding-standards/wpcs",
"version": "dev-feature/new-multi-line-comment-formatting-sniffs", "version": "dev-master",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git",
"reference": "ce4d719296ebbecd01f57bc3729833e89b39ad99" "reference": "cf6b310caad735816caef7573295f8a534374706"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/ce4d719296ebbecd01f57bc3729833e89b39ad99", "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/cf6b310caad735816caef7573295f8a534374706",
"reference": "ce4d719296ebbecd01f57bc3729833e89b39ad99", "reference": "cf6b310caad735816caef7573295f8a534374706",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -164,7 +164,7 @@
"standards", "standards",
"wordpress" "wordpress"
], ],
"time": "2017-11-30T18:28:51+00:00" "time": "2018-02-16T01:57:48+00:00"
} }
], ],
"aliases": [], "aliases": [],

View File

@ -4,10 +4,15 @@
<rule ref="WordPress-Core"/> <rule ref="WordPress-Core"/>
<rule ref="WordPress.CodeAnalysis.EmptyStatement"/> <rule ref="WordPress.CodeAnalysis.EmptyStatement"/>
<rule ref="WordPress.Commenting.DocblockFormat"/>
<arg name="extensions" value="php"/> <arg name="extensions" value="php"/>
<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>
<!-- Check up to 20 files simultanously. -->
<arg name="parallel" value="20"/>
<!-- Show sniff codes in all reports --> <!-- Show sniff codes in all reports -->
<arg value="ps"/> <arg value="ps"/>
@ -69,6 +74,12 @@
<exclude-pattern>/tests/phpunit/tests/db\.php</exclude-pattern> <exclude-pattern>/tests/phpunit/tests/db\.php</exclude-pattern>
</rule> </rule>
<!-- Whitelist the I18n functions file from issues identified by the I18n sniff
(such as calling the low-level translate() function). -->
<rule ref="WordPress.WP.I18n">
<exclude-pattern>/src/wp-includes/l10n\.php</exclude-pattern>
</rule>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"> <rule ref="Generic.Functions.FunctionCallArgumentSpacing">
<exclude-pattern>/wp-config\.php</exclude-pattern> <exclude-pattern>/wp-config\.php</exclude-pattern>
<exclude-pattern>/wp-config-sample\.php</exclude-pattern> <exclude-pattern>/wp-config-sample\.php</exclude-pattern>