Skip to content

Commit f328bca

Browse files
authored
Merge pull request #1548 from WordPress-Coding-Standards/develop
Release version 1.2.1
2 parents 7aa217a + 67dd140 commit f328bca

18 files changed

+114
-106
lines changed

CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ 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+
## [1.2.1] - 2018-12-18
12+
13+
Note: This will be the last release supporting PHP_CodeSniffer 2.x.
14+
15+
### Changed
16+
- The default value for `minimum_supported_wp_version`, as used by a [number of sniffs detecting usage of deprecated WP features](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters), has been updated to `4.7`.
17+
- The `WordPress.NamingConventions.PrefixAllGlobals` sniff will now report the error for hook names and constant names declared with `define()` on the line containing the parameter for the hook/constant name. Previously, it would report the error on the line containing the function call.
18+
- Various minor housekeeping fixes to inline documentation, rulesets, code.
19+
20+
### Removed
21+
- `comment_author_email_link()`, `comment_author_email()`, `comment_author_IP()`, `comment_author_link()`, `comment_author_rss()`, `comment_author_url_link()`, `comment_author_url()`, `comment_author()`, `comment_date()`, `comment_excerpt()`, `comment_form_title()`, `comment_form()`, `comment_id_fields()`, `comment_ID()`, `comment_reply_link()`, `comment_text_rss()`, `comment_text()`, `comment_time()`, `comment_type()`, `comments_link()`, `comments_number()`, `comments_popup_link()`, `comments_popup_script()`, `comments_rss_link()`, `delete_get_calendar_cache()`, `edit_bookmark_link()`, `edit_comment_link()`, `edit_post_link()`, `edit_tag_link()`, `get_footer()`, `get_header()`, `get_sidebar()`, `get_the_title()`, `next_comments_link()`, `next_image_link()`, `next_post_link()`, `next_posts_link()`, `permalink_anchor()`, `posts_nav_link()`, `previous_comments_link()`, `previous_image_link()`, `previous_post_link()`, `previous_posts_link()`, `sticky_class()`, `the_attachment_link()`, `the_author_link()`, `the_author_meta()`, `the_author_posts_link()`, `the_author_posts()`, `the_category_rss()`, `the_category()`, `the_content_rss()`, `the_content()`, `the_date_xml()`, `the_excerpt_rss()`, `the_excerpt()`, `the_feed_link()`, `the_ID()`, `the_meta()`, `the_modified_author()`, `the_modified_date()`, `the_modified_time()`, `the_permalink()`, `the_post_thumbnail()`, `the_search_query()`, `the_shortlink()`, `the_tags()`, `the_taxonomies()`, `the_terms()`, `the_time()`, `the_title_rss()`, `the_title()`, `wp_enqueue_script()`, `wp_meta()`, `wp_shortlink_header()` and `wp_shortlink_wp_head()` from the list of auto-escaped functions `Sniff::$autoEscapedFunctions`. This affects the `WordPress.Security.EscapeOutput` sniff.
22+
23+
### Fixed
24+
- The `WordPress.WhiteSpace.PrecisionAlignment` sniff would loose the value of a custom set `ignoreAlignmentTokens` property when scanning more than one file.
25+
26+
1127
## [1.2.0] - 2018-11-12
1228

1329
### Added
@@ -810,6 +826,7 @@ See the comparison for full list.
810826
Initial tagged release.
811827

