Skip to content

Commit b5a4532

Browse files
authored
Merge pull request #1855 from WordPress/develop
Release version 2.2.1
2 parents f90e869 + 9822816 commit b5a4532

16 files changed

+155
-62
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ cache:
88
# Cache directory for more recent Composer versions.
99
- $HOME/.cache/composer/files
1010

11-
language:
12-
- php
11+
language: php
1312

1413
php:
1514
- 5.4
@@ -19,7 +18,8 @@ php:
1918
- 7.1
2019
- 7.2
2120
- 7.3
22-
- "7.4snapshot"
21+
- 7.4
22+
- "nightly"
2323

2424
env:
2525
# `master` is now 3.x.
@@ -114,7 +114,7 @@ jobs:
114114

115115
allow_failures:
116116
# Allow failures for unstable builds.
117-
- php: "7.4snapshot"
117+
- php: "nightly"
118118

119119
before_install:
120120
# Speed up build time by disabling Xdebug.

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ 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+
## [2.2.1] - 2020-02-04
12+
13+
### Added
14+
- Metrics to the `WordPress.Arrays.CommaAfterArrayItem` sniff. These can be displayed using `--report=info`.
15+
- The `sanitize_hex_color()` and the `sanitize_hex_color_no_hash()` functions to the `escapingFunctions` list used by the `WordPress.Security.EscapeOutput` sniff.
16+
17+
### Changed
18+
- The recommended version of the suggested DealerDirect PHPCS Composer plugin is now `^0.6`.
19+
20+
### Fixed
21+
- `WordPress.PHP.NoSilencedErrors`: depending on the custom properties set, the metrics would be different.
22+
- `WordPress.WhiteSpace.ControlStructureSpacing`: fixed undefined index notice for closures with `use`.
23+
- `WordPress.WP.GlobalVariablesOverride`: fixed undefined offset notice when the `treat_files_as_scoped` property would be set to `true`.
24+
- `WordPress.WP.I18n`: fixed a _Trying to access array offset on value of type null_ error when the sniff was run on PHP 7.4 and would encounter a translation function expecting singular and plural texts for which one of these arguments was missing.
1125

1226
## [2.2.0] - 2019-11-11
1327

@@ -1148,6 +1162,7 @@ See the comparison for full list.
11481162
Initial tagged release.
11491163

11501164
[Unreleased]: https://github.com/WordPress/WordPress-Coding-Standards/compare/master...HEAD
1165+
[2.2.1]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2.2.0...2.2.1
11511166
[2.2.0]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2.1.1...2.2.0
11521167
[2.1.1]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2.1.0...2.1.1
11531168
[2.1.0]: https://github.com/WordPress/WordPress-Coding-Standards/compare/2.0.0...2.1.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ When installing the WordPress Coding Standards as a dependency in a larger proje
8282

