From 30a33cb47c5934db080156e4e2f622ef86e52cb3 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Mon, 11 Jun 2018 18:52:35 +0200
Subject: [PATCH] Update PHPCS ruleset for WP Core and related Composer setup
`.gitignore`:
* 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:
* Comment out a reference to a sniff which doesn't exist in WPCS yet (for now).
* 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/I18n.php` file from issues being reported by the `WordPress.WP.I18n` sniff.
---
.gitignore | 2 ++
composer.json | 3 +--
composer.lock | 22 +++++++++++-----------
phpcs.xml.dist | 15 ++++++++++++++-
4 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/.gitignore b/.gitignore
index fcccc17759..b1ce13bf19 100644
a
|
b
|
wp-tests-config.php |
7 | 7 | |
8 | 8 | # Files and folders related to build/test tools |
9 | 9 | /phpunit.xml |
| 10 | /.phpcs.xml |
| 11 | /phpcs.xml |
10 | 12 | /tests/phpunit/data/plugins/wordpress-importer |
11 | 13 | /tests/phpunit/data/.trac-ticket-cache* |
12 | 14 | /tests/qunit/compiled.html |
diff --git a/composer.json b/composer.json
index a95151612a..c612cbbfa3 100644
a
|
b
|
|
11 | 11 | }, |
12 | 12 | "require-dev": { |
13 | 13 | "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", |
14 | | "squizlabs/php_codesniffer": "^3.2.3", |
15 | | "wp-coding-standards/wpcs": "dev-feature/new-multi-line-comment-formatting-sniffs" |
| 14 | "wp-coding-standards/wpcs": "dev-master" |
16 | 15 | }, |
17 | 16 | "scripts": { |
18 | 17 | "format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source", |
diff --git a/composer.lock b/composer.lock
index 9176795c8c..2d88e21514 100644
a
|
b
|
|
4 | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
5 | 5 | "This file is @generated automatically" |
6 | 6 | ], |
7 | | "content-hash": "4b409623b2bc5d8e87b7f45d57a60990", |
| 7 | "content-hash": "9c2c871b813e89682ef445611d2f5363", |
8 | 8 | "packages": [], |
9 | 9 | "packages-dev": [ |
10 | 10 | { |
… |
… |
|
77 | 77 | }, |
78 | 78 | { |
79 | 79 | "name": "squizlabs/php_codesniffer", |
80 | | "version": "3.2.3", |
| 80 | "version": "3.3.0", |
81 | 81 | "source": { |
82 | 82 | "type": "git", |
83 | 83 | "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", |
84 | | "reference": "4842476c434e375f9d3182ff7b89059583aa8b27" |
| 84 | "reference": "d86873af43b4aa9d1f39a3601cc0cfcf02b25266" |
85 | 85 | }, |
86 | 86 | "dist": { |
87 | 87 | "type": "zip", |
88 | | "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", |
89 | | "reference": "4842476c434e375f9d3182ff7b89059583aa8b27", |
| 88 | "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/d86873af43b4aa9d1f39a3601cc0cfcf02b25266", |
| 89 | "reference": "d86873af43b4aa9d1f39a3601cc0cfcf02b25266", |
90 | 90 | "shasum": "" |
91 | 91 | }, |
92 | 92 | "require": { |
… |
… |
|
124 | 124 | "phpcs", |
125 | 125 | "standards" |
126 | 126 | ], |
127 | | "time": "2018-02-20T21:35:23+00:00" |
| 127 | "time": "2018-06-06T23:58:19+00:00" |
128 | 128 | }, |
129 | 129 | { |
130 | 130 | "name": "wp-coding-standards/wpcs", |
131 | | "version": "dev-feature/new-multi-line-comment-formatting-sniffs", |
| 131 | "version": "dev-master", |
132 | 132 | "source": { |
133 | 133 | "type": "git", |
134 | 134 | "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", |
135 | | "reference": "ce4d719296ebbecd01f57bc3729833e89b39ad99" |
| 135 | "reference": "cf6b310caad735816caef7573295f8a534374706" |
136 | 136 | }, |
137 | 137 | "dist": { |
138 | 138 | "type": "zip", |
139 | | "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/ce4d719296ebbecd01f57bc3729833e89b39ad99", |
140 | | "reference": "ce4d719296ebbecd01f57bc3729833e89b39ad99", |
| 139 | "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/cf6b310caad735816caef7573295f8a534374706", |
| 140 | "reference": "cf6b310caad735816caef7573295f8a534374706", |
141 | 141 | "shasum": "" |
142 | 142 | }, |
143 | 143 | "require": { |
… |
… |
|
164 | 164 | "standards", |
165 | 165 | "wordpress" |
166 | 166 | ], |
167 | | "time": "2017-11-30T18:28:51+00:00" |
| 167 | "time": "2018-02-16T01:57:48+00:00" |
168 | 168 | } |
169 | 169 | ], |
170 | 170 | "aliases": [], |
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index e119e13d08..63c249cc16 100644
a
|
b
|
|
4 | 4 | |
5 | 5 | <rule ref="WordPress-Core"/> |
6 | 6 | <rule ref="WordPress.CodeAnalysis.EmptyStatement"/> |
7 | | <rule ref="WordPress.Commenting.DocblockFormat"/> |
| 7 | <!-- Commented out in anticipation of a PR to WPCS to add this sniff properly. --> |
| 8 | <!--<rule ref="WordPress.Commenting.DocblockFormat"/>--> |
8 | 9 | |
9 | 10 | <arg name="extensions" value="php"/> |
10 | 11 | |
| 12 | <!-- Strip the filepaths down to the relevant bit. --> |
| 13 | <arg name="basepath" value="./"/> |
| 14 | |
| 15 | <!-- Check up to 20 files simultanously. --> |
| 16 | <arg name="parallel" value="20"/> |
| 17 | |
11 | 18 | <!-- Show sniff codes in all reports --> |
12 | 19 | <arg value="ps"/> |
13 | 20 | |
… |
… |
|
69 | 76 | <exclude-pattern>/tests/phpunit/tests/db\.php</exclude-pattern> |
70 | 77 | </rule> |
71 | 78 | |
| 79 | <!-- Whitelist the I18n functions file from issues identified by the I18n sniff |
| 80 | (such as calling the low-level translate() function). --> |
| 81 | <rule ref="WordPress.WP.I18n"> |
| 82 | <exclude-pattern>/src/wp-includes/l10n\.php</exclude-pattern> |
| 83 | </rule> |
| 84 | |
72 | 85 | <rule ref="Generic.Functions.FunctionCallArgumentSpacing"> |
73 | 86 | <exclude-pattern>/wp-config\.php</exclude-pattern> |
74 | 87 | <exclude-pattern>/wp-config-sample\.php</exclude-pattern> |