Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b4caf96

Browse files
authoredSep 14, 2023
Merge pull request #2386 from WordPress/develop
Release WordPressCS 3.0.1
2 parents bb792cb + 289cf43 commit b4caf96

File tree

8 files changed

+60
-14
lines changed

8 files changed

+60
-14
lines changed
 

Diff for: ‎.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: "https://opencollective.com/thewpcc/contribute/wp-php-63406"

Diff for: ‎.github/release-checklist.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ PR for tracking changes for the x.x.x release. Target release date: **DOW MONTH
6262
- [ ] Tweet, toot, etc about the release.
6363
- [ ] Post about it in Slack.
6464
- [ ] Submit for ["Month in WordPress"][month-in-wp].
65-
65+
- [ ] Submit for the ["Monthy Dev Roundup"][dev-roundup].
6666

6767
[phpcs-releases]: https://github.com/squizlabs/PHP_CodeSniffer/releases
6868
[phpcsutils-releases]: https://github.com/PHPCSStandards/PHPCSUtils/releases
6969
[phpcsextra-releases]: https://github.com/PHPCSStandards/PHPCSExtra/releases
7070
[month-in-wp]: https://make.wordpress.org/community/month-in-wordpress-submissions/
71+
[dev-roundup]: https://github.com/WordPress/developer-blog-content/issues?q=is%3Aissue+label%3A%22Monthly+Roundup%22

Diff for: ‎.github/workflows/basic-qa.yml

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ jobs:
141141
- name: Test the WordPress ruleset
142142
run: $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress
143143

144+
- name: Rename the example ruleset to one which can be used for a ruleset
145+
run: cp phpcs.xml.dist.sample sample.xml
146+
147+
- name: Test the example ruleset
148+
run: $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/example-ruleset-test.inc --standard=./sample.xml
149+
144150
# Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files.
145151
# This is not an exhaustive test, but should give an early indication for typical fixer conflicts.
146152
# If only fixable errors are found, the exit code will be 1, which can be interpreted as success.

Diff for: ‎CHANGELOG.md

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
88

99
_No documentation available about unreleased changes as of yet._
1010

11+
## [3.0.1] - 2023-09-13
12+
13+
### Added
14+
15+
- In WordPressCS 3.0.0, the functionality of the `WordPress.Security.EscapeOutput` sniff was updated to report unescaped message parameters passed to exceptions created in `throw` statements. This specific violation now has a separate error code: `ExceptionNotEscaped`. This will allow users to ignore or exclude that specific error code. Props [@anomiex].
16+
The error code(s) for other escaping issues flagged by the sniff remain unchanged.
17+
18+
### Changed
19+
20+
- Updated the CI workflow to test the example ruleset for issues.
21+
- Funding files and updates in the Readme about funding the project.
22+
23+
### Fixed
24+
25+
- Fixed a sniff name in the `phpcs.xml.dist.sample` file (case-sensitive sniff name). Props [@dawidurbanski].
26+
27+
1128
## [3.0.0] - 2023-08-21
1229

1330
### Important information about this release:
@@ -1556,6 +1573,7 @@ Initial tagged release.
15561573
[Composer PHPCS plugin]: https://github.com/PHPCSStandards/composer-installer
15571574

15581575
[Unreleased]: https://github.com/WordPress/WordPress-Coding-Standards/compare/main...HEAD
1576+
[3.0.1]: https://github.com/WordPress/WordPress-Coding-Standards/compare/3.0.0...3.0.1
15591577
[3.0.0]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2.3.0...3.0.0
15601578
[2.3.0]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2.2.1...2.3.0
15611579
[2.2.1]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2.2.0...2.2.1
@@ -1585,8 +1603,10 @@ Initial tagged release.
15851603
[0.3.0]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2013-10-06...0.3.0
15861604
[2013-10-06]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2013-06-11...2013-10-06
15871605

