Skip to content

Commit 5003882

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into develop
* upstream/develop: (428 commits) Rulesets: update schema URL GH Actions: use the xmllint-validate action runner and enhance checks (WordPress#2522) AbstractFunctionParameterSniff: fix first class callables and function imports (WordPress#2518) DontExtractStandard.xml file creation (WordPress#2456) Add documentation for WordPress.NamingConventions.ValidVariableName (WordPress#2457) Remove unused variables from a few sniffs (WordPress#2514) I18nTextDomainFixer: remove unnecessary variable initialization (WordPress#2513) GH Actions: Bump codecov/codecov-action from 4 to 5 (WordPress#2510) GH Actions: PHP 8.4 has been released CS/QA: remove redundant condition GH Actions: use explicit PHPStan major Various sniffs: simplify skipping the rest of the file GH Actions: always quote variables Release checklist: add new action item AbstractClassRestrictionsSniff: fix insufficient defensive coding (WordPress#2500) ✨ New WordPress.WP.GetMetaSingle sniff (WordPress#2465) Fix typo in AbstractFunctionRestrictionsSniff::is_targetted_token() DocBlock (WordPress#2477) Fix typos (WordPress#2472) Documentation: capitalization consistency fixes (WordPress#2469) [Documentation]: WordPress.DB.PreparedSQL (WordPress#2454) ...
2 parents fd4a50c + 16b9992 commit 5003882

File tree

305 files changed

+11551
-6586
lines changed

Some content is hidden

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

305 files changed

+11551
-6586
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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
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-
/.gitattributes export-ignore
8-
/.gitignore export-ignore
9-
/.phpcs.xml.dist export-ignore
10-
/phpunit.xml.dist export-ignore
11-
/.github export-ignore
12-
/bin export-ignore
13-
/Tests export-ignore
14-
/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
1517

1618
#
1719
# Auto detect text files and perform LF normalization

.github/CONTRIBUTING.md

Lines changed: 69 additions & 73 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/PHPCSStandards/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

@@ -36,91 +39,83 @@ When you introduce new `public` sniff properties, or your sniff extends a class
3639

3740
## Pre-requisites
3841
* WordPress-Coding-Standards
39-
* PHP_CodeSniffer 3.7.1 or higher
40-
* PHPUnit 4.x, 5.x, 6.x or 7.x
41-
42-
The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test suite for unit testing the sniffs.
43-
44-
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`.
45-
46-
> 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.
47-
> Other than that, you're all set already as Composer will have installed PHPUnit for you.
48-
49-
If you already have PHPUnit installed on your system: Congrats, you're all set.
42+
* PHP_CodeSniffer 3.9.0 or higher
43+
* PHPCSUtils 1.0.10 or higher
44+
* PHPCSExtra 1.2.1 or higher
45+
* PHPUnit 4.x - 9.x
5046

51-
## Installing PHPUnit
47+
The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test framework for unit testing the sniffs.
5248

53-
N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._
49+
## Getting ready to test
5450

55-
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.
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.
5652

57-
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.
53+
## Custom develop setups
5854

59-
## Before running the unit tests
60-
61-
N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._
62-
63-
For the unit tests to work, you need to make sure PHPUnit can find your `PHP_CodeSniffer` install.
64-
65-
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.
66-
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.
67-
```xml
68-
<php>
69-
<env name="PHPCS_DIR" value="/path/to/PHP_CodeSniffer/"/>
70-
</php>
71-
```
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+
```
7275
7376
## Running the unit tests
7477
75-
* If you didn't install WPCS using Composer, make sure you have registered the directory in which you installed WPCS with PHPCS using:
76-
```sh
77-
phpcs --config-set installed_paths path/to/WPCS
78-
```
79-
* Navigate to the directory in which you installed WPCS.
80-
* To run the unit tests:
81-
```sh
82-
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
8381
84-
# Or if you've installed WPCS with Composer:
85-
composer run-tests
86-
```
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+
```
8785
8886
Expected output:
8987
```
90-
PHPUnit 7.5.0 by Sebastian Bergmann and contributors.
88+
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.
9189
92-
Runtime: PHP 7.2.13
93-
Configuration: /WordPressCS/phpunit.xml
90+
Runtime: PHP 8.3.0
91+
Configuration: /WordPressCS/phpunit.xml.dist
9492
95-
........................................................ 56 / 56 (100%)
93+
......................................................... 57 / 57 (100%)
9694
97-
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%)
9896
99-
Time: 21.36 seconds, Memory: 22.00MB
97+
Time: 10.19 seconds, Memory: 40.00 MB
10098
101-
OK (56 tests, 0 assertions)
99+
OK (57 tests, 0 assertions)
102100
```
103101
104-
[![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078)
105-
106102
## Unit Testing conventions
107103
108104
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?
109105

110106
Lets take a look at what's inside `POSIXFunctionsUnitTest.php`:
111107
112108
```php
113-
...
114109
namespace WordPressCS\WordPress\Tests\PHP;
115110
116111
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
117112
118-
class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
113+
final class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
119114
120115
/**
121116
* Returns the lines where errors should occur.
122117
*
123-
* @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.
124119
*/
125120
public function getErrorList() {
126121
return array(
@@ -132,17 +127,18 @@ class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
132127
24 => 1,
133128
26 => 1,
134129
);
135-
136130
}
137-
...
131+
132+
...
133+
}
138134
```
139135
140-
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`.
141-
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:
142139
143140
```sh
144-
$ cd /path-to-cloned/phpcs
145-
$ ./bin/phpcs --standard=Wordpress -s /path/to/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions
141+
$ "vendor/bin/phpcs" --standard=Wordpress -s ./WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions
146142
...
147143
--------------------------------------------------------------------------------
148144
FOUND 7 ERRORS AFFECTING 7 LINES
@@ -153,28 +149,28 @@ FOUND 7 ERRORS AFFECTING 7 LINES
153149
16 | ERROR | eregi() has been deprecated since PHP 5.3 and removed in PHP 7.0,
154150
| | please use preg_match() instead.
155151
| | (WordPress.PHP.POSIXFunctions.ereg_eregi)
156-
18 | ERROR | ereg_replace() has been deprecated since PHP 5.3 and removed in PHP
157-
| | 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.
158154
| | (WordPress.PHP.POSIXFunctions.ereg_replace_ereg_replace)
159-
20 | ERROR | eregi_replace() has been deprecated since PHP 5.3 and removed in PHP
160-
| | 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.
161157
| | (WordPress.PHP.POSIXFunctions.ereg_replace_eregi_replace)
162158
22 | ERROR | split() has been deprecated since PHP 5.3 and removed in PHP 7.0,
163159
| | please use explode(), str_split() or preg_split() instead.
164160
| | (WordPress.PHP.POSIXFunctions.split_split)
165-
24 | ERROR | spliti() has been deprecated since PHP 5.3 and removed in PHP 7.0,
166-
| | please use explode(), str_split() or preg_split() instead.
167-
| | (WordPress.PHP.POSIXFunctions.split_spliti)
168-
26 | ERROR | sql_regcase() has been deprecated since PHP 5.3 and removed in PHP
169-
| | 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.
170166
| | (WordPress.PHP.POSIXFunctions.ereg_sql_regcase)
171167
--------------------------------------------------------------------------------
172-
....
168+
...
173169
```
174170
You'll see the line number and number of ERRORs we need to return in the `getErrorList()` method.
175171

