Skip to content

Commit bb792cb

Browse files
authored
Merge pull request #2369 from WordPress/develop
Release WordPressCS 3.0.0
2 parents 7da1894 + e36e0ea commit bb792cb

File tree

394 files changed

+19928
-13325
lines changed

Some content is hidden

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

394 files changed

+19928
-13325
lines changed

.codecov.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
codecov:
2+
notify:
3+
after_n_builds: 4
4+
5+
coverage:
6+
round: nearest
7+
# Status will be green when coverage is between 90 and 100%.
8+
range: "90...100"
9+
status:
10+
project:
11+
default:
12+
target: auto
13+
threshold: 1%
14+
paths:
15+
- "WordPress"
16+
patch: off
17+
18+
ignore:
19+
- "WordPress/Tests"
20+
21+
comment: false

.gitattributes

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#
22
# Exclude these files from release archives.
33
# This will also make them unavailable when using Composer with `--prefer-dist`.
4-
# If you develop for WPCS using Composer, use `--prefer-source`.
4+
# If you develop for WordPressCS using Composer, use `--prefer-source`.
55
# https://blog.madewithlove.be/post/gitattributes/
66
#
7-
/.travis.yml export-ignore
8-
/.phpcs.xml.dist export-ignore
9-
/phpunit.xml.dist export-ignore
10-
/.github export-ignore
11-
/bin export-ignore
12-
/WordPress/Tests export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/.codecov.yml export-ignore
10+
/.phpcs.xml.dist export-ignore
11+
/CODE_OF_CONDUCT.md export-ignore
12+
/phpstan.neon.dist export-ignore
13+
/phpunit.xml.dist export-ignore
14+
/.github export-ignore
15+
/Tests export-ignore
16+
/WordPress/Tests export-ignore
1317

1418
#
1519
# Auto detect text files and perform LF normalization
16-
# http://davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
20+
# https://pablorsk.medium.com/be-a-git-ninja-the-gitattributes-file-e58c07c9e915
1721
#
1822
* text=auto
1923

.github/CONTRIBUTING.md

Lines changed: 68 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ Bug reports containing a minimal code sample which can be used to reproduce the
1111

1212
## Upstream Issues
1313