1606+
[@anomiex]: https://github.com/anomiex
15881607
[@ckanitz]: https://github.com/ckanitz
15891608
[@craigfrancis]: https://github.com/craigfrancis
1609+
[@dawidurbanski]: https://github.com/dawidurbanski
15901610
[@desrosj]: https://github.com/desrosj
15911611
[@grappler]: https://github.com/grappler
15921612
[@Ipstenu]: https://github.com/Ipstenu

Diff for: ‎README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@
3939
* [Fixing errors or ignoring them](#fixing-errors-or-ignoring-them)
4040
+ [Tools shipped with WordPressCS](#tools-shipped-with-wordpresscs)
4141
* [Contributing](#contributing)
42+
* [Funding](#funding)
4243
* [License](#license)
4344

45+
---
4446

4547
## Introduction
4648

4749
This project is a collection of [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) rules (sniffs) to validate code developed for WordPress. It ensures code quality and adherence to coding conventions, especially the official [WordPress Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/).
4850

51+
This project needs funding. [Find out how you can help](#funding).
52+
4953
## Minimum Requirements
5054

5155
The WordPress Coding Standards package requires:
@@ -62,7 +66,7 @@ For the best results, it is recommended to also ensure the following additional
6266

6367
## Installation
6468

65-
As of WordPressCS 3.0.0, installation via Composer using the below instructions is the only supported type of installation.
69+
As of [WordPressCS 3.0.0](https://make.wordpress.org/core/2023/08/21/wordpresscs-3-0-0-is-now-available/), installation via Composer using the below instructions is the only supported type of installation.
6670

6771
[Composer](https://getcomposer.org/) will automatically install the project dependencies and register the rulesets from WordPressCS and other external standards with PHP_CodeSniffer using the [Composer PHPCS plugin](https://github.com/PHPCSStandards/composer-installer).
6872

@@ -248,6 +252,10 @@ At this moment, WordPressCS offer the following tools:
248252

249253
See [CONTRIBUTING](.github/CONTRIBUTING.md), including information about [unit testing](.github/CONTRIBUTING.md#unit-testing) the standard.
250254

255+
## Funding
256+
257+
If you want to sponsor the work on WordPressCS, you can do so by donating to the [WP PHP Open Collective](https://opencollective.com//thewpcc/contribute/wp-php-63406).
258+
251259
## License
252260

253261
See [LICENSE](LICENSE) (MIT).

Diff for: ‎Tests/RulesetCheck/example-ruleset-test.inc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* File which should not yield any errors when using the example ruleset.
4+
*
5+
* @package My\Prefix\Package
6+
*/
7+
8+
$my_prefix_var = 'hello';

Diff for: ‎WordPress/Sniffs/Security/EscapeOutputSniff.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public function process_token( $stackPtr ) {
263263

264264
// Examine each parameter individually.
265265
foreach ( $params as $param ) {
266-
$this->check_code_is_escaped( $param['start'], ( $param['end'] + 1 ) );
266+
$this->check_code_is_escaped( $param['start'], ( $param['end'] + 1 ), 'ExceptionNotEscaped' );
267267
}
268268

269269
return $end;
@@ -446,12 +446,13 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
446446
*
447447
* @since 3.0.0 Split off from the process_token() method.
448448
*
449-
* @param int $start The position to start checking from.
450-
* @param int $end The position to stop the check at.
449+
* @param int $start The position to start checking from.
450+
* @param int $end The position to stop the check at.
451+
* @param string $code Code to use for the PHPCS error.
451452
*
452453
* @return int Integer stack pointer to skip forward.
453454
*/
454-
protected function check_code_is_escaped( $start, $end ) {
455+
protected function check_code_is_escaped( $start, $end, $code = 'OutputNotEscaped' ) {
455456
/*
456457
* Check for a ternary operator.
457458
* We only need to do this here if this statement is lacking parenthesis.
@@ -532,7 +533,7 @@ protected function check_code_is_escaped( $start, $end ) {
532533

533534
// Handle PHP 8.0+ match expressions.
534535
if ( \T_MATCH === $this->tokens[ $i ]['code'] ) {
535-
$match_valid = $this->walk_match_expression( $i );
536+
$match_valid = $this->walk_match_expression( $i, $code );
536537
if ( false === $match_valid ) {
537538
// Live coding or parse error. Shouldn't be possible as PHP[CS] will tokenize the keyword as `T_STRING` in that case.
538539
break; // @codeCoverageIgnore
@@ -553,7 +554,7 @@ protected function check_code_is_escaped( $start, $end ) {
553554
$array_items = PassedParameters::getParameters( $this->phpcsFile, $i, 0, true );
554555
if ( ! empty( $array_items ) ) {
555556
foreach ( $array_items as $array_item ) {
556-
$this->check_code_is_escaped( $array_item['start'], ( $array_item['end'] + 1 ) );
557+
$this->check_code_is_escaped( $array_item['start'], ( $array_item['end'] + 1 ), $code );
557558
}
558559
}
559560

@@ -699,7 +700,7 @@ protected function check_code_is_escaped( $start, $end ) {
699700
$formatting_params = PassedParameters::getParameters( $this->phpcsFile, $i );
700701
if ( ! empty( $formatting_params ) ) {
701702
foreach ( $formatting_params as $format_param ) {
702-
$this->check_code_is_escaped( $format_param['start'], ( $format_param['end'] + 1 ) );
703+
$this->check_code_is_escaped( $format_param['start'], ( $format_param['end'] + 1 ), $code );
703704
}
704705
}
705706

@@ -754,7 +755,7 @@ protected function check_code_is_escaped( $start, $end ) {
754755
$this->phpcsFile->addError(
755756
"All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '%s'.",
756757
$ptr,
757-
'OutputNotEscaped',
758+
$code,
758759
array( $content )
759760
);
760761
}
@@ -825,11 +826,12 @@ private function find_long_ternary( $start, $end ) {
825826
*
826827
* @since 3.0.0
827828
*
828-
* @param int $stackPtr Pointer to a T_MATCH token.
829+
* @param int $stackPtr Pointer to a T_MATCH token.
830+
* @param string $code Code to use for the PHPCS error.
829831
*
830832
* @return int|false Stack pointer to skip to or FALSE if the match expression contained a parse error.
831833
*/
832-
private function walk_match_expression( $stackPtr ) {
834+
private function walk_match_expression( $stackPtr, $code ) {
833835
if ( ! isset( $this->tokens[ $stackPtr ]['scope_opener'], $this->tokens[ $stackPtr ]['scope_closer'] ) ) {
834836
// Parse error/live coding. Shouldn't be possible as PHP[CS] will tokenize the keyword as `T_STRING` in that case.
835837
return false; // @codeCoverageIgnore
@@ -889,7 +891,7 @@ private function walk_match_expression( $stackPtr ) {
889891
}
890892

891893
// Now check that the value returned by this match "leaf" is correctly escaped.
892-
$this->check_code_is_escaped( $item_start, $item_end );
894+
$this->check_code_is_escaped( $item_start, $item_end, $code );
893895

894896
// Independently of whether or not the check was succesfull or ran into (parse error) problems,
895897
// always skip to the identified end of the item.

Diff for: ‎phpcs.xml.dist.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
<rule ref="WordPress.WP.GlobalVariablesOverride">
147147
<exclude-pattern>/path/to/Tests/*Test\.php</exclude-pattern>
148148
</rule>
149-
<rule ref="WordPress.Files.Filename">
149+
<rule ref="WordPress.Files.FileName">
150150
<exclude-pattern>/path/to/Tests/*Test\.php</exclude-pattern>
151151
</rule>
152152

0 commit comments

Comments
 (0)