Skip to content

Commit c0877a9

Browse files
authored
Merge pull request #1608 from WordPress-Coding-Standards/develop
Release WPCS 2.0.0-RC1
2 parents f328bca + 9b17fe2 commit c0877a9

File tree

321 files changed

+1432
-8764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

321 files changed

+1432
-8764
lines changed

.gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
/phpunit.xml.dist export-ignore
1010
/.github export-ignore
1111
/bin export-ignore
12-
/Test export-ignore
1312
/WordPress/Tests export-ignore
1413

1514
#

.github/CONTRIBUTING.md

+29-62
Original file line numberDiff line numberDiff line change
@@ -37,111 +37,78 @@ When you introduce new `public` sniff properties, or your sniff extends a class
3737
> **Important**:
3838
> PHPCS 3.2.0 introduced new selective ignore annotations, which can be considered an improved version of the whitelist mechanism which WPCS contains.
3939
>
40-
> There is a [tentative intention to drop support for the WPCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1048#issuecomment-340698249) in WPCS 2.0.0.
41-
>
42-
> Considering that, the introduction of new whitelist comments is discouraged.
40+
> Support for the WPCS native whitelist comments has been deprecated in WPCS 2.0.0 and will be removed in WPCS 3.0.0.
4341
>
44-
> The below information remains as guidance for exceptional cases and to aid in understanding the previous implementation.
45-
46-
Sometimes, a sniff will flag code which upon further inspection by a human turns out to be OK.
47-
48-
If the sniff you are writing is susceptible to this, please consider adding the ability to [whitelist lines of code](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors).
49-
50-
To this end, the `WordPress\Sniff::has_whitelist_comment()` method was introduced.
51-
52-
Example usage:
53-
```php
54-
namespace WordPress\Sniffs\Security;
55-
56-
use WordPress\Sniff;
57-
58-
class NonceVerificationSniff extends Sniff {
59-
60-
public function process_token( $stackPtr ) {
61-
62-
// Check something.
63-
64-
if ( $this->has_whitelist_comment( 'CSRF', $stackPtr ) ) {
65-
return;
66-
}
67-
68-
$this->phpcsFile->addError( ... );
69-
}
70-
}
71-
```
72-
73-
When you introduce a new whitelist comment, please don't forget to update the [whitelisting code wiki page](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors) with the relevant details once your PR has been merged into the `develop` branch.
42+
> With that in mind, (new) sniffs should not introduce new WPCS native whitelist comments.
7443
7544

7645
# Unit Testing
7746

7847
## Pre-requisites
7948
* WordPress-Coding-Standards
80-
* PHP_CodeSniffer 2.9.x or 3.x
49+
* PHP_CodeSniffer 3.3.1 or higher
8150
* PHPUnit 4.x, 5.x, 6.x or 7.x
8251

83-
The WordPress Coding Standards use the PHP_CodeSniffer native unit test suite for unit testing the sniffs.
52+
The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test suite for unit testing the sniffs.
8453

85-
Presuming you have installed PHP_CodeSniffer and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`.
54+
Presuming you have installed `PHP_CodeSniffer` and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`.
8655

87-
N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` or run `composer install --prefer-source` now to make sure the unit tests are available.
56+
> N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` or run `composer install --prefer-source` now to make sure the unit tests are available.
57+
> Other than that, you're all set already as Composer will have installed PHPUnit for you.
8858
8959
If you already have PHPUnit installed on your system: Congrats, you're all set.
9060

91-
If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies.
92-
Alternatively, you can [install PHPUnit](https://phpunit.de/manual/5.7/en/installation.html) as a PHAR file.
61+
## Installing PHPUnit
62+
63+
N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._
64+
65+
You can either navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies or you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file.
66+
67+
You may want to add the directory where PHPUnit is installed to a `PATH` environment variable for your operating system to make the command available everywhere on your system.
9368

9469
## Before running the unit tests
9570

9671
N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._
9772

9873
For the unit tests to work, you need to make sure PHPUnit can find your `PHP_CodeSniffer` install.
9974

100-
The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. Make sure to adjust the path to reflect your local setup.
75+
The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file.
76+
Copy the existing `phpunit.xml.dist` file and add the below `<env>` directive within the `<php>` section. Make sure to adjust the path to reflect your local setup.
10177
```xml
102-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
103-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
104-
beStrictAboutTestsThatDoNotTestAnything="false"
105-
backupGlobals="true">
10678
<php>
10779
<env name="PHPCS_DIR" value="/path/to/PHP_CodeSniffer/"/>
10880
</php>
109-
</phpunit>
11081
```
11182

11283
## Running the unit tests
11384

114-
The WordPress Coding Standards are compatible with both PHPCS 2.x as well as 3.x. This has some implications for running the unit tests.
115-
116-
* Make sure you have registered the directory in which you installed WPCS with PHPCS using;
85+
* If you didn't install WPCS using Composer, make sure you have registered the directory in which you installed WPCS with PHPCS using:
11786
```sh
11887
phpcs --config-set installed_paths path/to/WPCS
11988
```
12089
* Navigate to the directory in which you installed WPCS.
121-
* To run the unit tests with PHPCS 3.x:
90+
* To run the unit tests:
12291
```sh
123-
phpunit --bootstrap="./Test/phpcs3-bootstrap.php" --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php
124-
```
125-
* To run the unit tests with PHPCS 2.x:
126-
```sh
127-
phpunit --bootstrap="./Test/phpcs2-bootstrap.php" --filter WordPress ./Test/AllTests.php
92+
phpunit --filter WordPress --bootstrap="/path/to/PHP_CodeSniffer/tests/bootstrap.php" /path/to/PHP_CodeSniffer/tests/AllTests.php
93+
94+
# Or if you've installed WPCS with Composer:
95+
composer run-tests
12896
```
12997

13098
Expected output:
13199
```
132-
PHPUnit 6.5.8 by Sebastian Bergmann and contributors.
100+
PHPUnit 7.5.0 by Sebastian Bergmann and contributors.
133101

134-
Runtime: PHP 7.2.7 with Xdebug 2.6.0
102+
Runtime: PHP 7.2.13
135103
Configuration: /WordPressCS/phpunit.xml
136104

137-
................................................................. 65 / 77 ( 84%)
138-
............ 77 / 77 (100%)
105+
........................................................ 56 / 56 (100%)
139106

140-
Tests generated 576 unique error codes; 51 were fixable (8.85%)
107+
152 sniff test files generated 487 unique error codes; 52 were fixable (10.68%)
141108

142-
Time: 22.93 seconds, Memory: 40.00MB
109+
Time: 21.36 seconds, Memory: 22.00MB
143110

144-
OK (77 tests, 0 assertions)
111+
OK (56 tests, 0 assertions)
145112
```
146113
147114
[![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078)
@@ -154,7 +121,7 @@ Lets take a look at what's inside `POSIXFunctionsUnitTest.php`:
154121
155122
```php
156123
...
157-
namespace WordPress\Tests\PHP;
124+
namespace WordPressCS\WordPress\Tests\PHP;
158125
159126
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
160127

.github/ISSUE_TEMPLATE/dependency-change.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ about: A reminder to take action when a WPCS dependency changes
44

55
---
66

7-
<!-- PLEASE prefix the title the Issue with the dependency name and version when action should be taken e.g. PHPCS 3.3: ... -->
7+
<!-- PLEASE prefix the title the Issue with the dependency name and version when action should be taken e.g. PHPCS 3.5: ... -->
88

99
## Rationale
1010

.github/issue_template.md

-11
This file was deleted.

.phpcs.xml.dist

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<?xml version="1.0"?>
2-
<ruleset name="WordPress Coding Standards">
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WordPress Coding Standards" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
3+
34
<description>The Coding standard for the WordPress Coding Standards itself.</description>
45

56
<file>.</file>
67

78
<arg value="sp"/>
89
<arg name="extensions" value="php"/>
910

10-
<!-- Exclude the code in the PHPCS 2.x test files copied in from PHPCS. -->
11-
<exclude-pattern>/Test/AllTests.php</exclude-pattern>
12-
<exclude-pattern>/Test/Standards/*.php</exclude-pattern>
1311
<exclude-pattern>/bin/class-ruleset-test.php</exclude-pattern>
14-
1512
<!-- Exclude Composer vendor directory. -->
1613
<exclude-pattern>*/vendor/*</exclude-pattern>
1714

@@ -29,13 +26,14 @@
2926
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
3027
<properties>
3128
<property name="alignMultilineItems" value="!=100"/>
29+
<property name="exact" value="false" phpcs-only="true"/>
3230
</properties>
3331
</rule>
3432

3533
<rule ref="PSR2.Methods.FunctionClosingBrace"/>
3634

3735
<!-- Check code for cross-version PHP compatibility. -->
38-
<config name="testVersion" value="5.3-"/>
36+
<config name="testVersion" value="5.4-"/>
3937
<rule ref="PHPCompatibility">
4038
<!-- Exclude PHP constants back-filled by PHPCS. -->
4139
<exclude name="PHPCompatibility.Constants.NewConstants.t_finallyFound"/>
@@ -47,9 +45,12 @@
4745
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesceFound"/>
4846
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesce_equalFound"/>
4947
<exclude name="PHPCompatibility.Constants.NewConstants.t_yield_fromFound"/>
48+
</rule>
5049

51-
<!-- Unclear how, but appears to be back-filled anyhow, could be that PHP did so before the token was in use. -->
52-
<exclude name="PHPCompatibility.Constants.NewConstants.t_traitFound"/>
50+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.DeprecatedWhitelistCommentFound">
51+
<!-- False positive for whitelist comment recognition, but no use fixing this now
52+
as the WPCS native whitelist comments are deprecated anyhow. -->
53+
<exclude-pattern>/WordPress/AbstractClassRestrictionsSniff\.php$</exclude-pattern>
5354
</rule>
5455

5556
</ruleset>

.travis.yml

+7-39
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ php:
2626
env:
2727
# `master` is now 3.x.
2828
- PHPCS_BRANCH="dev-master" LINT=1
29-
# Lowest supported release in the 3.x series with which WPCS is compatible (and which can run the unit tests).
30-
- PHPCS_BRANCH="3.1.0"
31-
# Lowest tagged release in the 2.x series with which WPCS is compatible.
32-
- PHPCS_BRANCH="2.9.0"
29+
# Lowest supported release in the 3.x series with which WPCS is compatible.
30+
- PHPCS_BRANCH="3.3.1"
3331

3432
matrix:
3533
fast_finish: true
@@ -42,22 +40,9 @@ matrix:
4240
packages:
4341
- libxml2-utils
4442

45-
# Test PHP 5.3 only against PHPCS 2.x as PHPCS 3.x has a minimum requirement of PHP 5.4.
46-
- php: 5.3
47-
env: PHPCS_BRANCH="2.9.*" LINT=1
48-
dist: precise
49-
# Test PHP 5.3 with short_open_tags set to On (is Off by default)
50-
- php: 5.3
51-
env: PHPCS_BRANCH="2.9.0" SHORT_OPEN_TAGS=true
52-
dist: precise
53-
5443
allow_failures:
5544
# Allow failures for unstable builds.
5645
- php: nightly
57-
- php: 7.3
58-
env: PHPCS_BRANCH="3.1.0"
59-
- php: 7.3
60-
env: PHPCS_BRANCH="2.9.0"
6146

6247
before_install:
6348
# Speed up build time by disabling Xdebug.
@@ -66,36 +51,21 @@ before_install:
6651
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
6752
- export XMLLINT_INDENT=" "
6853
- export PHPUNIT_DIR=/tmp/phpunit
69-
- |
70-
if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then
71-
# --prefer-source is needed to ensure that the PHPCS unit test suite is available in PHPCS 2.9.
72-
composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --prefer-source --update-no-dev --no-suggest --no-scripts
73-
else
74-
composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts
75-
fi
54+
- composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts
7655
- |
7756
if [[ "$SNIFF" == "1" ]]; then
7857
composer install --dev --no-suggest
79-
# The post-install-cmd script takes care of the installed_paths.
58+
# The `dev` required DealerDirect Composer plugin takes care of the installed_paths.
8059
else
8160
# The above require already does the install.
8261
$(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd)
8362
fi
84-
# Download PHPUnit 5.x for builds on PHP 7 and nightly as the PHPCS
85-
# test suite is currently not compatible with PHPUnit 6.x.
86-
# Fixed at a very specific PHPUnit version.
87-
- if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-5.7.17.phar && chmod +x $PHPUNIT_DIR/phpunit-5.7.17.phar; fi
88-
# Selectively adjust the ini values for the build image to test ini value dependent sniff features.
89-
- if [[ "$SHORT_OPEN_TAGS" == "true" ]]; then echo "short_open_tag = On" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
9063
9164
script:
9265
# Lint the PHP files against parse errors.
9366
- if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi
9467
# Run the unit tests.
95-
- if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPress $(pwd)/Test/AllTests.php; fi
96-
- if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi
97-
- if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/Test/AllTests.php; fi
98-
- if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi
68+
- phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php
9969
# Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
10070
# This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
10171
# For the first run, the exit code will be 1 (= all fixable errors fixed).
@@ -108,22 +78,20 @@ script:
10878
- if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Core; fi
10979
- if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Docs; fi
11080
- if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Extra; fi
111-
- if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-VIP; fi
11281
- if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress; fi
11382
# WordPress Coding Standards.
11483
# @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
11584
# @link http://pear.php.net/package/PHP_CodeSniffer/
11685
- if [[ "$SNIFF" == "1" ]]; then $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi
11786
# Validate the xml files.
11887
# @link http://xmlsoft.org/xmllint.html
119-
- if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./*/ruleset.xml; fi
120-
- if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./phpcs.xml.dist.sample; fi
88+
- if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml; fi
89+
- if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample; fi
12190
# Check the code-style consistency of the xml files.
12291
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml"); fi
12392
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi
12493
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml"); fi
12594
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml"); fi
126-
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-VIP/ruleset.xml <(xmllint --format "./WordPress-VIP/ruleset.xml"); fi
12795
- if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample"); fi
12896
# Validate the composer.json file.
12997
# @link https://getcomposer.org/doc/03-cli.md#validate

0 commit comments

Comments
 (0)