8383
There are two actively maintained Composer plugins which can handle the registration of standards with PHP_CodeSniffer for you:
8484
* [composer-phpcodesniffer-standards-plugin](https://github.com/higidi/composer-phpcodesniffer-standards-plugin)
85-
* [phpcodesniffer-composer-installer](https://github.com/DealerDirect/phpcodesniffer-composer-installer):"^0.5.0"
85+
* [phpcodesniffer-composer-installer](https://github.com/DealerDirect/phpcodesniffer-composer-installer):"^0.6"
8686

8787
It is strongly suggested to `require` one of these plugins in your project to handle the registration of external standards with PHPCS for you.
8888

WordPress/Sniff.php

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -132,40 +132,42 @@ abstract class Sniff implements PHPCS_Sniff {
132132
* @var array
133133
*/
134134
protected $escapingFunctions = array(
135-
'absint' => true,
136-
'esc_attr__' => true,
137-
'esc_attr_e' => true,
138-
'esc_attr_x' => true,
139-
'esc_attr' => true,
140-
'esc_html__' => true,
141-
'esc_html_e' => true,
142-
'esc_html_x' => true,
143-
'esc_html' => true,
144-
'esc_js' => true,
145-
'esc_sql' => true,
146-
'esc_textarea' => true,
147-
'esc_url_raw' => true,
148-
'esc_url' => true,
149-
'filter_input' => true,
150-
'filter_var' => true,
151-
'floatval' => true,
152-
'highlight_string' => true,
153-
'intval' => true,
154-
'json_encode' => true,
155-
'like_escape' => true,
156-
'number_format' => true,
157-
'rawurlencode' => true,
158-
'sanitize_html_class' => true,
159-
'sanitize_key' => true,
160-
'sanitize_user_field' => true,
161-
'tag_escape' => true,
162-
'urlencode_deep' => true,
163-
'urlencode' => true,
164-
'wp_json_encode' => true,
165-
'wp_kses_allowed_html' => true,
166-
'wp_kses_data' => true,
167-
'wp_kses_post' => true,
168-
'wp_kses' => true,
135+
'absint' => true,
136+
'esc_attr__' => true,
137+
'esc_attr_e' => true,
138+
'esc_attr_x' => true,
139+
'esc_attr' => true,
140+
'esc_html__' => true,
141+
'esc_html_e' => true,
142+
'esc_html_x' => true,
143+
'esc_html' => true,
144+
'esc_js' => true,
145+
'esc_sql' => true,
146+
'esc_textarea' => true,
147+
'esc_url_raw' => true,
148+
'esc_url' => true,
149+
'filter_input' => true,
150+
'filter_var' => true,
151+
'floatval' => true,
152+
'highlight_string' => true,
153+
'intval' => true,
154+
'json_encode' => true,
155+
'like_escape' => true,
156+
'number_format' => true,
157+
'rawurlencode' => true,
158+
'sanitize_hex_color' => true,
159+
'sanitize_hex_color_no_hash' => true,
160+
'sanitize_html_class' => true,
161+
'sanitize_key' => true,
162+
'sanitize_user_field' => true,
163+
'tag_escape' => true,
164+
'urlencode_deep' => true,
165+
'urlencode' => true,
166+
'wp_json_encode' => true,
167+
'wp_kses_allowed_html' => true,
168+
'wp_kses_data' => true,
169+
'wp_kses_post' => true,
170+
'wp_kses' => true,
169171
);
170172

171173
/**

WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public function process_token( $stackPtr ) {
103103
*/
104104
if ( true === $single_line && $item_index === $array_item_count ) {
105105

106+
$this->phpcsFile->recordMetric(
107+
$stackPtr,
108+
'Single line array - comma after last item',
109+
( true === $is_comma ? 'yes' : 'no' )
110+
);
111+
106112
if ( true === $is_comma ) {
107113
$fix = $this->phpcsFile->addFixableError(
108114
'Comma not allowed after last value in single-line array declaration',
@@ -153,6 +159,14 @@ public function process_token( $stackPtr ) {
153159
}
154160
}
155161

162+
if ( false === $single_line && $item_index === $array_item_count ) {
163+
$this->phpcsFile->recordMetric(
164+
$stackPtr,
165+
'Multi-line array - comma after last item',
166+
( true === $is_comma ? 'yes' : 'no' )
167+
);
168+
}
169+
156170
if ( false === $is_comma ) {
157171
// Can't check spacing around the comma if there is no comma.
158172
continue;

WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,24 @@ public function process_token( $stackPtr ) {
179179
$this->custom_whitelist = $this->merge_custom_array( $this->custom_whitelist, array(), false );
180180
$this->custom_whitelist = array_map( 'strtolower', $this->custom_whitelist );
181181

182-
if ( true === $this->use_default_whitelist || ! empty( $this->custom_whitelist ) ) {
183-
/*
184-
* Check if the error silencing is done for one of the whitelisted functions.
185-
*/
186-
$next_non_empty = $this->phpcsFile->findNext( $this->empty_tokens, ( $stackPtr + 1 ), null, true, null, true );
187-
if ( false !== $next_non_empty && \T_STRING === $this->tokens[ $next_non_empty ]['code'] ) {
188-
$has_parenthesis = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true, null, true );
189-
if ( false !== $has_parenthesis && \T_OPEN_PARENTHESIS === $this->tokens[ $has_parenthesis ]['code'] ) {
190-
$function_name = strtolower( $this->tokens[ $next_non_empty ]['content'] );
191-
if ( ( true === $this->use_default_whitelist
192-
&& isset( $this->function_whitelist[ $function_name ] ) === true )
193-
|| in_array( $function_name, $this->custom_whitelist, true ) === true
194-
) {
195-
$this->phpcsFile->recordMetric( $stackPtr, 'Error silencing', 'whitelisted function call: ' . $function_name );
196-
return;
197-
}
182+
/*
183+
* Check if the error silencing is done for one of the whitelisted functions.
184+
*
185+
* @internal The function call name determination is done even when there is no whitelist active
186+
* to allow the metrics to be more informative.
187+
*/
188+
$next_non_empty = $this->phpcsFile->findNext( $this->empty_tokens, ( $stackPtr + 1 ), null, true, null, true );
189+
if ( false !== $next_non_empty && \T_STRING === $this->tokens[ $next_non_empty ]['code'] ) {
190+
$has_parenthesis = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true, null, true );
191+
if ( false !== $has_parenthesis && \T_OPEN_PARENTHESIS === $this->tokens[ $has_parenthesis ]['code'] ) {
192+
$function_name = strtolower( $this->tokens[ $next_non_empty ]['content'] );
193+
if ( ( true === $this->use_default_whitelist
194+
&& isset( $this->function_whitelist[ $function_name ] ) === true )
195+
|| ( ! empty( $this->custom_whitelist )
196+
&& in_array( $function_name, $this->custom_whitelist, true ) === true )
197+
) {
198+
$this->phpcsFile->recordMetric( $stackPtr, 'Error silencing', 'whitelisted function call: ' . $function_name );
199+
return;
198200
}
199201
}
200202
}
@@ -228,7 +230,7 @@ public function process_token( $stackPtr ) {
228230
);
229231

230232
if ( isset( $function_name ) ) {
231-
$this->phpcsFile->recordMetric( $stackPtr, 'Error silencing', $function_name );
233+
$this->phpcsFile->recordMetric( $stackPtr, 'Error silencing', '@' . $function_name );
232234
} else {
233235
$this->phpcsFile->recordMetric( $stackPtr, 'Error silencing', $found );
234236
}

WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ protected function process_global_statement( $stackPtr, $in_function_scope ) {
351351
$end = $this->tokens[ $scope_cond ]['scope_closer'];
352352
} else {
353353
// Global statement in the global namespace with file is being treated as scoped.
354-
$end = ( $this->phpcsFile->numTokens + 1 );
354+
$end = $this->phpcsFile->numTokens;
355355
}
356356

357357
for ( $ptr = $start; $ptr < $end; $ptr++ ) {

WordPress/Sniffs/WP/I18nSniff.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,16 @@ public function process_matched_token( $stack_ptr, $group_name, $matched_content
390390
$this->check_argument_tokens( $argument_assertion_context );
391391
}
392392

393-
// For _n*() calls, compare the singular and plural strings.
394-
if ( false !== strpos( $this->i18n_functions[ $matched_content ], 'number' ) ) {
393+
/*
394+
* For _n*() calls, compare the singular and plural strings.
395+
* If either of the arguments is missing, empty or has more than 1 token, skip out.
396+
* An error for that will already have been reported via the `check_argument_tokens()` method.
397+
*/
398+
if ( false !== strpos( $this->i18n_functions[ $matched_content ], 'number' )
399+
&& isset( $argument_assertions[0]['tokens'], $argument_assertions[1]['tokens'] )
400+
&& count( $argument_assertions[0]['tokens'] ) === 1
401+
&& count( $argument_assertions[1]['tokens'] ) === 1
402+
) {
395403
$single_context = $argument_assertions[0];
396404
$plural_context = $argument_assertions[1];
397405

WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ public function process_token( $stackPtr ) {
346346
if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisCloser + 1 ) ]['code']
347347
&& ! ( // Do NOT flag : immediately following ) for return types declarations.
348348
\T_COLON === $this->tokens[ ( $parenthesisCloser + 1 ) ]['code']
349-
&& in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ]['code'], array( \T_FUNCTION, \T_CLOSURE ), true )
349+
&& ( isset( $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ) === false
350+
|| in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ]['code'], array( \T_FUNCTION, \T_CLOSURE ), true ) )
350351
)
351352
&& ( isset( $scopeOpener ) && \T_COLON !== $this->tokens[ $scopeOpener ]['code'] )
352353
) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped true
4+
5+
global $post;
6+
7+
// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped false

0 commit comments

Comments
 (0)