diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a5e83627a..a777dc0905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,27 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ + +## [2.1.1] - 2019-05-21 + +### Changed +- The `WordPress.WP.CapitalPDangit` will now ignore misspelled instances of `WordPress` within constant declarations. + This covers both constants declared using `defined()` as well as constants declared using the `const` keyword. +- 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.9`. + +### Removed +- `paginate_comments_links()` from the list of auto-escaped functions `Sniff::$autoEscapedFunctions`. + This affects the `WordPress.Security.EscapeOutput` sniff. + +### Fixed +- The `$current_blog` and `$tag_ID` variables have been added to the list of WordPress global variables. + This fixes some false positives from the `WordPress.NamingConventions.PrefixAllGlobals` and the `WordPress.WP.GlobalVariablesOverride` sniffs. +- The generic `TestCase` class name has been added to the `$test_class_whitelist`. + This fixes some false positives from the `WordPress.NamingConventions.FileName`, `WordPress.NamingConventions.PrefixAllGlobals` and the `WordPress.WP.GlobalVariablesOverride` sniffs. +- The `WordPress.NamingConventions.ValidVariableName` sniff will now correctly recognize `$tag_ID` as a WordPress native, mixed-case variable. +- The `WordPress.Security.NonceVerification` sniff will now correctly recognize nonce verification within a nested closure or anonymous class. + + ## [2.1.0] - 2019-04-08 ### Added @@ -1070,6 +1091,7 @@ See the comparison for full list. Initial tagged release. [Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD +[2.1.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.1.0...2.1.1 [2.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0...2.1.0 [2.0.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/2.0.0-RC1...2.0.0 [2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1 diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 07d88fbe81..1d5edc4e28 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -82,7 +82,7 @@ abstract class Sniff implements PHPCS_Sniff { * * @var string WordPress version. */ - public $minimum_supported_version = '4.8'; + public $minimum_supported_version = '4.9'; /** * Custom list of classes which test classes can extend. @@ -202,7 +202,6 @@ abstract class Sniff implements PHPCS_Sniff { 'get_the_ID' => true, 'get_the_post_thumbnail' => true, 'get_the_term_list' => true, - 'paginate_comments_links' => true, 'post_type_archive_title' => true, 'readonly' => true, 'selected' => true, @@ -638,6 +637,7 @@ abstract class Sniff implements PHPCS_Sniff { 'compress_css' => true, 'compress_scripts' => true, 'concatenate_scripts' => true, + 'current_blog' => true, 'current_screen' => true, 'current_site' => true, 'current_user' => true, @@ -740,6 +740,7 @@ abstract class Sniff implements PHPCS_Sniff { 'table_prefix' => true, 'tabs' => true, 'tag' => true, + 'tag_ID' => true, 'targets' => true, 'tax' => true, 'taxnow' => true, @@ -860,6 +861,8 @@ abstract class Sniff implements PHPCS_Sniff { 'WP_XMLRPC_UnitTestCase' => true, 'PHPUnit_Framework_TestCase' => true, 'PHPUnit\Framework\TestCase' => true, + // PHPUnit native TestCase class when imported via use statement. + 'TestCase' => true, ); /** @@ -1440,13 +1443,15 @@ protected function has_nonce_check( $stackPtr ) { $tokens = $this->phpcsFile->getTokens(); // If we're in a function, only look inside of it. - $f = $this->phpcsFile->getCondition( $stackPtr, \T_FUNCTION ); - if ( false !== $f ) { - $start = $tokens[ $f ]['scope_opener']; - } else { - $f = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE ); - if ( false !== $f ) { - $start = $tokens[ $f ]['scope_opener']; + // Once PHPCS 3.5.0 comes out this should be changed to the new Conditions::GetLastCondition() method. + if ( isset( $tokens[ $stackPtr ]['conditions'] ) === true ) { + $conditions = $tokens[ $stackPtr ]['conditions']; + $conditions = array_reverse( $conditions, true ); + foreach ( $conditions as $tokenPtr => $condition ) { + if ( \T_FUNCTION === $condition || \T_CLOSURE === $condition ) { + $start = $tokens[ $tokenPtr ]['scope_opener']; + break; + } } } diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 0b9422796a..dad06cac71 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -50,6 +50,7 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { 'is_winIE' => true, 'PHP_SELF' => true, 'post_ID' => true, + 'tag_ID' => true, 'user_ID' => true, ); diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index 908e5d6cc8..3c270154a1 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -188,6 +188,24 @@ public function process_token( $stackPtr ) { } } + // Ignore constant declarations via define(). + if ( $this->is_in_function_call( $stackPtr, array( 'define' => true ), true, true ) ) { + return; + } + + // Ignore constant declarations using the const keyword. + $stop_points = array( + \T_CONST, + \T_SEMICOLON, + \T_OPEN_TAG, + \T_CLOSE_TAG, + \T_OPEN_CURLY_BRACKET, + ); + $maybe_const = $this->phpcsFile->findPrevious( $stop_points, ( $stackPtr - 1 ) ); + if ( false !== $maybe_const && \T_CONST === $this->tokens[ $maybe_const ]['code'] ) { + return; + } + $content = $this->tokens[ $stackPtr ]['content']; if ( preg_match_all( self::WP_REGEX, $content, $matches, ( \PREG_PATTERN_ORDER | \PREG_OFFSET_CAPTURE ) ) > 0 ) { diff --git a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc index 0f494371b1..7d17da83b9 100644 --- a/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc +++ b/WordPress/Tests/Files/FileNameUnitTests/TestFiles/test-sample-namespaced-extends.4.inc @@ -2,5 +2,5 @@ phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample array( 'a' => 'b' ), + WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly). +} diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed index 7dcc166678..7dc636aa88 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed @@ -180,3 +180,11 @@ wordpress.pot $text = <<<'EOD' This is an explanation about WordPress. EOD; + +// Issue 1698 - ignore constant declarations. +define( 'WORDPRESS_SOMETHING', 'wordpress' ); // OK. +class TestMe { + public const MY_CONST = 123, + ANOTHER => array( 'a' => 'b' ), + WORDPRESS_SOMETHING = 'wordpress'; // OK (complex declaration to make sure start of statement is detected correctly). +} diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc index eb0822692e..6a41db6cc6 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc @@ -327,12 +327,12 @@ _usort_terms_by_name(); get_paged_template(); wp_get_network(); wp_kses_js_entities(); +/* ============ WP 4.8 ============ */ +wp_dashboard_plugins_output(); /* * Warning. */ -/* ============ WP 4.8 ============ */ -wp_dashboard_plugins_output(); /* ============ WP 4.9 ============ */ get_shortcut_link(); is_user_option_local(); diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index c14a79c9bd..ba45e47476 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -28,7 +28,7 @@ class DeprecatedFunctionsUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { - $errors = array_fill( 8, 322, 1 ); + $errors = array_fill( 8, 324, 1 ); // Unset the lines related to version comments. unset( @@ -61,7 +61,8 @@ public function getErrorList() { $errors[304], $errors[311], $errors[319], - $errors[323] + $errors[323], + $errors[330] ); return $errors; @@ -74,10 +75,10 @@ public function getErrorList() { */ public function getWarningList() { - $warnings = array_fill( 335, 9, 1 ); + $warnings = array_fill( 337, 7, 1 ); // Unset the lines related to version comments. - unset( $warnings[336], $warnings[341] ); + unset( $warnings[341] ); return $warnings; } diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc index 8022d59bc5..3ada338c90 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.inc @@ -34,6 +34,7 @@ comments_link( 'deprecated', 'deprecated' ); comments_number( '', '', '', 'deprecated' ); convert_chars( '', 'deprecated' ); discover_pingback_server_uri( '', 'deprecated' ); +get_category_parents( '', '', '', '', array( 'deprecated') ); get_delete_post_link( '', 'deprecated' ); get_last_updated( 'deprecated' ); get_the_author( 'deprecated' ); @@ -61,6 +62,4 @@ wp_title_rss( 'deprecated' ); wp_upload_bits( '', 'deprecated' ); xfn_check( '', '', 'deprecated' ); -// All will give an WARNING as they have been deprecated after WP 4.8. - -get_category_parents( '', '', '', '', array( 'deprecated') ); +// All will give an WARNING as they have been deprecated after WP 4.9. diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php index 77d4d87e88..af86abf2e5 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php @@ -27,7 +27,7 @@ class DeprecatedParametersUnitTest extends AbstractSniffUnitTest { * @return array => */ public function getErrorList() { - $errors = array_fill( 28, 35, 1 ); + $errors = array_fill( 28, 36, 1 ); $errors[22] = 1; $errors[23] = 1; @@ -35,7 +35,7 @@ public function getErrorList() { // Override number of errors. $errors[33] = 2; - $errors[47] = 2; + $errors[48] = 2; return $errors; } @@ -46,9 +46,7 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array( - 66 => 1, - ); + return array(); } } diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.5.inc b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.5.inc new file mode 100644 index 0000000000..234e452e0e --- /dev/null +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.5.inc @@ -0,0 +1,11 @@ + - +