812828
[Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD
829+
[1.2.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.0...1.2.1
813830
[1.2.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.1.0...1.2.0
814831
[1.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.0.0...1.1.0
815832
[1.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/0.14.1...1.0.0

WordPress-Docs/ruleset.xml

+3-6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentNotCapital"/>
6262
<!-- Excluded to allow param documentation for arrays -->
6363
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamName"/>
64+
<!-- It is too early for PHP7 features to be required -->
65+
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
6466
<!-- WP doesn't require type hints -->
6567
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing"/>
6668

@@ -81,9 +83,6 @@
8183
<exclude name="Squiz.Commenting.VariableComment.TagNotAllowed"/>
8284
<!-- WP prefers @since first -->
8385
<exclude name="Squiz.Commenting.VariableComment.VarOrder"/>
84-
85-
<!-- It is too early for PHP7 features to be required -->
86-
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
8786
</rule>
8887

8988
<rule ref="Generic.Commenting">
@@ -105,8 +104,6 @@
105104
<exclude name="Generic.Commenting.DocComment.ContentBeforeClose"/>
106105

107106
<!-- WP allows @todo's in comments -->
108-
<exclude name="Generic.Commenting.Todo.CommentFound"/>
109-
<!-- WP allows @todo's in comments -->
110-
<exclude name="Generic.Commenting.Todo.TaskFound"/>
107+
<exclude name="Generic.Commenting.Todo"/>
111108
</rule>
112109
</ruleset>

WordPress/Sniff.php

+3-79
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ abstract class Sniff implements PHPCS_Sniff {
8282
*
8383
* @var string WordPress version.
8484
*/
85-
public $minimum_supported_version = '4.6';
85+
public $minimum_supported_version = '4.7';
8686

8787
/**
8888
* Custom list of classes which test classes can extend.
@@ -178,40 +178,11 @@ abstract class Sniff implements PHPCS_Sniff {
178178
'calendar_week_mod' => true,
179179
'category_description' => true,
180180
'checked' => true,
181-
'comment_author_email_link' => true,
182-
'comment_author_email' => true,
183-
'comment_author_IP' => true,
184-
'comment_author_link' => true,
185-
'comment_author_rss' => true,
186-
'comment_author_url_link' => true,
187-
'comment_author_url' => true,
188-
'comment_author' => true,
189181
'comment_class' => true,
190-
'comment_date' => true,
191-
'comment_excerpt' => true,
192-
'comment_form_title' => true,
193-
'comment_form' => true,
194-
'comment_id_fields' => true,
195-
'comment_ID' => true,
196-
'comment_reply_link' => true,
197-
'comment_text_rss' => true,
198-
'comment_text' => true,
199-
'comment_time' => true,
200-
'comment_type' => true,
201-
'comments_link' => true,
202-
'comments_number' => true,
203-
'comments_popup_link' => true,
204-
'comments_popup_script' => true,
205-
'comments_rss_link' => true,
206182
'count' => true,
207-
'delete_get_calendar_cache' => true,
208183
'disabled' => true,
209184
'do_shortcode' => true,
210185
'do_shortcode_tag' => true,
211-
'edit_bookmark_link' => true,
212-
'edit_comment_link' => true,
213-
'edit_post_link' => true,
214-
'edit_tag_link' => true,
215186
'get_archives_link' => true,
216187
'get_attachment_link' => true,
217188
'get_avatar' => true,
@@ -220,76 +191,32 @@ abstract class Sniff implements PHPCS_Sniff {
220191
'get_comment_author_link' => true,
221192
'get_current_blog_id' => true,
222193
'get_delete_post_link' => true,
223-
'get_footer' => true,
224-
'get_header' => true,
225194
'get_search_form' => true,
226195
'get_search_query' => true,
227-
'get_sidebar' => true,
228196
'get_the_author_link' => true,
229197
'get_the_author' => true,
230198
'get_the_date' => true,
231199
'get_the_ID' => true,
232200
'get_the_post_thumbnail' => true,
233201
'get_the_term_list' => true,
234-
'get_the_title' => true,
235-
'next_comments_link' => true,
236-
'next_image_link' => true,
237-
'next_post_link' => true,
238-
'next_posts_link' => true,
239202
'paginate_comments_links' => true,
240-
'permalink_anchor' => true,
241203
'post_type_archive_title' => true,
242-
'posts_nav_link' => true,
243-
'previous_comments_link' => true,
244-
'previous_image_link' => true,
245-
'previous_post_link' => true,
246-
'previous_posts_link' => true,
247204
'readonly' => true,
248205
'selected' => true,
249206
'single_cat_title' => true,
250207
'single_month_title' => true,
251208
'single_post_title' => true,
252209
'single_tag_title' => true,
253210
'single_term_title' => true,
254-
'sticky_class' => true,
255211
'tag_description' => true,
256212
'term_description' => true,
257-
'the_attachment_link' => true,
258-
'the_author_link' => true,
259-
'the_author_meta' => true,
260-
'the_author_posts_link' => true,
261-
'the_author_posts' => true,
262213
'the_author' => true,
263-
'the_category_rss' => true,
264-
'the_category' => true,
265-
'the_content_rss' => true,
266-
'the_content' => true,
267-
'the_date_xml' => true,
268214
'the_date' => true,
269-
'the_excerpt_rss' => true,
270-
'the_excerpt' => true,
271-
'the_feed_link' => true,
272-
'the_ID' => true,
273-
'the_meta' => true,
274-
'the_modified_author' => true,
275-
'the_modified_date' => true,
276-
'the_modified_time' => true,
277-
'the_permalink' => true,
278-
'the_post_thumbnail' => true,
279-
'the_search_query' => true,
280-
'the_shortlink' => true,
281-
'the_tags' => true,
282-
'the_taxonomies' => true,
283-
'the_terms' => true,
284-
'the_time' => true,
285215
'the_title_attribute' => true,
286-
'the_title_rss' => true,
287-
'the_title' => true,
288216
'vip_powered_wpcom' => true,
289217
'walk_nav_menu_tree' => true,
290218
'wp_dropdown_categories' => true,
291219
'wp_dropdown_users' => true,
292-
'wp_enqueue_script' => true,
293220
'wp_generate_tag_cloud' => true,
294221
'wp_get_archives' => true,
295222
'wp_get_attachment_image' => true,
@@ -301,11 +228,8 @@ abstract class Sniff implements PHPCS_Sniff {
301228
'wp_list_comments' => true,
302229
'wp_login_form' => true,
303230
'wp_loginout' => true,
304-
'wp_meta' => true,
305231
'wp_nav_menu' => true,
306232
'wp_register' => true,
307-
'wp_shortlink_header' => true,
308-
'wp_shortlink_wp_head' => true,
309233
'wp_tag_cloud' => true,
310234
'wp_title' => true,
311235
);
@@ -2390,7 +2314,7 @@ public function get_declared_namespace_name( $stackPtr ) {
23902314
\T_STRING => true,
23912315
\T_NS_SEPARATOR => true,
23922316
);
2393-
$validTokens = $acceptedTokens + Tokens::$emptyTokens;
2317+
$validTokens = $acceptedTokens + Tokens::$emptyTokens;
23942318

23952319
$namespaceName = '';
23962320
while ( isset( $validTokens[ $this->tokens[ $nextToken ]['code'] ] ) ) {
@@ -2493,7 +2417,7 @@ public function is_class_property( $stackPtr ) {
24932417
$deepest_open = array_pop( $parenthesis );
24942418
if ( $deepest_open < $scopePtr
24952419
|| isset( $this->tokens[ $deepest_open ]['parenthesis_owner'] ) === false
2496-
|| T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ]['parenthesis_owner'] ]['code']
2420+
|| \T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ]['parenthesis_owner'] ]['code']
24972421
) {
24982422
return true;
24992423
}

WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
801801

802802
$data[] = $raw_content;
803803

804-
$recorded = $this->addMessage( self::ERROR_MSG, $parameters[1]['start'], $is_error, $error_code, $data );
804+
$recorded = $this->addMessage( self::ERROR_MSG, $first_non_empty, $is_error, $error_code, $data );
805805

806806
if ( true === $recorded ) {
807807
$this->record_potential_prefix_metric( $stackPtr, $raw_content );

WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class I18nTextDomainFixerSniff extends AbstractFunctionParameterSniff {
121121
*
122122
* @since 1.2.0
123123
*
124-
* @var string
124+
* @var bool
125125
*/
126126
private $is_valid = false;
127127

@@ -139,7 +139,7 @@ class I18nTextDomainFixerSniff extends AbstractFunctionParameterSniff {
139139
*
140140
* @since 1.2.0
141141
*
142-
* @var string
142+
* @var bool
143143
*/
144144
private $header_found = false;
145145

WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function process_token( $stackPtr ) {
9191
}
9292

9393
// Handle any custom ignore tokens received from a ruleset.
94-
$this->ignoreAlignmentTokens = $this->merge_custom_array( $this->ignoreAlignmentTokens );
94+
$ignoreAlignmentTokens = $this->merge_custom_array( $this->ignoreAlignmentTokens );
9595

9696
$check_tokens = array(
9797
'T_WHITESPACE' => true,
@@ -109,9 +109,9 @@ public function process_token( $stackPtr ) {
109109
|| ( isset( $this->tokens[ ( $i + 1 ) ] )
110110
&& \T_WHITESPACE === $this->tokens[ ( $i + 1 ) ]['code'] )
111111
|| $this->tokens[ $i ]['content'] === $this->phpcsFile->eolChar
112-
|| isset( $this->ignoreAlignmentTokens[ $this->tokens[ $i ]['type'] ] )
112+
|| isset( $ignoreAlignmentTokens[ $this->tokens[ $i ]['type'] ] )
113113
|| ( isset( $this->tokens[ ( $i + 1 ) ] )
114-
&& isset( $this->ignoreAlignmentTokens[ $this->tokens[ ( $i + 1 ) ]['type'] ] ) )
114+
&& isset( $ignoreAlignmentTokens[ $this->tokens[ ( $i + 1 ) ]['type'] ] ) )
115115
) {
116116
continue;
117117
}

WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc

+15
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,19 @@ apply_filters( 'my_wordpress_plugin_filtername', $var ); // OK.
409409
// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes test-this
410410
do_action( 'Test-THIS-hookname' ); // OK.
411411

412+
// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes acronym,tgmpa
413+
// Issue #1495 - throw the error on the line with the non-prefixed name.
414+
$acronym = apply_filters(
415+
'content-types-post-types', // Bad.
416+
[
417+
PostType\Post::NAME => PostType\Post::class,
418+
]
419+
);
420+
421+
define(
422+
/* comment */
423+
'SOME_GLOBAL', // Bad.
424+
[ 1, 2, 3 ]
425+
);
426+
412427
// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes false

WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function getErrorList( $testFile = 'PrefixAllGlobalsUnitTest.1.inc' ) {
6868
387 => 1,
6969
389 => 1,
7070
403 => 1,
71+
415 => 1,
72+
423 => 1,
7173
);
7274

7375
case 'PrefixAllGlobalsUnitTest.4.inc':

WordPress/Tests/Security/EscapeOutputUnitTest.inc

+4
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,7 @@ echo // phpcs:ignore WP.Secur1ty.EscapeOutput -- WPCS: XSS ok. (sniff name mang
285285
echo esc_html( $something ),
286286
$something_else,
287287
esc_html( $something_more ); // phpcs:ignore WP.Secur1ty.EscapeOutput -- WPCS: XSS ok. (sniff name mangled on purpose).
288+
289+
echo get_the_title(); // Bad.
290+
echo wp_kses_post( get_the_title() ); // Ok.
291+
echo esc_html( get_the_title() ); // Ok.

WordPress/Tests/Security/EscapeOutputUnitTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function getErrorList() {
7878
263 => 1,
7979
264 => 1,
8080
266 => 1,
81+
289 => 1,
8182
);
8283
}
8384

WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc

+4-4
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,14 @@ get_comments_popup_template();
315315
get_currentuserinfo();
316316
is_comments_popup();
317317
use function popuplinks as something_else; // Related to issue #1306.
318-
319-
/*
320-
* Warning.
321-
*/
322318
/* ============ WP 4.6 ============ */
323319
post_form_autocomplete_off();
324320
wp_embed_handler_googlevideo();
325321
wp_get_sites();
322+
323+
/*
324+
* Warning.
325+
*/
326326
/* ============ WP 4.7 ============ */
327327
_sort_nav_menu_items();
328328
_usort_terms_by_ID();

WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DeprecatedFunctionsUnitTest extends AbstractSniffUnitTest {
2828
*/
2929
public function getErrorList() {
3030

31-
$errors = array_fill( 8, 310, 1 );
31+
$errors = array_fill( 8, 314, 1 );
3232

3333
// Unset the lines related to version comments.
3434
unset(
@@ -59,7 +59,8 @@ public function getErrorList() {
5959
$errors[290],
6060
$errors[295],
6161
$errors[303],
62-
$errors[310]
62+
$errors[310],
63+
$errors[318]
6364
);
6465

6566
return $errors;
@@ -72,7 +73,7 @@ public function getErrorList() {
7273
*/
7374
public function getWarningList() {
7475

75-
$warnings = array_fill( 323, 17, 1 );
76+
$warnings = array_fill( 326, 14, 1 );
7677

7778
// Unset the lines related to version comments.
7879
unset( $warnings[326], $warnings[333], $warnings[335] );

WordPress/Tests/WP/DeprecatedParametersUnitTest.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ wp_title_rss( 'deprecated' );
6060
wp_upload_bits( '', 'deprecated' );
6161
xfn_check( '', '', 'deprecated' );
6262

63-
// All will give an WARNING as they have been deprecated after WP 4.5.
63+
// All will give an WARNING as they have been deprecated after WP 4.7.
6464

6565
get_category_parents( '', '', '', '', array( 'deprecated') );
6666
unregister_setting( '', '', '', 'deprecated' );

WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
/**
2020
* OK: Doc comments are indented with tabs and one space.
2121
*
22-
* @var string <= Bad.
22+
* @var string <= Bad, but not reported as token type is whitelisted.
2323
* @access private
2424
*/
2525

2626
/*
2727
* OK: Multi-line comments are indented with tabs and one space.
2828
*
29-
* <= Bad.
29+
* <= Bad, but not reported as token type is whitelisted
3030
*/
3131

32-
function exampleFunctionD() {} // Bad: [tab][space].
33-
function exampleFunctionE() {} // Bad: [tab][space][space].
34-
function exampleFunctionF() {} // Bad: [tab][space][space][space].
32+
function exampleFunctionD() {} // Bad, but not reported as token type is whitelisted.
33+
function exampleFunctionE() {} // Bad, but not reported as token type is whitelisted.
34+
function exampleFunctionF() {} // Bad, but not reported as token type is whitelisted.
3535

3636
?>
3737

3838
<p>
39-
Bad: Some text with precision alignment.
39+
Bad: Some text with precision alignment, but not reported as token type is whitelisted.
4040
</p>
4141

4242
<?php

0 commit comments

Comments
 (0)