176172
The `--sniffs=...` directive limits the output to the sniff you are testing.
177173

178174
## Code Standards for this project
179175

180-
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/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: "https://opencollective.com/php_codesniffer"

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ The error code for the sniff that is (or should be) being triggered (you
4747
can see the sniff error codes by running `phpcs` with the `-s` flag).
4848
e.g. `WordPress.PHP.NoSilencedErrors.Discouraged`
4949
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+
5054
You can leave this section empty if you are reporting a false negative.
5155
-->
5256

53-
## Custom ruleset
57+
## Custom Ruleset
5458
<!--
5559
If the issue cannot be reproduced when using `--standard=WordPress` on the command line,
5660
please post the relevant part of your custom ruleset here.
@@ -67,21 +71,22 @@ please post the relevant part of your custom ruleset here.
6771
<!--
6872
To find out the versions used:
6973
* PHP: run `php -v`.
70-
* PHPCS: run `[vendor/bin/]phpcs --version`
71-
* WPCS: run `composer [global] info` for a Composer install.
74+
* Packages: run `composer info` or run `composer [global] info` to see the installed versions.
7275
-->
7376

74-
| Question | Answer
75-
| ------------------------| -------
76-
| PHP version | x.y.z
77-
| PHP_CodeSniffer version | x.y.z
78-
| WPCS version | x.y.z
79-
| WPCS install type | e.g. Composer global, Composer project local, git clone, other (please expand)
80-
| 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
8186

8287

8388
## Additional Context (optional)
8489
<!-- Add any other context about the problem here. -->
8590

86-
## Tested Against `develop` branch?
87-
- [ ] 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.

.github/ISSUE_TEMPLATE/dependency-change.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
name: Dependency Change
3-
about: A reminder to take action when a WPCS dependency changes
3+
about: A reminder to take action when a WordPressCS dependency changes
44

55
---
66

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

99
## Rationale
1010

11-
<!-- Why should this change be made in WPCS? -->
11+
<!-- Why should this change be made in WordPressCS? -->
1212

1313
## References
1414

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ And preferably also code samples of code which shouldn't be flagged.
1717

1818
## Additional context (optional)
1919
<!-- Add any other context or screenshots about the feature request here. -->
20+
21+
- [ ] I intend to create a pull request to implement this feature.

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Dependabot configuration.
2+
#
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
time: "09:00"
13+
open-pull-requests-limit: 5
14+
commit-message:
15+
prefix: "GH Actions:"
16+
labels:
17+
- "Type: Chores/Cleanup"

0 commit comments

Comments
 (0)