Skip to content

Commit 1b8960e

Browse files
authored
Merge pull request #793 from Automattic/release/3.0.0
2 parents b8610e3 + fad2290 commit 1b8960e

File tree

116 files changed

+503
-920
lines changed

Some content is hidden

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

116 files changed

+503
-920
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/.gitattributes export-ignore
99
/.gitignore export-ignore
1010
/.phpcs.xml.dist export-ignore
11+
/phpstan.neon.dist export-ignore
1112
/phpunit.xml.dist export-ignore
1213
/.github export-ignore
1314
/bin export-ignore

.github/CONTRIBUTING.md

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ Since VIPCS employs many sniffs that are part of PHPCS, and makes use of WordPre
1717

1818
To determine where best to report the bug, use the first part of the sniff name:
1919

20-
Sniffname starts with | Report to
20+
Sniff name starts with | Report to
2121
--- | ---
2222
`Generic` | [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/issues/)
2323
`PSR2` | [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/issues/)
2424
`Squiz` | [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/issues/)
25+
`Universal` | [PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra/issues/)
2526
`VariableAnalysis` | [VariableAnalysis](https://github.com/sirbrillig/phpcs-variable-analysis/issues/)
2627
`WordPress` | [WordPressCS](https://github.com/WordPress/WordPress-Coding-Standards/issues/)
2728
`WordPressVIPMinimum` | [VIPCS](https://github.com/Automattic/VIP-Coding-Standards/issues/) (this repo)
@@ -44,7 +45,7 @@ After `composer install`, you can do:
4445

4546
## Branches
4647

47-
Ongoing development will be done in feature branches then pulled against the `develop` branch and follows a typical _git-flow_ approach, where merges to `master` only happen when a new release is made.
48+
Ongoing development will be done in feature branches then pulled against the `develop` branch and follows a typical _git-flow_ approach, where merges to `main` only happen when a new release is made.
4849

4950
To contribute an improvement to this project, fork the repo and open a pull request to the relevant branch. Alternatively, if you have push access to this repo, create a feature branch prefixed by `fix/` (followed by the issue number) or `add/` and then open a PR from that branch to the default (`develop`) branch.
5051

@@ -64,6 +65,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class
6465
### Pre-requisites
6566
* VIP Coding Standards
6667
* WordPress-Coding-Standards
68+
* PHPCSUtils 1.x
6769
* PHP_CodeSniffer 3.x
6870
* PHPUnit 4.x, 5.x, 6.x or 7.x
6971

@@ -89,7 +91,7 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your VI
8991
<?xml version="1.0" encoding="UTF-8"?>
9092
<phpunit
9193
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
92-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
94+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
9395
backupGlobals="true"
9496
bootstrap="./tests/bootstrap.php"
9597
beStrictAboutTestsThatDoNotTestAnything="false"
@@ -111,49 +113,52 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your VI
111113
* To run the unit tests:
112114

113115
```sh
114-
phpunit --filter WordPressVIPMinimum $PHPCS_DIR/tests/AllTests.php
116+
composer test
115117
```
116118

117119
Expected output:
118120
```
119121
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
120122

121-
.......................................... 42 / 42 (100%)
123+
........................................ 40 / 40 (100%)
122124

123-
43 sniff test files generated 117 unique error codes; 0 were fixable (0%)
125+
45 sniff test files generated 175 unique error codes; 0 were fixable (0%)
124126

125-
Time: 246 ms, Memory: 32.00 MB
127+
Time: 150 ms, Memory: 20.00 MB
128+
129+
OK (40 tests, 0 assertions)
126130
```
127131
128132
### Unit Testing conventions
129133
130-
If you look inside the `WordPressVIPMinimum/Tests` subdirectory, you'll see the structure mimics the `WordPressVIPMinimum/Sniffs` subdirectory structure. For example, the `WordPressVIPMinimum/Sniffs/VIP/WPQueryParams.php` sniff has its unit test class defined in `WordPressVIPMinimum/Tests/VIP/WPQueryParamsUnitTest.php` which checks the `WordPressVIPMinimum/Tests/VIP/WPQueryParamsUnitTest.inc` test case file. See the file naming convention?
134+
If you look inside the `WordPressVIPMinimum/Tests` subdirectory, you'll see the structure mimics the `WordPressVIPMinimum/Sniffs` subdirectory structure. For example, the `WordPressVIPMinimum/Sniffs/Performance/WPQueryParams.php` sniff has its unit test class defined in `WordPressVIPMinimum/Tests/Performance/WPQueryParamsUnitTest.php` which checks the `WordPressVIPMinimum/Tests/Performance/WPQueryParamsUnitTest.inc` test case file. See the file naming convention?
131135
132-
Lets take a look at what's inside `WPQueryParamsUnitTest.php`:
136+
Let's take a look at what's inside `WPQueryParamsUnitTest.php`:
133137
134138
```php
135139
...
136-
namespace WordPressVIPMinimum\Tests\VIP;
140+
namespace WordPressVIPMinimum\Tests\Performance;
137141
138142
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
139143
140144
/**
141145
* Unit test class for the WP_Query params sniff.
142146
*
143-
* @package VIPCS\WordPressVIPMinimum
147+
* @covers \WordPressVIPMinimum\Sniffs\Performance\WPQueryParamsSniff
144148
*/
145149
class WPQueryParamsUnitTest extends AbstractSniffUnitTest {
146150
147151
/**
148152
* Returns the lines where errors should occur.
149153
*
150-
* @return array <int line number> => <int number of errors>
154+
* @return array<int, int> Key is the line number, value is the number of expected errors.
151155
*/
152156
public function getErrorList() {
153-
return array(
157+
return [
154158
5 => 1,
155159
17 => 1,
156-
);
160+
31 => 1,
161+
];
157162
}
158163
...
159164
```
@@ -162,24 +167,35 @@ Also note the class name convention. The method `getErrorList()` MUST return an
162167
If you run:
163168

164169
```sh
165-
$ cd /path-to-cloned/phpcs
166-
$ ./bin/phpcs --standard=WordPressVIPMinimum -s --sniffs=WordPressVIPMinimum.VIP.WPQueryParams /path/to/WordPressVIPMinimum/Tests/VIP/WPQueryParamsUnitTest.inc
167-
...
168-
E 1 / 1 (100%)
169-
170-
171-
172-
FILE: /path/to/vipcs/WordPressVIPMinimum/Tests/VIP/WPQueryParamsUnitTest.inc
173-
--------------------------------------------------------------------------------------------------------------------------------
174-
FOUND 2 ERRORS AND 2 WARNINGS AFFECTING 4 LINES
175-
--------------------------------------------------------------------------------------------------------------------------------
176-
4 | WARNING | Using `post__not_in` should be done with caution. (WordPressVIPMinimum.VIP.WPQueryParams.post__not_in)
177-
5 | ERROR | Setting `suppress_filters` to `true` is probihited.
178-
| | (WordPressVIPMinimum.VIP.WPQueryParams.suppressFiltersTrue)
179-
11 | WARNING | Using `post__not_in` should be done with caution. (WordPressVIPMinimum.VIP.WPQueryParams.post__not_in)
180-
17 | ERROR | Setting `suppress_filters` to `true` is probihited.
181-
| | (WordPressVIPMinimum.VIP.WPQueryParams.suppressFiltersTrue)
182-
--------------------------------------------------------------------------------------------------------------------------------
170+
$ cd /path/to/vipcs
171+
$ ./vendor/bin/phpcs --standard=WordPressVIPMinimum -s --sniffs=WordPressVIPMinimum.Performance.WPQueryParams WordPressVIPMinimum/Tests/Performance/WPQueryParamsUnitTest.inc
172+
173+
FILE: /path/to/vipcs/WordPressVIPMinimum/Tests/Performance/WPQueryParamsUnitTest.inc
174+
------------------------------------------------------------------------------------------------------------------------------------------------------
175+
FOUND 3 ERRORS AND 5 WARNINGS AFFECTING 8 LINES
176+
------------------------------------------------------------------------------------------------------------------------------------------------------
177+
4 | WARNING | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see
178+
| | https://wpvip.com/documentation/performance-improvements-by-removing-usage-of-post__not_in/ for more information.
179+
| | (WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in)
180+
5 | ERROR | Setting `suppress_filters` to `true` is prohibited.
181+
| | (WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters)
182+
11 | WARNING | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see
183+
| | https://wpvip.com/documentation/performance-improvements-by-removing-usage-of-post__not_in/ for more information.
184+
| | (WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in)
185+
17 | ERROR | Setting `suppress_filters` to `true` is prohibited.
186+
| | (WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters)
187+
21 | WARNING | Using exclusionary parameters, like exclude, in calls to get_posts() should be done with caution, see
188+
| | https://wpvip.com/documentation/performance-improvements-by-removing-usage-of-post__not_in/ for more information.
189+
| | (WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude)
190+
29 | WARNING | Using exclusionary parameters, like exclude, in calls to get_posts() should be done with caution, see
191+
| | https://wpvip.com/documentation/performance-improvements-by-removing-usage-of-post__not_in/ for more information.
192+
| | (WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude)
193+
30 | WARNING | Using exclusionary parameters, like exclude, in calls to get_posts() should be done with caution, see
194+
| | https://wpvip.com/documentation/performance-improvements-by-removing-usage-of-post__not_in/ for more information.
195+
| | (WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude)
196+
31 | ERROR | Setting `suppress_filters` to `true` is prohibited.
197+
| | (WordPressVIPMinimum.Performance.WPQueryParams.SuppressFilters_suppress_filters)
198+
------------------------------------------------------------------------------------------------------------------------------------------------------
183199
....
184200
```
185201
You'll see the line number and number of ERRORs we need to return in the `getErrorList()` method.
@@ -190,23 +206,26 @@ The `--sniffs=...` directive limits the output to the sniff you are testing.
190206

191207
The ruleset tests, previously named here as _integration tests_, are our way of ensuring that _rulesets_ do check for the violations we expect them to.
192208

193-
An example where it might not would be when a ruleset references a local sniff or a sniff from upstream (WPCS or PHPCS), but that the violation code, sniff name or category name has changed. Without a ruleset test, this would go unnoticed.
209+
An example where it might not would be when a ruleset references a local sniff or a sniff from upstream (WordPressCS or PHPCS), but that the violation code, sniff name or category name has changed. Without a ruleset test, this would go unnoticed.
194210

195-
The `composer check` or `composer test-ruleset` commands run the `ruleset-test.php` files (one for each standard), which internally run `phpcs` against the "dirty" test files (`ruleset-test.inc`), and looks out for a known number of errors, warnings, and messages on each line. This is then compared against the expected errors, warnings and messages to see if there are any missing or unexpected violations or difference in messages.
211+
The `composer check` or `composer test-ruleset` commands run the `ruleset-test.php` files (one for each ruleset), which internally run `phpcs` against the "dirty" test files (`ruleset-test.inc`), and looks out for a known number of errors, warnings, and messages on each line. This is then compared against the expected errors, warnings, and messages to see if there are any missing or unexpected violations or difference in messages.
196212

197213
When adding or changing a sniff, the ruleset test files should be updated to match.
198214

199215
## Releases
200216

201-
- In a `changelog/x.y.z` branch off of `develop`, update the `CHANGELOG.md` with a list of all of the changes following the keepachangelog.com format. Include PR references and GitHub username props.
202-
- Create a PR of `develop` <-- `changelog/x.y.z`, but do not merge until ready to release.
203-
- Create a PR of `master` <-- `develop`, and copy-paste the [`release-template.md`](https://github.com/Automattic/VIP-Coding-Standards/blob/develop/.github/ISSUE_TEMPLATE/release-template.md) contents.
204-
- When ready to release, merge the change log PR into `develop`, then merge the `develop` into `master` PR.
205-
- Tag the commit in `master` with the appropriate version number. Ideally, have it signed.
206-
- Close the current milestone.
217+
- Create a `release/x.y.z` branch off of `develop`.
218+
- In a `release/x.y.z-changelog` branch off of `release/x.y.z`, update the `CHANGELOG.md` with a list of all of the changes following the keepachangelog.com format. Include PR references and GitHub username props.
219+
- Create a PR of `release/x.y.z` <-- `release/x.y.z-changelog`, but do not merge until ready to release.
220+
- Create any other last-minute PRs as necessary, such as documentation updates, against the release branch.
221+
- When ready to release, merge the changelog and other branches into `release/x.y.z`.
222+
- Create a PR of `main` <-- `release/x.y.z`, and copy-paste the [`release-template.md`](https://github.com/Automattic/VIP-Coding-Standards/blob/develop/.github/ISSUE_TEMPLATE/release-template.md) contents.
223+
- When ready to release, merge `release/x.y.z` into `main`. Undelete the release branch after merging.
224+
- Tag the commit in `main` with the appropriate version number. Ideally, have it signed.
207225
- Open a new milestone for the next release.
208226
- If any open PRs/issues which were milestoned for this release do not make it into the release, update their milestone.
209-
- Write a Lobby post to inform VIP customers about the release, including the date when the Review Bot will be updated (usually about 1.5 weeks after the VIPCS release).
227+
- Close the current milestone.
228+
- Create a PR of `develop` <-- `release/x.y.z` and merge in when ready.
229+
- Write a Lobby post to inform VIP customers about the release, including the date when the VIP Code Analysis Bot will be updated (usually about 2 weeks after the VIPCS release).
210230
- Write an internal P2 post.
211-
- Open a PR to update the [Review Bot dependencies](https://github.com/Automattic/vip-go-ci/blob/master/tools-init.sh).
212-
231+
- Open a PR to update the [VIP Code Analysis bot dependencies](https://github.com/Automattic/vip-go-ci/blob/master/tools-init.sh).

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Use `php -v` and `composer show` to get versions.
4444
| ------------------------ | -------
4545
| PHP version | x.y.z
4646
| PHP_CodeSniffer version | x.y.z
47+
| PHPCSUtils version | x.y.z
4748
| VIPCS version | x.y.z
4849
| WordPressCS version | x.y.z
4950
| VariableAnalysis version | x.y.z
@@ -52,7 +53,7 @@ Use `php -v` and `composer show` to get versions.
5253

5354
<!-- Add any other context about the problem here. -->
5455

55-
## Tested Against `master` branch?
56+
## Tested Against `main` branch?
5657

57-
- [ ] I have verified the issue still exists in the `master` branch of VIPCS.
58+
- [ ] I have verified the issue still exists in the `main` branch of VIPCS.
5859
- [ ] I have verified the issue still exists in the `develop` branch of VIPCS.

.github/ISSUE_TEMPLATE/release-template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ assignees: GaryJones, rebeccahum
1313

1414
PR for tracking changes for the X.Y.Z release. Target release date: DOW DD MMMM YYYY.
1515

16-
- [ ] Scan WordPress (or just wp-admin folder) with prior version and compare results against new release for potential new bugs.
16+
- [ ] Scan WordPress (or just wp-admin folder) with prior version and compare results against new release for potential new bugs.
1717
- [ ] Add change log for this release: PR #XXX
1818
- [ ] Double-check whether any dependencies need bumping.
1919
- [ ] Merge this PR.
20-
- [ ] Add signed release tag against `master`.
20+
- [ ] Add signed release tag against `main`.
2121
- [ ] Close the current milestone.
2222
- [ ] Open a new milestone for the next release.
2323
- [ ] If any open PRs/issues which were milestoned for this release do not make it into the release, update their milestone.

.github/workflows/basics.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install PHP
3030
uses: shivammathur/setup-php@v2
3131
with:
32-
php-version: '7.4'
32+
php-version: 'latest'
3333
coverage: none
3434
tools: cs2pr
3535

@@ -76,3 +76,31 @@ jobs:
7676
# At a later stage the documentation check can be activated.
7777
- name: Check sniff feature completeness
7878
run: composer feature-completeness
79+
80+
phpstan:
81+
name: "PHPStan"
82+
83+
runs-on: "ubuntu-latest"
84+
85+
steps:
86+
- name: Checkout code
87+
uses: actions/checkout@v3
88+
89+
- name: Install PHP
90+
uses: shivammathur/setup-php@v2
91+
with:
92+
php-version: '7.4'
93+
coverage: none
94+
tools: phpstan
95+
96+
# Install dependencies and handle caching in one go.
97+
# Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized.
98+
# @link https://github.com/marketplace/actions/install-composer-dependencies
99+
- name: Install Composer dependencies
100+
uses: "ramsey/composer-install@v2"
101+
with:
102+
# Bust the cache at least once a month - output format: YYYY-MM.
103+
custom-cache-suffix: $(date -u "+%Y-%m")
104+
105+
- name: Run PHPStan
106+
run: phpstan analyse

0 commit comments

Comments
 (0)