14-
Since WPCS employs many sniffs that are part of PHPCS, sometimes an issue will be caused by a bug in PHPCS and not in WPCS itself. If the error message in question doesn't come from a sniff whose name starts with `WordPress`, the issue is probably a bug in PHPCS itself, and should be [reported there](https://github.com/squizlabs/PHP_CodeSniffer/issues).
14+
Since WordPressCS employs many sniffs that are part of PHP_CodeSniffer itself or PHPCSExtra, sometimes an issue will be caused by a bug in PHPCS or PHPCSExtra and not in WordPressCS itself.
15+
If the error message in question doesn't come from a sniff whose name starts with `WordPress`, the issue is probably a bug in PHPCS or PHPCSExtra.
16+
17+
* Bugs for sniffs starting with `Generic`, `PEAR`, `PSR1`, `PSR2`, `PSR12`, `Squiz` or `Zend` should be [reported to PHPCS](https://github.com/squizlabs/PHP_CodeSniffer/issues).
18+
* Bugs for sniffs starting with `Modernize`, `NormalizedArrays` or `Universal` should be [reported to PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra/issues).
1519

1620
# Contributing patches and new features
1721

1822
## Branches
1923

20-
Ongoing development will be done in the `develop` branch with merges done into `master` once considered stable.
21-
22-
To contribute an improvement to this project, fork the repo and open a pull request to the `develop` branch. Alternatively, if you have push access to this repo, create a feature branch prefixed by `feature/` and then open an intra-repo PR from that branch to `develop`.
24+
Ongoing development will be done in the `develop` branch with merges to `main` once considered stable.
2325

24-
Once a commit is made to `develop`, a PR should be opened from `develop` into `master` and named "Next release". This PR will provide collaborators with a forum to discuss the upcoming stable release.
26+
To contribute an improvement to this project, fork the repo, run `composer install`, make your changes to the code, run the unit tests and code style checks by running `composer check-all`, and if all is good, open a pull request to the `develop` branch.
27+
Alternatively, if you have push access to this repo, create a feature branch prefixed by `feature/` and then open an intra-repo PR from that branch to `develop`.
2528

2629
# Considerations when writing sniffs
2730

@@ -32,105 +35,87 @@ Only make a property `public` if that is the intended behaviour.
3235

3336
When you introduce new `public` sniff properties, or your sniff extends a class from which you inherit a `public` property, please don't forget to update the [public properties wiki page](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) with the relevant details once your PR has been merged into the `develop` branch.
3437

35-
## Whitelist comments
36-
37-
> **Important**:
38-
> PHPCS 3.2.0 introduced new selective ignore annotations, which can be considered an improved version of the whitelist mechanism which WPCS contains.
39-
>
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.
41-
>
42-
> With that in mind, (new) sniffs should not introduce new WPCS native whitelist comments.
43-
44-
4538
# Unit Testing
4639

4740
## Pre-requisites
4841
* WordPress-Coding-Standards
49-
* PHP_CodeSniffer 3.3.1 or higher
42+
* PHP_CodeSniffer 3.7.2 or higher
43+
* PHPCSUtils 1.0.8 or higher
44+
* PHPCSExtra 1.1.0 or higher
5045
* PHPUnit 4.x, 5.x, 6.x or 7.x
5146

52-
The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test suite for unit testing the sniffs.
53-
54-
Presuming you have installed `PHP_CodeSniffer` and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`.
55-
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.
47+
The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test framework for unit testing the sniffs.
5848

59-
If you already have PHPUnit installed on your system: Congrats, you're all set.
49+
## Getting ready to test
6050

61-
## Installing PHPUnit
51+
Presuming you have cloned WordPressCS for development, to run the unit tests you need to make sure you have run `composer install` from the root directory of your WordPressCS git clone.
6252

63-
N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._
53+
## Custom develop setups
6454

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.
68-
69-
## Before running the unit tests
70-
71-
N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._
72-
73-
For the unit tests to work, you need to make sure PHPUnit can find your `PHP_CodeSniffer` install.
74-
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.
77-
```xml
78-
<php>
79-
<env name="PHPCS_DIR" value="/path/to/PHP_CodeSniffer/"/>
80-
</php>
81-
```
55+
If you are developing with a stand-alone PHP_CodeSniffer (git clone) installation and want to use that git clone to test WordPressCS, there are three extra things you need to do:
56+
1. Install [PHPCSUtils](https://github.com/PHPCSStandards/PHPCSUtils).
57+
If you are using a git clone of PHPCS, you may want to `git clone` PHPCSUtils as well.
58+
2. Register PHPCSUtils with your stand-alone PHP_CodeSniffer installation by running the following commands:
59+
```bash
60+
phpcs --config-show
61+
```
62+
Copy the value from "installed_paths" and add the path to your local install of PHPCSUtils to it (and the path to WordPressCS if it's not registered with PHPCS yet).
63+
Now use the adjusted value to run:
64+
```bash
65+
phpcs --config-set installed_paths /path/1,/path/2,/path/3
66+
```
67+
3. Make sure PHPUnit can find your `PHP_CodeSniffer` install.
68+
The most straight-forward way to do this is to add a `phpunit.xml` file to the root of your WordPressCS installation and set a `PHPCS_DIR` environment variable from within this file.
69+
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.
70+
```xml
71+
<php>
72+
<env name="PHPCS_DIR" value="/path/to/PHP_CodeSniffer/"/>
73+
</php>
74+
```
8275
8376
## Running the unit tests
8477
85-
* If you didn't install WPCS using Composer, make sure you have registered the directory in which you installed WPCS with PHPCS using:
86-
```sh
87-
phpcs --config-set installed_paths path/to/WPCS
88-
```
89-
* Navigate to the directory in which you installed WPCS.
90-
* To run the unit tests:
91-
```sh
92-
phpunit --filter WordPress --bootstrap="/path/to/PHP_CodeSniffer/tests/bootstrap.php" /path/to/PHP_CodeSniffer/tests/AllTests.php
78+
From the root of your WordPressCS install, run the unit tests like so:
79+
```bash
80+
composer run-tests
9381
94-
# Or if you've installed WPCS with Composer:
95-
composer run-tests
96-
```
82+
# Or if you want to use a globally installed version of PHPUnit:
83+
phpunit --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php
84+
```
9785
9886
Expected output:
9987
```
100-
PHPUnit 7.5.0 by Sebastian Bergmann and contributors.
88+
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
10189
102-
Runtime: PHP 7.2.13
103-
Configuration: /WordPressCS/phpunit.xml
90+
Runtime: PHP 7.4.33
91+
Configuration: /WordPressCS/phpunit.xml.dist
10492
105-
........................................................ 56 / 56 (100%)
93+
......................................................... 57 / 57 (100%)
10694
107-
152 sniff test files generated 487 unique error codes; 52 were fixable (10.68%)
95+
201 sniff test files generated 744 unique error codes; 50 were fixable (6%)
10896
109-
Time: 21.36 seconds, Memory: 22.00MB
97+
Time: 10.19 seconds, Memory: 40.00 MB
11098
111-
OK (56 tests, 0 assertions)
99+
OK (57 tests, 0 assertions)
112100
```
113101
114-
[![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078)
115-
116102
## Unit Testing conventions
117103
118104
If you look inside the `WordPress/Tests` subdirectory, you'll see the structure mimics the `WordPress/Sniffs` subdirectory structure. For example, the `WordPress/Sniffs/PHP/POSIXFunctionsSniff.php` sniff has its unit test class defined in `WordPress/Tests/PHP/POSIXFunctionsUnitTest.php` which checks the `WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc` test case file. See the file naming convention?
119105

120106
Lets take a look at what's inside `POSIXFunctionsUnitTest.php`:
121107
122108
```php
123-
...
124109
namespace WordPressCS\WordPress\Tests\PHP;
125110
126111
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
127112
128-
class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
113+
final class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
129114
130115
/**
131116
* Returns the lines where errors should occur.
132117
*
133-
* @return array <int line number> => <int number of errors>
118+
* @return array<int, int> Key is the line number, value is the number of expected errors.
134119
*/
135120
public function getErrorList() {
136121
return array(
@@ -142,17 +127,18 @@ class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
142127
24 => 1,
143128
26 => 1,
144129
);
145-
146130
}
147-
...
131+
132+
...
133+
}
148134
```
149135
150-
Also note the class name convention. The method `getErrorList()` MUST return an array of line numbers indicating errors (when running `phpcs`) found in `WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc`.
151-
If you run:
136+
Also note the class name convention. The method `getErrorList()` MUST return an array of line numbers indicating errors (when running `phpcs`) found in `WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc`. Similarly, the `getWarningList()` method must return an array of line numbers with the number of expected warnings.
137+
138+
If you run the following from the root directory of your WordPressCS clone:
152139
153140
```sh
154-
$ cd /path-to-cloned/phpcs
155-
$ ./bin/phpcs --standard=Wordpress -s /path/to/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions
141+
$ "vendor/bin/phpcs" --standard=Wordpress -s ./Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions
156142
...
157143
--------------------------------------------------------------------------------
158144
FOUND 7 ERRORS AFFECTING 7 LINES
@@ -163,28 +149,28 @@ FOUND 7 ERRORS AFFECTING 7 LINES
163149
16 | ERROR | eregi() has been deprecated since PHP 5.3 and removed in PHP 7.0,
164150
| | please use preg_match() instead.
165151
| | (WordPress.PHP.POSIXFunctions.ereg_eregi)
166-
18 | ERROR | ereg_replace() has been deprecated since PHP 5.3 and removed in PHP
167-
| | 7.0, please use preg_replace() instead.
152+
18 | ERROR | ereg_replace() has been deprecated since PHP 5.3 and removed in
153+
| | PHP 7.0, please use preg_replace() instead.
168154
| | (WordPress.PHP.POSIXFunctions.ereg_replace_ereg_replace)
169-
20 | ERROR | eregi_replace() has been deprecated since PHP 5.3 and removed in PHP
170-
| | 7.0, please use preg_replace() instead.
155+
20 | ERROR | eregi_replace() has been deprecated since PHP 5.3 and removed in
156+
| | PHP 7.0, please use preg_replace() instead.
171157
| | (WordPress.PHP.POSIXFunctions.ereg_replace_eregi_replace)
172158
22 | ERROR | split() has been deprecated since PHP 5.3 and removed in PHP 7.0,
173159
| | please use explode(), str_split() or preg_split() instead.
174160
| | (WordPress.PHP.POSIXFunctions.split_split)
175-
24 | ERROR | spliti() has been deprecated since PHP 5.3 and removed in PHP 7.0,
176-
| | please use explode(), str_split() or preg_split() instead.
177-
| | (WordPress.PHP.POSIXFunctions.split_spliti)
178-
26 | ERROR | sql_regcase() has been deprecated since PHP 5.3 and removed in PHP
179-
| | 7.0, please use preg_match() instead.
161+
24 | ERROR | spliti() has been deprecated since PHP 5.3 and removed in PHP
162+
| | 7.0, please use explode(), str_split() or preg_split()
163+
| | instead. (WordPress.PHP.POSIXFunctions.split_spliti)
164+
26 | ERROR | sql_regcase() has been deprecated since PHP 5.3 and removed in
165+
| | PHP 7.0, please use preg_match() instead.
180166
| | (WordPress.PHP.POSIXFunctions.ereg_sql_regcase)
181167
--------------------------------------------------------------------------------
182-
....
168+
...
183169
```
184170
You'll see the line number and number of ERRORs we need to return in the `getErrorList()` method.
185171

186172
The `--sniffs=...` directive limits the output to the sniff you are testing.
187173

188174
## Code Standards for this project
189175

190-
The sniffs and test files - not test _case_ files! - for WPCS should be written such that they pass the `WordPress-Extra` and the `WordPress-Docs` code standards using the custom ruleset as found in `/.phpcs.xml.dist`.
176+
The sniffs and test files - not test _case_ files! - for WordPressCS should be written such that they pass the `WordPress-Extra` and the `WordPress-Docs` code standards using the custom ruleset as found in `/.phpcs.xml.dist`.

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ about: Create a report to help us improve
44

55
---
66

7+
<!--
8+
PLEASE FILL OUT THE TEMPLATE COMPLETELY.
9+
BUG REPORTS WHICH CANNOT BE REPRODUCED BASED ON THE INFORMATION PROVIDED WILL BE CLOSED.
10+
-->
11+
712
## Bug Description
813
<!--
914
Please provide a clear and concise description of what the bug is.
@@ -12,36 +17,76 @@ What did you expect to happen? What actually happened?
1217
-->
1318

1419
## Minimal Code Snippet
15-
<!-- Please provide example code that demonstrates the issue. Do NOT paste screenshots of code! -->
20+
<!-- Please provide example code that allows us to reproduce the issue. Do NOT paste screenshots of code! -->
1621

22+
The issue happens when running this command:
23+
```bash
24+
phpcs ...
25+
```
26+
27+
... over a file containing this code:
1728
```php
1829
// Place your code sample here.
1930
```
2031

21-
For bugs with fixers: How was the code fixed? How did you expect the code to be fixed?
32+
<!-- For bugs with fixers: How was the code fixed? How did you expect the code to be fixed? -->
33+
34+
The file was auto-fixed via `phpcbf` to:
35+
```php
36+
// Place your code sample here.
37+
```
38+
39+
... while I expected the code to be fixed to:
40+
```php
41+
// Place your code sample here.
42+
```
2243

2344
## Error Code
2445
<!--
2546
The error code for the sniff that is (or should be) being triggered (you
2647
can see the sniff error codes by running `phpcs` with the `-s` flag).
2748
e.g. `WordPress.PHP.NoSilencedErrors.Discouraged`
2849
50+
Note: only report issues for error codes starting with `WordPress` to this repo!
51+
If the error code starts with `Universal`, `NormalizedArrays` or `Modernize` report the issue to PHPCSExtra.
52+
If the error code starts with `Generic`, `PEAR`, `PSR1`, `PSR2`, `PSR12`, `Squiz` or `Zend` report the issue to PHP_CodeSniffer itself.
53+
2954
You can leave this section empty if you are reporting a false negative.
3055
-->
3156

57+
## Custom Ruleset
58+
<!--
59+
If the issue cannot be reproduced when using `--standard=WordPress` on the command line,
60+
please post the relevant part of your custom ruleset here.
61+
-->
62+
63+
```xml
64+
<?xml version="1.0"?>
65+
<ruleset name="My Custom Standard">
66+
...
67+
</ruleset>
68+
```
69+
3270
## Environment
71+
<!--
72+
To find out the versions used:
73+
* PHP: run `php -v`.
74+
* Packages: run `composer info` or run `composer [global] info` to see the installed versions.
75+
-->
3376

34-
| Question | Answer
35-
| ------------------------| -------
36-
| PHP version | x.y.z
37-
| PHP_CodeSniffer version | x.y.z
38-
| WPCS version | x.y.z
39-
| WPCS install type | e.g. Composer global, Composer project local, git clone, other (please expand)
40-
| IDE (if relevant) | Name and version e.g. PhpStorm 2018.2.2
77+
| Question | Answer
78+
| ------------------------ | -------
79+
| PHP version | x.y.z
80+
| PHP_CodeSniffer version | x.y.z
81+
| WordPressCS version | x.y.z
82+
| PHPCSUtils version | x.y.z
83+
| PHPCSExtra version | x.y.z
84+
| WordPressCS install type | e.g. Composer global, Composer project local, other (please expand)
85+
| IDE (if relevant) | Name and version e.g. PhpStorm 2018.2.2
4186

4287

4388
## Additional Context (optional)
4489
<!-- Add any other context about the problem here. -->
4590

46-
## Tested Against `develop` branch?
47-
- [ ] I have verified the issue still exists in the `develop` branch of WPCS.
91+
## Tested Against `develop` Branch?
92+
- [ ] I have verified the issue still exists in the `develop` branch of WordPressCS.

0 commit comments

Comments
 (0)