From 239ce3f33ed765f448cb85d95e64e81b034995ac Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:01:30 +0100 Subject: [PATCH 01/64] WPCS 2.0.0: Remove the deprecated VIP ruleset and sniffs The VIP ruleset and sniffs were deprecated in WPCS 1.0.0 and will now be removed for WPCS 2.0.0. --- .travis.yml | 2 - README.md | 7 +- WordPress-VIP/ruleset.xml | 231 --------- WordPress/Sniff.php | 1 - WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 465 ------------------ WordPress/Sniffs/VIP/CronIntervalSniff.php | 89 ---- .../Sniffs/VIP/DirectDatabaseQuerySniff.php | 78 --- .../VIP/FileSystemWritesDisallowSniff.php | 152 ------ WordPress/Sniffs/VIP/OrderByRandSniff.php | 107 ---- WordPress/Sniffs/VIP/PluginMenuSlugSniff.php | 65 --- WordPress/Sniffs/VIP/PostsPerPageSniff.php | 105 ---- .../Sniffs/VIP/RestrictedFunctionsSniff.php | 280 ----------- .../Sniffs/VIP/RestrictedVariablesSniff.php | 113 ----- .../Sniffs/VIP/SessionFunctionsUsageSniff.php | 126 ----- .../Sniffs/VIP/SessionVariableUsageSniff.php | 81 --- WordPress/Sniffs/VIP/SlowDBQuerySniff.php | 76 --- .../Sniffs/VIP/SuperGlobalInputUsageSniff.php | 87 ---- WordPress/Sniffs/VIP/TimezoneChangeSniff.php | 75 --- .../VIP/ValidatedSanitizedInputSniff.php | 77 --- .../ArrayDeclarationSpacingUnitTest.1.inc | 4 +- ...rrayDeclarationSpacingUnitTest.1.inc.fixed | 4 +- .../ArrayDeclarationSpacingUnitTest.2.inc | 4 +- ...rrayDeclarationSpacingUnitTest.2.inc.fixed | 4 +- .../Tests/VIP/AdminBarRemovalUnitTest.css | 55 --- .../Tests/VIP/AdminBarRemovalUnitTest.inc | 108 ---- .../Tests/VIP/AdminBarRemovalUnitTest.php | 105 ---- WordPress/Tests/VIP/CronIntervalUnitTest.inc | 6 - WordPress/Tests/VIP/CronIntervalUnitTest.php | 48 -- .../Tests/VIP/DirectDatabaseQueryUnitTest.inc | 6 - .../Tests/VIP/DirectDatabaseQueryUnitTest.php | 46 -- .../VIP/FileSystemWritesDisallowUnitTest.inc | 49 -- .../VIP/FileSystemWritesDisallowUnitTest.php | 68 --- WordPress/Tests/VIP/OrderByRandUnitTest.inc | 18 - WordPress/Tests/VIP/OrderByRandUnitTest.php | 51 -- .../Tests/VIP/PluginMenuSlugUnitTest.inc | 3 - .../Tests/VIP/PluginMenuSlugUnitTest.php | 46 -- WordPress/Tests/VIP/PostsPerPageUnitTest.inc | 24 - WordPress/Tests/VIP/PostsPerPageUnitTest.php | 54 -- .../Tests/VIP/RestrictedFunctionsUnitTest.inc | 89 ---- .../Tests/VIP/RestrictedFunctionsUnitTest.php | 77 --- .../Tests/VIP/RestrictedVariablesUnitTest.inc | 34 -- .../Tests/VIP/RestrictedVariablesUnitTest.php | 54 -- .../VIP/SessionFunctionsUsageUnitTest.inc | 34 -- .../VIP/SessionFunctionsUsageUnitTest.php | 44 -- .../VIP/SessionVariableUsageUnitTest.inc | 4 - .../VIP/SessionVariableUsageUnitTest.php | 47 -- WordPress/Tests/VIP/SlowDBQueryUnitTest.inc | 6 - WordPress/Tests/VIP/SlowDBQueryUnitTest.php | 48 -- .../VIP/SuperGlobalInputUsageUnitTest.inc | 23 - .../VIP/SuperGlobalInputUsageUnitTest.php | 47 -- .../Tests/VIP/TimezoneChangeUnitTest.inc | 6 - .../Tests/VIP/TimezoneChangeUnitTest.php | 49 -- .../VIP/ValidatedSanitizedInputUnitTest.inc | 6 - .../VIP/ValidatedSanitizedInputUnitTest.php | 49 -- WordPress/ruleset.xml | 12 +- bin/class-ruleset-test.php | 1 - 56 files changed, 12 insertions(+), 3538 deletions(-) delete mode 100644 WordPress-VIP/ruleset.xml delete mode 100644 WordPress/Sniffs/VIP/AdminBarRemovalSniff.php delete mode 100644 WordPress/Sniffs/VIP/CronIntervalSniff.php delete mode 100644 WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php delete mode 100644 WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php delete mode 100644 WordPress/Sniffs/VIP/OrderByRandSniff.php delete mode 100644 WordPress/Sniffs/VIP/PluginMenuSlugSniff.php delete mode 100644 WordPress/Sniffs/VIP/PostsPerPageSniff.php delete mode 100644 WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php delete mode 100644 WordPress/Sniffs/VIP/RestrictedVariablesSniff.php delete mode 100644 WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php delete mode 100644 WordPress/Sniffs/VIP/SessionVariableUsageSniff.php delete mode 100644 WordPress/Sniffs/VIP/SlowDBQuerySniff.php delete mode 100644 WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php delete mode 100644 WordPress/Sniffs/VIP/TimezoneChangeSniff.php delete mode 100644 WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php delete mode 100644 WordPress/Tests/VIP/AdminBarRemovalUnitTest.css delete mode 100644 WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc delete mode 100644 WordPress/Tests/VIP/AdminBarRemovalUnitTest.php delete mode 100644 WordPress/Tests/VIP/CronIntervalUnitTest.inc delete mode 100644 WordPress/Tests/VIP/CronIntervalUnitTest.php delete mode 100644 WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc delete mode 100644 WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php delete mode 100644 WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc delete mode 100644 WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php delete mode 100644 WordPress/Tests/VIP/OrderByRandUnitTest.inc delete mode 100644 WordPress/Tests/VIP/OrderByRandUnitTest.php delete mode 100644 WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc delete mode 100644 WordPress/Tests/VIP/PluginMenuSlugUnitTest.php delete mode 100644 WordPress/Tests/VIP/PostsPerPageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/PostsPerPageUnitTest.php delete mode 100644 WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc delete mode 100644 WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php delete mode 100644 WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc delete mode 100644 WordPress/Tests/VIP/RestrictedVariablesUnitTest.php delete mode 100644 WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php delete mode 100644 WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SessionVariableUsageUnitTest.php delete mode 100644 WordPress/Tests/VIP/SlowDBQueryUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SlowDBQueryUnitTest.php delete mode 100644 WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc delete mode 100644 WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php delete mode 100644 WordPress/Tests/VIP/TimezoneChangeUnitTest.inc delete mode 100644 WordPress/Tests/VIP/TimezoneChangeUnitTest.php delete mode 100644 WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc delete mode 100644 WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.php diff --git a/.travis.yml b/.travis.yml index 29f5e6fe61..74ad0a2745 100644 --- a/.travis.yml +++ b/.travis.yml @@ -108,7 +108,6 @@ script: - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Core; fi - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Docs; fi - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-Extra; fi - - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress-VIP; fi - if [[ $TRAVIS_PHP_VERSION == "7.1" ]]; then $(pwd)/vendor/bin/phpcs -s ./bin/class-ruleset-test.php --standard=WordPress; fi # WordPress Coding Standards. # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards @@ -123,7 +122,6 @@ script: - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Docs/ruleset.xml <(xmllint --format "./WordPress-Docs/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Extra/ruleset.xml <(xmllint --format "./WordPress-Extra/ruleset.xml"); fi - - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-VIP/ruleset.xml <(xmllint --format "./WordPress-VIP/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./phpcs.xml.dist.sample <(xmllint --format "./phpcs.xml.dist.sample"); fi # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate diff --git a/README.md b/README.md index eb903125a1..d672ea0ed4 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ You should then see `WordPress-Core` et al listed when you run `phpcs -i`. ### Standards subsets -The project encompasses a super-set of the sniffs that the WordPress community may need. If you use the `WordPress` standard you will get all the checks. Some of them might be unnecessary for your environment, for example, those specific to WordPress.com VIP coding requirements. +The project encompasses a super-set of the sniffs that the WordPress community may need. If you use the `WordPress` standard you will get all the checks. You can use the following as standard names when invoking `phpcs` to select sniffs, fitting your needs: @@ -137,9 +137,8 @@ You can use the following as standard names when invoking `phpcs` to select snif - `WordPress-Extra` - extended ruleset for recommended best practices, not sufficiently covered in the WordPress core coding standards - includes `WordPress-Core` -**Notes:** This WPCS package contains the sniffs for another ruleset, `WordPress-VIP`. This ruleset was originally intended to aid with the [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/), but this is no longer used or recommended by the WordPress.com VIP team or their clients, since they prefer to use their [official VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) ruleset instead. - -Before WPCS `1.0.0`, the WordPress-VIP ruleset was included as part of the complete `WordPress` ruleset. **As of `1.0.0` the `WordPress-VIP` ruleset is not part of the WordPress ruleset, and it is deprecated**. The remaining `WordPress-VIP` sniffs may still be referenced in custom rulesets, so to maintain some backwards compatibility, they will remain in WPCS until `2.0.0`. See [#1309](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1309) for more information. +**Note:** The WPCS package used to include a `WordPress-VIP` ruleset and associated sniffs, prior to WPCS 2.0.0. +The `WordPress-VIP` ruleset was originally intended to aid with the [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/), but has been superseded. It is recommended to use the [official VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) ruleset instead for checking code against the VIP platform requirements. ### Using a custom ruleset diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml deleted file mode 100644 index 202b3bc872..0000000000 --- a/WordPress-VIP/ruleset.xml +++ /dev/null @@ -1,231 +0,0 @@ - - - Deprecated WordPress.com VIP Coding Standards. Use the official VIP coding standards instead which can be found at https://github.com/Automattic/VIP-Coding-Standards - - - - - ./../WordPress/PHPCSAliases.php - - - - - - - - - - - - - - - - - - - - - - - - - - - error - - - - - error - - - error - - - - - - - - Using cURL functions is highly discouraged within VIP context. Check (Fetching Remote Data) on VIP Documentation. - - - %s() is highly discouraged, please use vip_safe_wp_remote_get() instead. - - - - - - - error - Attempting a database schema change is highly discouraged. - - - error - Usage of a direct database call without caching is prohibited on the VIP platform. Use wp_cache_get / wp_cache_set or wp_cache_delete. - - - - - - - error - - - - - error - Scheduling crons at %s sec ( less than %s minutes ) is prohibited. - - - - - - - error - - - error - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index ca7ca0bad8..461faad62f 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -213,7 +213,6 @@ abstract class Sniff implements PHPCS_Sniff { 'the_author' => true, 'the_date' => true, 'the_title_attribute' => true, - 'vip_powered_wpcom' => true, 'walk_nav_menu_tree' => true, 'wp_dropdown_categories' => true, 'wp_dropdown_users' => true, diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php deleted file mode 100644 index ba8208c601..0000000000 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ /dev/null @@ -1,465 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * A list of tokenizers this sniff supports. - * - * @since 0.11.0 - * - * @var array - */ - public $supportedTokenizers = array( 'PHP', 'CSS' ); - - /** - * Whether or not the sniff only checks for removal of the admin bar - * or any manipulation to the visibility of the admin bar. - * - * Defaults to true: only check for removal of the admin bar. - * Set to false to check for any form of manipulation of the visibility - * of the admin bar. - * - * @since 0.11.0 - * - * @var bool - */ - public $remove_only = true; - - /** - * Functions this sniff is looking for. - * - * @since 0.11.0 - * - * @var array - */ - protected $target_functions = array( - 'show_admin_bar' => true, - 'add_filter' => true, - ); - - /** - * CSS properties this sniff is looking for. - * - * @since 0.11.0 - * - * @var array - */ - protected $target_css_properties = array( - 'visibility' => array( - 'type' => '!=', - 'value' => 'hidden', - ), - 'display' => array( - 'type' => '!=', - 'value' => 'none', - ), - 'opacity' => array( - 'type' => '>', - 'value' => 0.3, - ), - ); - - /** - * CSS selectors this sniff is looking for. - * - * @since 0.11.0 - * - * @var array - */ - protected $target_css_selectors = array( - '.show-admin-bar', - '#wpadminbar', - ); - - /** - * String tokens within PHP files we want to deal with. - * - * Set from the register() method. - * - * @since 0.11.0 - * - * @var array - */ - private $string_tokens = array(); - - /** - * Regex template for use with the CSS selectors in combination with PHP text strings. - * - * @since 0.11.0 - * - * @var string - */ - private $target_css_selectors_regex = '`(?:%s).*?\{(.*)$`'; - - /** - * Property to keep track of whether a ' ) ) { - // Make sure we check any content on this line before the closing style tag. - $this->in_style[ $file_name ] = false; - $content = trim( substr( $content, 0, strpos( $content, '' ) ) ); - } - } elseif ( true === $this->has_html_open_tag( 'style', $stackPtr, $content ) ) { - // Ok, found a ' ) ) { - // Make sure we check any content on this line after the opening style tag. - $this->in_style[ $file_name ] = true; - $content = trim( substr( $content, ( strpos( $content, '' ); - $content = trim( substr( $content, $start, ( $end - $start ) ) ); - unset( $start, $end ); - } - } else { - return; - } - - // Are we in one of the target selectors ? - if ( true === $this->in_target_selector[ $file_name ] ) { - if ( false !== strpos( $content, '}' ) ) { - // Make sure we check any content on this line before the selector closing brace. - $this->in_target_selector[ $file_name ] = false; - $content = trim( substr( $content, 0, strpos( $content, '}' ) ) ); - } - } elseif ( preg_match( $this->target_css_selectors_regex, $content, $matches ) > 0 ) { - // Ok, found a new target selector. - $content = ''; - - if ( isset( $matches[1] ) && '' !== $matches[1] ) { - if ( false === strpos( $matches[1], '}' ) ) { - // Make sure we check any content on this line before the closing brace. - $this->in_target_selector[ $file_name ] = true; - $content = trim( $matches[1] ); - } else { - // Ok, we have the selector open and close brace on the same line. - $content = trim( substr( $matches[1], 0, strpos( $matches[1], '}' ) ) ); - } - } else { - $this->in_target_selector[ $file_name ] = true; - } - } else { - return; - } - unset( $matches ); - - // Now let's do the check for the CSS properties. - if ( ! empty( $content ) ) { - foreach ( $this->target_css_properties as $property => $requirements ) { - if ( false !== strpos( $content, $property ) ) { - $error = true; - - if ( true === $this->remove_only ) { - // Check the value of the CSS property. - if ( preg_match( '`' . preg_quote( $property, '`' ) . '\s*:\s*(.+?)\s*(?:!important)?;`', $content, $matches ) > 0 ) { - $value = trim( $matches[1] ); - $valid = $this->validate_css_property_value( $value, $requirements['type'], $requirements['value'] ); - if ( true === $valid ) { - $error = false; - } - } - } - - if ( true === $error ) { - $this->phpcsFile->addError( 'Hiding of the admin bar is not allowed.', $stackPtr, 'HidingDetected' ); - } - } - } - } - } - - /** - * Processes this test for T_STYLE tokens in CSS files. - * - * @since 0.11.0 - * - * @param int $stackPtr The position of the current token in the stack passed in $tokens. - * - * @return void - */ - protected function process_css_style( $stackPtr ) { - if ( ! isset( $this->target_css_properties[ $this->tokens[ $stackPtr ]['content'] ] ) ) { - // Not one of the CSS properties we're interested in. - return; - } - - $css_property = $this->target_css_properties[ $this->tokens[ $stackPtr ]['content'] ]; - - // Check if the CSS selector matches. - $opener = $this->phpcsFile->findPrevious( \T_OPEN_CURLY_BRACKET, $stackPtr ); - if ( false !== $opener ) { - for ( $i = ( $opener - 1 ); $i >= 0; $i-- ) { - if ( isset( Tokens::$commentTokens[ $this->tokens[ $i ]['code'] ] ) - || \T_CLOSE_CURLY_BRACKET === $this->tokens[ $i ]['code'] - ) { - break; - } - } - $start = ( $i + 1 ); - $selector = trim( $this->phpcsFile->getTokensAsString( $start, ( $opener - $start ) ) ); - unset( $i ); - - foreach ( $this->target_css_selectors as $target_selector ) { - if ( false !== strpos( $selector, $target_selector ) ) { - $error = true; - - if ( true === $this->remove_only ) { - // Check the value of the CSS property. - $valuePtr = $this->phpcsFile->findNext( array( \T_COLON, \T_WHITESPACE ), ( $stackPtr + 1 ), null, true ); - $value = $this->tokens[ $valuePtr ]['content']; - $valid = $this->validate_css_property_value( $value, $css_property['type'], $css_property['value'] ); - if ( true === $valid ) { - $error = false; - } - } - - if ( true === $error ) { - $this->phpcsFile->addError( 'Hiding of the admin bar is not allowed.', $stackPtr, 'HidingDetected' ); - } - } - } - } - } - - /** - * Verify if a CSS property value complies with an expected value. - * - * {@internal This is a method stub, doing only what is needed for this sniff. - * If at some point in the future other sniff would need similar functionality, - * this method should be moved to the WordPress_Sniff class and expanded to cover - * all types of comparisons.}} - * - * @since 0.11.0 - * - * @param mixed $value The value of CSS property. - * @param string $compare_type The type of comparison to use for the validation. - * @param string $compare_value The value to compare against. - * - * @return bool True if the property value complies, false otherwise. - */ - protected function validate_css_property_value( $value, $compare_type, $compare_value ) { - switch ( $compare_type ) { - case '!=': - return $value !== $compare_value; - - case '>': - return $value > $compare_value; - - default: - return false; - } - } - -} diff --git a/WordPress/Sniffs/VIP/CronIntervalSniff.php b/WordPress/Sniffs/VIP/CronIntervalSniff.php deleted file mode 100644 index 0cf91d9486..0000000000 --- a/WordPress/Sniffs/VIP/CronIntervalSniff.php +++ /dev/null @@ -1,89 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.CronInterval" sniff has been renamed to "WordPress.WP.CronInterval". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( 900 !== (int) $this->min_interval - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.CronInterval" sniff has been renamed to "WordPress.WP.CronInterval". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php deleted file mode 100644 index a1abd4a683..0000000000 --- a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php +++ /dev/null @@ -1,78 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.DirectDatabaseQuery" sniff has been renamed to "WordPress.DB.DirectDatabaseQuery". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] - && ( ( array() !== $this->customCacheGetFunctions && $this->customCacheGetFunctions !== $this->addedCustomFunctions['cacheget'] ) - || ( array() !== $this->customCacheSetFunctions && $this->customCacheSetFunctions !== $this->addedCustomFunctions['cacheset'] ) - || ( array() !== $this->customCacheDeleteFunctions && $this->customCacheDeleteFunctions !== $this->addedCustomFunctions['cachedelete'] ) ) - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.DirectDatabaseQuery" sniff has been renamed to "WordPress.DB.DirectDatabaseQuery". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php deleted file mode 100644 index d95eea636b..0000000000 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ /dev/null @@ -1,152 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of functions to restrict. - * - * Example: groups => array( - * 'lambda' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Use anonymous functions instead please!', - * 'functions' => array( 'file_get_contents', 'create_function' ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - $groups = array( - 'file_ops' => array( - 'type' => 'error', - 'message' => 'Filesystem writes are forbidden, you should not be using %s()', - 'functions' => array( - 'delete', - 'file_put_contents', - 'flock', - 'fputcsv', - 'fputs', - 'fwrite', - 'ftruncate', - 'is_writable', - 'is_writeable', - 'link', - 'rename', - 'symlink', - 'tempnam', - 'touch', - 'unlink', - ), - ), - 'directory' => array( - 'type' => 'error', - 'message' => 'Filesystem writes are forbidden, you should not be using %s()', - 'functions' => array( - 'mkdir', - 'rmdir', - ), - ), - 'chmod' => array( - 'type' => 'error', - 'message' => 'Filesystem writes are forbidden, you should not be using %s()', - 'functions' => array( - 'chgrp', - 'chown', - 'chmod', - 'lchgrp', - 'lchown', - ), - ), - ); - - /* - * Maintain old behaviour - allow for changing the error type from the ruleset - * using the `error` property. - */ - if ( false === $this->error ) { - foreach ( $groups as $group_name => $details ) { - $groups[ $group_name ]['type'] = 'warning'; - } - } - - return $groups; - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ( ! empty( $this->exclude ) || true !== $this->error ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php deleted file mode 100644 index 5e33df9122..0000000000 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ /dev/null @@ -1,107 +0,0 @@ - rand. - * - * @link https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#order-by-rand - * - * @package WPCS\WordPressCodingStandards - * - * @since 0.9.0 - * @since 0.13.0 Class name changed: this class is now namespaced. - * - * @deprecated 1.0.0 This sniff has been deprecated. - * This file remains for now to prevent BC breaks. - */ -class OrderByRandSniff extends AbstractArrayAssignmentRestrictionsSniff { - - /** - * Keep track of whether the warnings have been thrown to prevent - * the messages being thrown for every token triggering the sniff. - * - * @since 1.0.0 - * - * @var array - */ - private $thrown = array( - 'DeprecatedSniff' => false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of variables to restrict. - * - * @return array - */ - public function getGroups() { - return array( - 'orderby' => array( - 'type' => 'error', - 'keys' => array( - 'orderby', - ), - ), - ); - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - - /** - * Callback to process each confirmed key, to check value - * This must be extended to add the logic to check assignment value - * - * @param string $key Array index / key. - * @param mixed $val Assigned value. - * @param int $line Token line. - * @param array $group Group definition. - * @return mixed FALSE if no match, TRUE if matches, STRING if matches with custom error message passed to ->process(). - */ - public function callback( $key, $val, $line, $group ) { - if ( 'rand' === strtolower( $val ) ) { - return 'Detected forbidden query_var "%s" of "%s". Use vip_get_random_posts() instead.'; - } else { - return false; - } - } - -} diff --git a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php deleted file mode 100644 index 072da87462..0000000000 --- a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php +++ /dev/null @@ -1,65 +0,0 @@ - false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->phpcsFile->addWarning( - 'The "WordPress.VIP.PluginMenuSlug" sniff has been renamed to "WordPress.Security.PluginMenuSlug". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - - $this->thrown['DeprecatedSniff'] = true; - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/PostsPerPageSniff.php b/WordPress/Sniffs/VIP/PostsPerPageSniff.php deleted file mode 100644 index 73588a8f13..0000000000 --- a/WordPress/Sniffs/VIP/PostsPerPageSniff.php +++ /dev/null @@ -1,105 +0,0 @@ - false, - ); - - /** - * Groups of variables to restrict. - * - * @return array - */ - public function getGroups() { - return array( - 'posts_per_page' => array( - 'type' => 'error', - 'keys' => array( - 'posts_per_page', - 'nopaging', - 'numberposts', - ), - ), - ); - } - - /** - * Callback to process each confirmed key, to check value. - * - * @param string $key Array index / key. - * @param mixed $val Assigned value. - * @param int $line Token line. - * @param array $group Group definition. - * @return mixed FALSE if no match, TRUE if matches, STRING if matches - * with custom error message passed to ->process(). - */ - public function callback( $key, $val, $line, $group ) { - if ( 100 !== (int) $this->posts_per_page - && false === $this->thrown['FoundDeprecatedProperty'] - ) { - $this->phpcsFile->addWarning( - 'The "posts_per_page" property for the "WordPress.VIP.PostsPerPage" sniff is deprecated. The detection of high pagination limits has been moved to the "WordPress.WP.PostsPerPage" sniff. Please update your custom ruleset.', - 0, - 'FoundDeprecatedProperty' - ); - - $this->thrown['FoundDeprecatedProperty'] = true; - } - - $key = strtolower( $key ); - - if ( ( 'nopaging' === $key && ( 'true' === $val || 1 === $val ) ) - || ( \in_array( $key, array( 'numberposts', 'posts_per_page' ), true ) && '-1' === $val ) - ) { - return 'Disabling pagination is prohibited in VIP context, do not set `%s` to `%s` ever.'; - } - - return false; - } - -} diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php deleted file mode 100644 index 7d7bad1c18..0000000000 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ /dev/null @@ -1,280 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of functions to restrict. - * - * Example: groups => array( - * 'lambda' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Use anonymous functions instead please!', - * 'functions' => array( 'file_get_contents', 'create_function' ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - return array( - // @link WordPress.com: https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#switch_to_blog - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#switch_to_blog - 'switch_to_blog' => array( - 'type' => 'error', - 'message' => '%s() is not something you should ever need to do in a VIP theme context. Instead use an API (XML-RPC, REST) to interact with other sites if needed.', - 'functions' => array( 'switch_to_blog' ), - ), - - 'file_get_contents' => array( - 'type' => 'warning', - 'message' => '%s() is highly discouraged, please use wpcom_vip_file_get_contents() instead.', - 'functions' => array( - 'file_get_contents', - 'vip_wp_file_get_contents', - ), - ), - - 'wpcom_vip_get_term_link' => array( - 'type' => 'error', - 'message' => '%s() is deprecated, please use get_term_link(), get_tag_link(), or get_category_link() instead.', - 'functions' => array( - 'wpcom_vip_get_term_link', - ), - ), - - 'get_page_by_path' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_get_page_by_path() instead.', - 'functions' => array( - 'get_page_by_path', - ), - ), - - 'get_page_by_title' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_get_page_by_title() instead.', - 'functions' => array( - 'get_page_by_title', - ), - ), - - 'wpcom_vip_get_term_by' => array( - 'type' => 'error', - 'message' => '%s() is deprecated, please use get_term_by() or get_cat_ID() instead.', - 'functions' => array( - 'wpcom_vip_get_term_by', - ), - ), - - 'wpcom_vip_get_category_by_slug' => array( - 'type' => 'error', - 'message' => '%s() is deprecated, please use get_category_by_slug() instead.', - 'functions' => array( - 'wpcom_vip_get_category_by_slug', - ), - ), - - 'url_to_postid' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_url_to_postid() instead.', - 'functions' => array( - 'url_to_postid', - 'url_to_post_id', - ), - ), - - 'attachment_url_to_postid' => array( - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_attachment_url_to_postid() instead.', - 'functions' => array( - 'attachment_url_to_postid', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#remote-calls - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#remote-calls - 'wp_remote_get' => array( - 'type' => 'warning', - 'message' => '%s() is highly discouraged, please use vip_safe_wp_remote_get() instead.', - 'functions' => array( - 'wp_remote_get', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#custom-roles - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#custom-roles - 'custom_role' => array( - 'type' => 'error', - 'message' => 'Use wpcom_vip_add_role() instead of %s()', - 'functions' => array( - 'add_role', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#custom-roles - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#cache-constraints - 'cookies' => array( - 'type' => 'warning', - 'message' => 'Due to using Batcache, server side based client related logic will not work, use JS instead.', - 'functions' => array( - 'setcookie', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#wp_users-and-user_meta - 'user_meta' => array( - 'type' => 'error', - 'message' => '%s() usage is highly discouraged, check VIP documentation on "Working with wp_users"', - 'functions' => array( - 'get_user_meta', - 'update_user_meta', - 'delete_user_meta', - 'add_user_meta', - ), - ), - - // @todo Introduce a sniff specific to get_posts() that checks for suppress_filters=>false being supplied. - 'get_posts' => array( - 'type' => 'warning', - 'message' => '%s() is discouraged in favor of creating a new WP_Query() so that Advanced Post Cache will cache the query, unless you explicitly supply suppress_filters => false.', - 'functions' => array( - 'get_posts', - 'wp_get_recent_posts', - 'get_children', - ), - ), - - 'term_exists' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_term_exists() instead.', - 'functions' => array( - 'term_exists', - ), - ), - - 'count_user_posts' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_count_user_posts() instead.', - 'functions' => array( - 'count_user_posts', - ), - ), - - 'wp_old_slug_redirect' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_old_slug_redirect() instead.', - 'functions' => array( - 'wp_old_slug_redirect', - ), - ), - - 'get_adjacent_post' => array( - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_get_adjacent_post() instead.', - 'functions' => array( - 'get_adjacent_post', - 'get_previous_post', - 'get_previous_post_link', - 'get_next_post', - 'get_next_post_link', - ), - ), - - 'get_intermediate_image_sizes' => array( - 'type' => 'error', - 'message' => 'Intermediate images do not exist on the VIP platform, and thus get_intermediate_image_sizes() returns an empty array() on the platform. This behavior is intentional to prevent WordPress from generating multiple thumbnails when images are uploaded.', - 'functions' => array( - 'get_intermediate_image_sizes', - ), - ), - - // @link WordPress.com: https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#mobile-detection - // @link VIP Go: https://vip.wordpress.com/documentation/vip-go/code-review-blockers-warnings-notices/#mobile-detection - 'wp_is_mobile' => array( - 'type' => 'error', - 'message' => '%s() found. When targeting mobile visitors, jetpack_is_mobile() should be used instead of wp_is_mobile. It is more robust and works better with full page caching.', - 'functions' => array( - 'wp_is_mobile', - ), - ), - ); - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php deleted file mode 100644 index 37a5326003..0000000000 --- a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php +++ /dev/null @@ -1,113 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of variables to restrict. - * - * Example: groups => array( - * 'wpdb' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Dont use this one please!', - * 'variables' => array( '$val', '$var' ), - * 'object_vars' => array( '$foo->bar', .. ), - * 'array_members' => array( '$foo['bar']', .. ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - return array( - // @link https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#wp_users-and-user_meta - 'user_meta' => array( - 'type' => 'error', - 'message' => 'Usage of users/usermeta tables is highly discouraged in VIP context, For storing user additional user metadata, you should look at User Attributes.', - 'object_vars' => array( - '$wpdb->users', - '$wpdb->usermeta', - ), - ), - - // @link https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#caching-constraints - 'cache_constraints' => array( - 'type' => 'warning', - 'message' => 'Due to using Batcache, server side based client related logic will not work, use JS instead.', - 'variables' => array( - '$_COOKIE', - ), - 'array_members' => array( - '$_SERVER[\'HTTP_USER_AGENT\']', - '$_SERVER[\'REMOTE_ADDR\']', - ), - ), - ); - } - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php deleted file mode 100644 index 3554e2bbde..0000000000 --- a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php +++ /dev/null @@ -1,126 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Groups of functions to restrict. - * - * Example: groups => array( - * 'lambda' => array( - * 'type' => 'error' | 'warning', - * 'message' => 'Use anonymous functions instead please!', - * 'functions' => array( 'file_get_contents', 'create_function' ), - * ) - * ) - * - * @return array - */ - public function getGroups() { - return array( - 'session' => array( - 'type' => 'error', - 'message' => 'The use of PHP session function %s() is prohibited.', - 'functions' => array( - 'session_abort', - 'session_cache_expire', - 'session_cache_limiter', - 'session_commit', - 'session_create_id', - 'session_decode', - 'session_destroy', - 'session_encode', - 'session_gc', - 'session_get_cookie_params', - 'session_id', - 'session_is_registered', - 'session_module_name', - 'session_name', - 'session_regenerate_id', - 'session_register_shutdown', - 'session_register', - 'session_reset', - 'session_save_path', - 'session_set_cookie_params', - 'session_set_save_handler', - 'session_start', - 'session_status', - 'session_unregister', - 'session_unset', - 'session_write_close', - ), - ), - ); - } - - - /** - * Process the token and handle the deprecation notices. - * - * @since 1.0.0 Added to allow for throwing the deprecation notices. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php deleted file mode 100644 index 945807b450..0000000000 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ /dev/null @@ -1,81 +0,0 @@ - false, - ); - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() { - return array( - \T_VARIABLE, - ); - } - - /** - * Process the token and handle the deprecation notice. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionVariableUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( '$_SESSION' === $this->tokens[ $stackPtr ]['content'] ) { - $this->phpcsFile->addError( - 'Usage of $_SESSION variable is prohibited.', - $stackPtr, - 'SessionVarsProhibited' - ); - } - } - -} diff --git a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php deleted file mode 100644 index 20c6eae42e..0000000000 --- a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php +++ /dev/null @@ -1,76 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SlowDBQuery" sniff has been renamed to "WordPress.DB.SlowDBQuery". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SlowDBQuery" sniff has been renamed to "WordPress.DB.SlowDBQuery". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php deleted file mode 100644 index 403317f9da..0000000000 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ /dev/null @@ -1,87 +0,0 @@ - false, - ); - - /** - * Returns an array of tokens this test wants to listen for. - * - * @return array - */ - public function register() { - return array( - \T_VARIABLE, - ); - } - - /** - * Process the token and handle the deprecation notice. - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SuperGlobalInputUsage" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - // Check for global input variable. - if ( ! \in_array( $this->tokens[ $stackPtr ]['content'], $this->input_superglobals, true ) ) { - return; - } - - $varName = $this->tokens[ $stackPtr ]['content']; - - // If we're overriding a superglobal with an assignment, no need to test. - if ( $this->is_assignment( $stackPtr ) ) { - return; - } - - // Check for whitelisting comment. - if ( ! $this->has_whitelist_comment( 'input var', $stackPtr ) ) { - $this->phpcsFile->addWarning( 'Detected access of super global var %s, probably needs manual inspection.', $stackPtr, 'AccessDetected', array( $varName ) ); - } - } - -} diff --git a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php deleted file mode 100644 index 395008a7d3..0000000000 --- a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php +++ /dev/null @@ -1,75 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.TimezoneChange" sniff has been renamed to "WordPress.WP.TimezoneChange". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.TimezoneChange" sniff has been renamed to "WordPress.WP.TimezoneChange". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php deleted file mode 100644 index 699c00463e..0000000000 --- a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php +++ /dev/null @@ -1,77 +0,0 @@ - false, - 'FoundPropertyForDeprecatedSniff' => false, - ); - - /** - * Don't use. - * - * @deprecated 1.0.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return void|int - */ - public function process_token( $stackPtr ) { - if ( false === $this->thrown['DeprecatedSniff'] ) { - $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.ValidatedSanitizedInput" sniff has been renamed to "WordPress.Security.ValidatedSanitizedInput". Please update your custom ruleset.', - 0, - 'DeprecatedSniff' - ); - } - - if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] - && ( ( array() !== $this->customSanitizingFunctions && $this->customSanitizingFunctions !== $this->addedCustomFunctions['sanitize'] ) - || ( array() !== $this->customUnslashingSanitizingFunctions && $this->customUnslashingSanitizingFunctions !== $this->addedCustomFunctions['unslashsanitize'] ) - || false !== $this->check_validation_in_scope_only ) - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.ValidatedSanitizedInput" sniff has been renamed to "WordPress.Security.ValidatedSanitizedInput". Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - - return parent::process_token( $stackPtr ); - } - -} diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc index 50624e4346..e3120a8816 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc @@ -111,6 +111,6 @@ $bad = array( 'key1' => 'value1', 'key2' => 'value2' ); // Bad. // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed index bc003ef79a..71b8d9c8f3 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed @@ -166,6 +166,6 @@ $bad = array( // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc index 26436a0757..ff971e9177 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc @@ -94,6 +94,6 @@ $bad = [ 'key1' => 'value1', 'key2' => 'value2' ]; // Bad. // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed index 9805c7c8ff..23c25a07b2 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed @@ -150,6 +150,6 @@ $bad = [ // @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ - 'meta_key' => 'foo', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key - 'meta_value' => 'bar', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value + 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode + 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.css b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.css deleted file mode 100644 index 84d55d0d9a..0000000000 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.css +++ /dev/null @@ -1,55 +0,0 @@ -#wpadminbar { - display: block; /* OK. */ - visibility: visible; /* OK. */ - opacity: 1; /* OK. */ - color: red; /* OK. */ -} - -#not-wpadminbar { - display: none; /* OK. */ - visibility: hidden; /* OK. */ - opacity: 0; /* OK. */ -} - -#wpadminbar { - display: none; /* Bad. */ - visibility: hidden; /* Bad. */ - opacity: 0; /* Bad. */ -} - -/* With !important. */ -#wpadminbar { - display: none !important; /* Bad. */ - visibility: hidden !important; /* Bad. */ - opacity: 0.0 !important; /* Bad. */ -} - -/* Indented. */ - .show-admin-bar { - visibility: hidden; /* Bad. */ - display: none !important; /* Bad. */ - opacity: 0; /* Bad. */ - } - -/* Multi-line selector. */ -.something-else, -.show-admin-bar, -#identifier { - visibility: hidden; /* Bad. */ - display: none !important; /* Bad. */ - opacity: 0; /* Bad. */ -} - - -/* @codingStandardsChangeSetting WordPress.VIP.AdminBarRemoval remove_only false */ -#wpadminbar { - display: block; /* Bad. */ - visibility: visible; /* Bad. */ - opacity: 1; /* Bad. */ -} -#not-wpadminbar { - display: none; /* OK. */ - visibility: hidden; /* OK. */ - opacity: 0; /* OK. */ -} -/* @codingStandardsChangeSetting WordPress.VIP.AdminBarRemoval remove_only true */ diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc deleted file mode 100644 index eb47174e9a..0000000000 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.inc +++ /dev/null @@ -1,108 +0,0 @@ - -#wpadminbar { - visibility: hidden; /* Bad. */ - display: none; /* Bad. */ - opacity: 0; /* Bad. */ -} -'; - -// Various text before/after combinations. -echo ''; // Bad. - -echo 'Some text about .show-admin-bar before a style tag '; // Ok. -echo 'Some text about .show-admin-bar after a style tag'; // Ok. - -echo ''; - -// Testing T_DOUBLE_QUOTED_STRING. -echo " -"; - -// Testing T_HEREDOC. -$style = << - .show-admin-bar { - visibility: $hidden; /* Ok, value not 'hidden'. */ - } - -EOT; - -// Testing T_NOWDOC. -$style = <<<'EOT' - -EOT; - -// Testing T_INLINE_HTML -?> - - - - - - - .show-admin-bar { - visibility: $hidden; /* Bad. */ - } - .my-admin-bar { - visibility: $hidden; /* OK. */ - } - -EOT; -?> - - -/* @codingStandardsChangeSetting WordPress.VIP.AdminBarRemoval remove_only true */ diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php deleted file mode 100644 index d6b7a06516..0000000000 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php +++ /dev/null @@ -1,105 +0,0 @@ - => - */ - public function getErrorList( $testFile = '' ) { - - switch ( $testFile ) { - case 'AdminBarRemovalUnitTest.inc': - return array( - 3 => 1, - 6 => 1, - 9 => 1, - 12 => 1, - 13 => 1, - 19 => 1, - 20 => 1, - 21 => 1, - 26 => 1, - 32 => 1, - 56 => 1, - 57 => 1, - 58 => 1, - 68 => 1, - 69 => 1, - 70 => 1, - 81 => 1, - 82 => 1, - 83 => 1, - 92 => 1, - 103 => 1, - 104 => 1, - 105 => 1, - ); - - case 'AdminBarRemovalUnitTest.css': - return array( - 15 => 1, - 16 => 1, - 17 => 1, - 22 => 1, - 23 => 1, - 24 => 1, - 29 => 1, - 30 => 1, - 31 => 1, - 38 => 1, - 39 => 1, - 40 => 1, - 46 => 1, - 47 => 1, - 48 => 1, - ); - - default: - return array(); - } - } - - /** - * Returns the lines where warnings should occur. - * - * @param string $testFile The name of the file being tested. - * @return array => - */ - public function getWarningList( $testFile = '' ) { - switch ( $testFile ) { - case 'AdminBarRemovalUnitTest.css': - return array( - 1 => 2, - ); - - case 'AdminBarRemovalUnitTest.inc': - return array(); - - default: - return array(); - } - } -} diff --git a/WordPress/Tests/VIP/CronIntervalUnitTest.inc b/WordPress/Tests/VIP/CronIntervalUnitTest.inc deleted file mode 100644 index 51e6582bac..0000000000 --- a/WordPress/Tests/VIP/CronIntervalUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 4 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc b/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc deleted file mode 100644 index a8799948e3..0000000000 --- a/WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc deleted file mode 100644 index 4a5c2b23e1..0000000000 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc +++ /dev/null @@ -1,49 +0,0 @@ - $loop ) { - if ( flock( $fp, LOCK_EX ) ) { // Bad. - fwrite( $fp, $text ); // Bad. - } - flock( $fp, LOCK_UN ); // Bad. -} - -fclose( $fp ); - -delete(); -fputcsv(); -fputs(); -ftruncate(); -is_writable(); -is_writeable(); -link(); -rename(); -symlink(); -tempnam(); -touch(); -unlink(); - -mkdir(); -rmdir(); - -chgrp(); -chown(); -chmod(); -lchgrp(); -lchown(); - -// @codingStandardsChangeSetting WordPress.VIP.FileSystemWritesDisallow exclude directory -mkdir(); - -// @codingStandardsChangeSetting WordPress.VIP.FileSystemWritesDisallow exclude false - - -// Issue #956. -use Fieldmanager_Link as Link; - -namespace Fieldmanager\Link\Something; -namespace Fieldmanager\Link; diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php deleted file mode 100644 index b5d30f8a56..0000000000 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php +++ /dev/null @@ -1,68 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 1, - 9 => 1, - 10 => 1, - 12 => 1, - 17 => 1, - 18 => 1, - 19 => 1, - 20 => 1, - 21 => 1, - 22 => 1, - 23 => 1, - 24 => 1, - 25 => 1, - 26 => 1, - 27 => 1, - 28 => 1, - 30 => 1, - 31 => 1, - 33 => 1, - 34 => 1, - 35 => 1, - 36 => 1, - 37 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.inc b/WordPress/Tests/VIP/OrderByRandUnitTest.inc deleted file mode 100644 index 0a722377df..0000000000 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.inc +++ /dev/null @@ -1,18 +0,0 @@ - 'rand', // Bad. - "orderby" => "rand", // Bad. - "orderby" => "RAND", // Bad. -); - -_query_posts( 'orderby=rand' ); // Bad. - -$query_args['orderby'] = 'rand'; // Bad. - -$query_args['orderby'] = 'date'; // Ok. - -// @codingStandardsChangeSetting WordPress.VIP.OrderByRand exclude something -$query_args['orderby'] = 'rand'; // Bad. - -// @codingStandardsChangeSetting WordPress.VIP.OrderByRand exclude false \ No newline at end of file diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.php b/WordPress/Tests/VIP/OrderByRandUnitTest.php deleted file mode 100644 index 084eedfd33..0000000000 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.php +++ /dev/null @@ -1,51 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - 5 => 1, - 6 => 1, - 9 => 1, - 11 => 1, - 16 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc b/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc deleted file mode 100644 index a625119c1d..0000000000 --- a/WordPress/Tests/VIP/PluginMenuSlugUnitTest.inc +++ /dev/null @@ -1,3 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc b/WordPress/Tests/VIP/PostsPerPageUnitTest.inc deleted file mode 100644 index 25e92fbe54..0000000000 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.inc +++ /dev/null @@ -1,24 +0,0 @@ - true, // Bad. - 'posts_per_page' => 999, // OK. - 'posts_per_page' => -1, // Bad. - 'posts_per_page' => 1, // Ok. - 'posts_per_page' => '1', // Ok. -); - -_query_posts( 'nopaging=true&posts_per_page=999' ); // Bad. - -$query_args['posts_per_page'] = -1; // Bad. -$query_args['posts_per_page'] = 1; // OK. -$query_args['posts_per_page'] = '1'; // OK. -$query_args['posts_per_page'] = '-1'; // Bad. -$query_args['numberposts'] = '-1'; // Bad. - -$query_args['my_posts_per_page'] = -1; // OK. - -// Test deprecated property message. -// @codingStandardsChangeSetting WordPress.VIP.PostsPerPage posts_per_page 50 -$query_args['posts_per_page'] = 50; // OK. -// @codingStandardsChangeSetting WordPress.VIP.PostsPerPage posts_per_page 100 diff --git a/WordPress/Tests/VIP/PostsPerPageUnitTest.php b/WordPress/Tests/VIP/PostsPerPageUnitTest.php deleted file mode 100644 index c4ba575911..0000000000 --- a/WordPress/Tests/VIP/PostsPerPageUnitTest.php +++ /dev/null @@ -1,54 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - 6 => 1, - 11 => 1, - 13 => 1, - 16 => 1, - 17 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc deleted file mode 100644 index f0f06d3a1b..0000000000 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc +++ /dev/null @@ -1,89 +0,0 @@ -add_role(); // Ok. -$y = Bar::add_role(); // Ok. -\SomeNamespace\add_role(); // Ok. - -\add_role(); // Error. - -wpcom_vip_get_term_link( $term ); // Error. - -get_page_by_path( $path ); // Error. - -get_page_by_title( $page_title ); // Error. - -wpcom_vip_get_term_by( $field, $value, $taxonomy ); // Error. - -wpcom_vip_get_category_by_slug( $slug ); // Error. - -url_to_postid( $url ); // Error. - -attachment_url_to_postid( $url ); // Error. -wpcom_vip_attachment_url_to_postid( $url ); // Ok. - -get_tag_link(); // Ok. -get_category_link(); // Ok. -get_cat_ID(); // Ok. -url_to_post_id(); // Error. - -get_posts(); // Warning. -wp_get_recent_posts(); // Warning. - -get_children(); // Warning. - - - - -term_exists(); // Error. -count_user_posts(); // Error. -wp_old_slug_redirect(); // Error. -get_adjacent_post(); // Error. -get_previous_post(); // Error. -get_next_post(); // Error. - - - - -get_previous_post_link(); // Error. -get_next_post_link(); // Error. -get_intermediate_image_sizes(); // Error. - - -wp_is_mobile(); // Error. - -setcookie( 'cookie[three]', 'cookiethree' ); // Warning. - -get_user_meta(); // Error. -update_user_meta(); // Error. -delete_user_meta(); // Error. -add_user_meta(); // Error. - -// @codingStandardsChangeSetting WordPress.VIP.RestrictedFunctions exclude switch_to_blog -switch_to_blog( $blogid ); // Error. - -// @codingStandardsChangeSetting WordPress.VIP.RestrictedFunctions exclude false diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php deleted file mode 100644 index b2cb717aba..0000000000 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php +++ /dev/null @@ -1,77 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 1, - 17 => 1, - 32 => 1, - 34 => 1, - 36 => 1, - 38 => 1, - 40 => 1, - 42 => 1, - 44 => 1, - 46 => 1, - 52 => 1, - 62 => 1, - 63 => 1, - 64 => 1, - 65 => 1, - 66 => 1, - 67 => 1, - 72 => 1, - 73 => 1, - 74 => 1, - 77 => 1, - 81 => 1, - 82 => 1, - 83 => 1, - 84 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 5 => 1, - 7 => 1, - 9 => 1, - 54 => 1, - 55 => 1, - 57 => 1, - 79 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc deleted file mode 100644 index b4b3a65c48..0000000000 --- a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc +++ /dev/null @@ -1,34 +0,0 @@ -users"; // Error. - -$wp_db->update( $wpdb->users, array( 'displayname' => 'Kanobe!' ), array( 'ID' => 1 ) ); // Error. - -$query = "SELECT * FROM $wpdb->usermeta"; // Error. - -$wp_db->update( $wpdb->usermeta, array( 'meta_value' => 'bar!' ), array( 'user_id' => 1, 'meta_key' => 'foo' ) ); // Error. - -$query = "SELECT * FROM $wpdb->posts"; // Ok. - -if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // Warning. - foo( $_SERVER['HTTP_USER_AGENT'] ); // Warning. -} - -$x = $_COOKIE['bar']; // Warning. - -$y = $_SERVER['REQUEST_URI']; // Ok. - -// Error. -$query = <<usermeta -EOD; - -// Warning -$phrase = << => - */ - public function getErrorList() { - return array( - 3 => 1, - 5 => 1, - 7 => 1, - 9 => 1, - 23 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 13 => 1, - 14 => 1, - 17 => 1, - 28 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc deleted file mode 100644 index 086fdab098..0000000000 --- a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc +++ /dev/null @@ -1,34 +0,0 @@ - => - */ - public function getErrorList() { - return array_fill( 3, 26, 1 ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc b/WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc deleted file mode 100644 index d635ed98fa..0000000000 --- a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.inc +++ /dev/null @@ -1,4 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 3 => 1, - 4 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/SlowDBQueryUnitTest.inc b/WordPress/Tests/VIP/SlowDBQueryUnitTest.inc deleted file mode 100644 index 749e23d1e0..0000000000 --- a/WordPress/Tests/VIP/SlowDBQueryUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - 4 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc b/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc deleted file mode 100644 index 449117850a..0000000000 --- a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.inc +++ /dev/null @@ -1,23 +0,0 @@ - - // Do something. - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 1, - 3 => 1, - 13 => 1, - 15 => 1, - ); - } - -} diff --git a/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc b/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc deleted file mode 100644 index b49ed63821..0000000000 --- a/WordPress/Tests/VIP/TimezoneChangeUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc deleted file mode 100644 index 01950abed5..0000000000 --- a/WordPress/Tests/VIP/ValidatedSanitizedInputUnitTest.inc +++ /dev/null @@ -1,6 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 3, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 1 => 2, - ); - } - -} diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index cd3cd73dff..505d42a273 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -6,17 +6,7 @@ - - - - - - - - - - - + - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - From 969a8054f6c699652e57c4e681018c772f2499f0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:17:59 +0100 Subject: [PATCH 03/64] WPCS 2.0.0: Remove deprecated Sniff::has_html_open_tag() method --- WordPress/Sniff.php | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 461faad62f..92660c6a5b 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2326,41 +2326,6 @@ public function get_declared_namespace_name( $stackPtr ) { return $namespaceName; } - /** - * Check if a content string contains a specific html open tag. - * - * @since 0.11.0 - * @since 0.13.0 No longer allows for the PHP 5.2 bug for which the function was - * originally created. - * @since 0.13.0 The $stackPtr parameter is now optional. Either that or the - * $content parameter has to be passed. - * @deprecated 1.0.0 This method is only used by deprecated sniffs. - * - * @param string $tag_name The name of the HTML tag without brackets. So if - * searching for ' open tag, false otherwise. - */ - public function has_html_open_tag( $tag_name, $stackPtr = null, $content = false ) { - if ( false === $content && isset( $stackPtr ) ) { - $content = $this->tokens[ $stackPtr ]['content']; - } - - if ( ! empty( $content ) && false !== strpos( $content, '<' . $tag_name ) ) { - return true; - } - - return false; - } - /** * Check whether a T_CONST token is a class constant declaration. * From 71ddaac06d673249f141f8d94e71c5c812b816f6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 6 Nov 2018 01:23:22 +0100 Subject: [PATCH 04/64] PrefixAllGlobals: use separate errorcodes for warning vs error While cleaning up a plugin, I noticed that the issue count for the `WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound` error code was different if I ran phpcs with the `-n` flag (no warnings). Error codes should be unique. Having the same error code for something which is mandatory (`error`) and recommended (`warning`) is bad practice and does not properly allow for modular disabling of notices. This PR fixes this. This is a breaking change as for the warnings, ``s for the old errorcode currently in custom rulesets will be invalidated by it, so this PR should go into WPCS 2.0.0. --- .../Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 43d5a2b9a7..796c65de58 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -794,9 +794,15 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $data = array( 'Global constants defined' ); $error_code = 'NonPrefixedConstantFound'; + if ( false === $is_error ) { + $error_code = 'VariableConstantNameFound'; + } } else { $data = array( 'Hook names invoked' ); $error_code = 'NonPrefixedHooknameFound'; + if ( false === $is_error ) { + $error_code = 'DynamicHooknameFound'; + } } $data[] = $raw_content; From 7b920b48ff9d49342b18ec1b989dbba5dec73ec8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 14 Aug 2018 18:56:05 +0200 Subject: [PATCH 05/64] NonceVerification: use separate errorcodes for warning vs error While cleaning up a plugin, I noticed that the issue count for the `WordPress.Security.NonceVerification.NoNonceVerification` error code was different if I ran phpcs with the `-n` flag (no warnings). Error codes should be unique. Having the same error code for something which is mandatory (`error`) and recommended (`warning`) is bad practice and does not properly allow for modular disabling of notices. This PR fixes this. As the error code is changing anyhow, I figured it made sense to also remove the duplication of the sniff name from the code. This is a breaking change as ``s for the old errorcode currently in custom rulesets will be invalidated by it, so this PR should go into WPCS 2.0.0. N.B.: The ruleset change is necessary until the deprecated sniffs have been removed. --- WordPress/Sniffs/Security/NonceVerificationSniff.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index 4909a01f99..d3d6a9d40f 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -155,12 +155,17 @@ public function process_token( $stackPtr ) { return; } + $error_code = 'Missing'; + if ( false === $this->superglobals[ $instance['content'] ] ) { + $error_code = 'Recommended'; + } + // If we're still here, no nonce-verification function was found. $this->addMessage( 'Processing form data without nonce verification.', $stackPtr, $this->superglobals[ $instance['content'] ], - 'NoNonceVerification' + $error_code ); } From 405f264544d7fa16899c1423b6ed4e2a045b8897 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:17:37 +0100 Subject: [PATCH 06/64] WPCS 2.0.0: Remove deprecated properties ... and code related to them. --- .../ValidVariableNameSniff.php | 29 +---------------- .../Sniffs/Security/EscapeOutputSniff.php | 32 ++----------------- .../Security/NonceVerificationSniff.php | 26 --------------- 3 files changed, 3 insertions(+), 84 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 2325514ad2..4a364e1a5c 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -116,16 +116,6 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { 'variables' => null, ); - /** - * Custom list of properties which can have mixed case. - * - * @since 0.10.0 - * @deprecated 0.11.0 Use $customPropertiesWhitelist instead. - * - * @var string|string[] - */ - public $customVariablesWhitelist = array(); - /** * Processes this test, when one of its tokens is encountered. * @@ -303,33 +293,16 @@ public static function isSnakeCase( $var_name ) { * @return void */ protected function mergeWhiteList( File $phpcs_file ) { - if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] - || $this->customVariablesWhitelist !== $this->addedCustomProperties['variables'] - ) { + if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] ) { // Fix property potentially passed as comma-delimited string. $customProperties = Sniff::merge_custom_array( $this->customPropertiesWhitelist, array(), false ); - if ( ! empty( $this->customVariablesWhitelist ) ) { - $customProperties = Sniff::merge_custom_array( - $this->customVariablesWhitelist, - $customProperties, - false - ); - - $phpcs_file->addWarning( - 'The customVariablesWhitelist property is deprecated in favor of customPropertiesWhitelist.', - 0, - 'DeprecatedCustomVariablesWhitelist' - ); - } - $this->whitelisted_mixed_case_member_var_names = Sniff::merge_custom_array( $customProperties, $this->whitelisted_mixed_case_member_var_names ); $this->addedCustomProperties['properties'] = $this->customPropertiesWhitelist; - $this->addedCustomProperties['variables'] = $this->customVariablesWhitelist; } } diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index abb66540d0..428b0fc3a5 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -48,17 +48,6 @@ class EscapeOutputSniff extends Sniff { */ public $customAutoEscapedFunctions = array(); - /** - * Custom list of functions which escape values for output. - * - * @since 0.3.0 - * @deprecated 0.5.0 Use $customEscapingFunctions instead. - * @see \WordPress\Sniffs\Security\EscapeOutputSniff::$customEscapingFunctions - * - * @var string|string[] - */ - public $customSanitizingFunctions = array(); - /** * Custom list of functions which print output incorporating the passed values. * @@ -493,32 +482,15 @@ public function process_token( $stackPtr ) { * @return void */ protected function mergeFunctionLists() { - if ( $this->customEscapingFunctions !== $this->addedCustomFunctions['escape'] - || $this->customSanitizingFunctions !== $this->addedCustomFunctions['sanitize'] - ) { + if ( $this->customEscapingFunctions !== $this->addedCustomFunctions['escape'] ) { $customEscapeFunctions = $this->merge_custom_array( $this->customEscapingFunctions, array(), false ); - if ( ! empty( $this->customSanitizingFunctions ) ) { - $customEscapeFunctions = $this->merge_custom_array( - $this->customSanitizingFunctions, - $customEscapeFunctions, - false - ); - - $this->phpcsFile->addWarning( - 'The customSanitizingFunctions property is deprecated in favor of customEscapingFunctions.', - 0, - 'DeprecatedCustomSanitizingFunctions' - ); - } - $this->escapingFunctions = $this->merge_custom_array( $customEscapeFunctions, $this->escapingFunctions ); - $this->addedCustomFunctions['escape'] = $this->customEscapingFunctions; - $this->addedCustomFunctions['sanitize'] = $this->customSanitizingFunctions; + $this->addedCustomFunctions['escape'] = $this->customEscapingFunctions; } if ( $this->customAutoEscapedFunctions !== $this->addedCustomFunctions['autoescape'] ) { diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index 4909a01f99..1d80b0b87b 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -40,32 +40,6 @@ class NonceVerificationSniff extends Sniff { '$_REQUEST' => false, ); - /** - * Superglobals to give an error for when not accompanied by an nonce check. - * - * @since 0.5.0 - * @since 0.11.0 Changed visibility from public to protected. - * - * @deprecated 0.12.0 Replaced by $superglobals property. - * - * @var array - */ - protected $errorForSuperGlobals = array(); - - /** - * Superglobals to give a warning for when not accompanied by an nonce check. - * - * If the variable is also in the error list, that takes precedence. - * - * @since 0.5.0 - * @since 0.11.0 Changed visibility from public to protected. - * - * @deprecated 0.12.0 Replaced by $superglobals property. - * - * @var array - */ - protected $warnForSuperGlobals = array(); - /** * Custom list of functions which verify nonces. * From 0d314d0737e1092c40690ad7a070f3bf3a2b5716 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 04:55:08 +0100 Subject: [PATCH 07/64] WPCS 2.0.0: Set the minimum required PHPCS version to 3.3.1 / PHP 5.4 --- .github/CONTRIBUTING.md | 2 +- .github/ISSUE_TEMPLATE/dependency-change.md | 2 +- .phpcs.xml.dist | 5 +-- .travis.yml | 38 +++------------------ README.md | 12 +++---- composer.json | 4 +-- 6 files changed, 13 insertions(+), 50 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a497a78486..a70d94d195 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -77,7 +77,7 @@ When you introduce a new whitelist comment, please don't forget to update the [w ## Pre-requisites * WordPress-Coding-Standards -* PHP_CodeSniffer 2.9.x or 3.x +* PHP_CodeSniffer 3.3.1 or higher * PHPUnit 4.x, 5.x, 6.x or 7.x The WordPress Coding Standards use the PHP_CodeSniffer native unit test suite for unit testing the sniffs. diff --git a/.github/ISSUE_TEMPLATE/dependency-change.md b/.github/ISSUE_TEMPLATE/dependency-change.md index 740abf51ad..1208b19678 100644 --- a/.github/ISSUE_TEMPLATE/dependency-change.md +++ b/.github/ISSUE_TEMPLATE/dependency-change.md @@ -4,7 +4,7 @@ about: A reminder to take action when a WPCS dependency changes --- - + ## Rationale diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index ec29a1708c..4bb6850731 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -35,7 +35,7 @@ - + @@ -47,9 +47,6 @@ - - - diff --git a/.travis.yml b/.travis.yml index 74ad0a2745..18cc71e459 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,10 +26,8 @@ php: env: # `master` is now 3.x. - PHPCS_BRANCH="dev-master" LINT=1 - # Lowest supported release in the 3.x series with which WPCS is compatible (and which can run the unit tests). - - PHPCS_BRANCH="3.1.0" - # Lowest tagged release in the 2.x series with which WPCS is compatible. - - PHPCS_BRANCH="2.9.0" + # Lowest supported release in the 3.x series with which WPCS is compatible. + - PHPCS_BRANCH="3.3.1" matrix: fast_finish: true @@ -42,22 +40,9 @@ matrix: packages: - libxml2-utils - # Test PHP 5.3 only against PHPCS 2.x as PHPCS 3.x has a minimum requirement of PHP 5.4. - - php: 5.3 - env: PHPCS_BRANCH="2.9.*" LINT=1 - dist: precise - # Test PHP 5.3 with short_open_tags set to On (is Off by default) - - php: 5.3 - env: PHPCS_BRANCH="2.9.0" SHORT_OPEN_TAGS=true - dist: precise - allow_failures: # Allow failures for unstable builds. - php: nightly - - php: 7.3 - env: PHPCS_BRANCH="3.1.0" - - php: 7.3 - env: PHPCS_BRANCH="2.9.0" before_install: # Speed up build time by disabling Xdebug. @@ -66,13 +51,7 @@ before_install: - phpenv config-rm xdebug.ini || echo 'No xdebug config.' - export XMLLINT_INDENT=" " - export PHPUNIT_DIR=/tmp/phpunit - - | - if [[ ${PHPCS_BRANCH:0:2} == "2." ]]; then - # --prefer-source is needed to ensure that the PHPCS unit test suite is available in PHPCS 2.9. - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --prefer-source --update-no-dev --no-suggest --no-scripts - else - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts - fi + - composer require squizlabs/php_codesniffer:${PHPCS_BRANCH} --update-no-dev --no-suggest --no-scripts - | if [[ "$SNIFF" == "1" ]]; then composer install --dev --no-suggest @@ -81,21 +60,12 @@ before_install: # The above require already does the install. $(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd) fi - # Download PHPUnit 5.x for builds on PHP 7 and nightly as the PHPCS - # test suite is currently not compatible with PHPUnit 6.x. - # Fixed at a very specific PHPUnit version. - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." ]]; then wget -P $PHPUNIT_DIR https://phar.phpunit.de/phpunit-5.7.17.phar && chmod +x $PHPUNIT_DIR/phpunit-5.7.17.phar; fi - # Selectively adjust the ini values for the build image to test ini value dependent sniff features. - - if [[ "$SHORT_OPEN_TAGS" == "true" ]]; then echo "short_open_tag = On" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then phpunit --filter WordPress $(pwd)/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} == "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/Test/AllTests.php; fi - - if [[ ${TRAVIS_PHP_VERSION:0:2} != "5." && ${PHPCS_BRANCH:0:2} != "2." ]]; then php $PHPUNIT_DIR/phpunit-5.7.17.phar --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php; fi + - phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. # For the first run, the exit code will be 1 (= all fixable errors fixed). diff --git a/README.md b/README.md index d672ea0ed4..8e9fc04d31 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![Last Commit to Unstable](https://img.shields.io/github/last-commit/WordPress-Coding-Standards/WordPress-Coding-Standards/develop.svg)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/commits/develop) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/wp-coding-standards/wpcs.svg?maxAge=3600)](https://packagist.org/packages/wp-coding-standards/wpcs) -[![Tested on PHP 5.3 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.3%20|%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%20nightly-green.svg?maxAge=2419200)](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards) +[![Tested on PHP 5.4 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%20nightly-green.svg?maxAge=2419200)](https://travis-ci.org/WordPress-Coding-Standards/WordPress-Coding-Standards) [![License: MIT](https://poser.pugx.org/wp-coding-standards/wpcs/license)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/LICENSE) [![Total Downloads](https://poser.pugx.org/wp-coding-standards/wpcs/downloads)](https://packagist.org/packages/wp-coding-standards/wpcs/stats) @@ -59,8 +59,7 @@ This project is a collection of [PHP_CodeSniffer](https://github.com/squizlabs/P ### Requirements -The WordPress Coding Standards require PHP 5.3 or higher and [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) version **2.9.0** or higher. -As of version 0.13.0, the WordPress Coding Standards are compatible with PHPCS 3.0.2+. In that case, the minimum PHP requirement is PHP 5.4. +The WordPress Coding Standards require PHP 5.4 or higher and [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) version **3.3.1** or higher. ### Composer @@ -75,7 +74,7 @@ Running this command will: 3. Register WordPress standards in PHP_CodeSniffer configuration. 4. Make `phpcs` command available from `wpcs/vendor/bin`. -For the convenience of using `phpcs` as a global command, you may want to add the path to the `wpcs/vendor/scripts` (PHPCS 2.x) and/or `wpcs/vendor/bin` (PHPCS 3.x) directories to a `PATH` environment variable for your operating system. +For the convenience of using `phpcs` as a global command, you may want to add the path to the `wpcs/vendor/bin` directory to a `PATH` environment variable for your operating system. #### Installing WPCS as a dependency @@ -113,13 +112,10 @@ cd ~/projects git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs cd phpcs -#PHPCS 2.x -./scripts/phpcs --config-set installed_paths ../wpcs -#PHPCS 3.x ./bin/phpcs --config-set installed_paths ../wpcs ``` -And then add the `~/projects/phpcs/scripts` (PHPCS 2.x) or `~/projects/phpcs/bin` (PHPCS 3.x) directory to your `PATH` environment variable via your `.bashrc`. +And then add the `~/projects/phpcs/bin` directory to your `PATH` environment variable via your `.bashrc`. You should then see `WordPress-Core` et al listed when you run `phpcs -i`. diff --git a/composer.json b/composer.json index db2f784258..f7511b0fb3 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ } ], "require": { - "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.3.1" }, "require-dev": { "phpcompatibility/php-compatibility": "^9.0" From df7f5dfc8c73d3a89ec3e0aa85619c9c4aedc8bd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 15:41:32 +0100 Subject: [PATCH 08/64] WPCS 2.0.0: Update the WPCS namespace To prevent conflicts with WordPress itself - especially now that WordPress will let go of the PHP 5.2 minimum supported version -, WPCS should not use the `WordPress` namespace. While PHPCS 2.x still needed to be supported, this could not be helped as it was a PHPCS requirement. Now that PHPCS 2.x support is being dropped, the namespace can be adjusted. Note: It is still a requirement that the namespace contains `StandardName\Sniffs\Category`, so we cannot replace `WordPress` with just `WordPressCS`. It has to be `WordPressCS\WordPress`. Note: This is a BC-break for any external standard which extends sniffs from WPCS. They will need to update their `use` statements to use the new WPCS namespace. Refs: * squizlabs/PHP_CodeSniffer 1469 * squizlabs/PHP_CodeSniffer 1569 * https://github.com/squizlabs/PHP_CodeSniffer/wiki/Version-3.0-Upgrade-Guide --- .github/CONTRIBUTING.md | 6 +++--- WordPress/AbstractArrayAssignmentRestrictionsSniff.php | 4 ++-- WordPress/AbstractClassRestrictionsSniff.php | 4 ++-- WordPress/AbstractFunctionParameterSniff.php | 4 ++-- WordPress/AbstractFunctionRestrictionsSniff.php | 4 ++-- WordPress/PHPCSAliases.php | 4 +++- WordPress/PHPCSHelper.php | 2 +- WordPress/Sniff.php | 4 ++-- WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php | 4 ++-- WordPress/Sniffs/Arrays/ArrayIndentationSniff.php | 6 +++--- .../Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php | 4 ++-- WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php | 4 ++-- WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php | 4 ++-- WordPress/Sniffs/Classes/ClassInstantiationSniff.php | 4 ++-- .../Sniffs/CodeAnalysis/AssignmentInConditionSniff.php | 4 ++-- WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php | 4 ++-- WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php | 4 ++-- WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php | 4 ++-- WordPress/Sniffs/DB/PreparedSQLSniff.php | 4 ++-- WordPress/Sniffs/DB/RestrictedClassesSniff.php | 4 ++-- WordPress/Sniffs/DB/RestrictedFunctionsSniff.php | 4 ++-- WordPress/Sniffs/DB/SlowDBQuerySniff.php | 4 ++-- WordPress/Sniffs/Files/FileNameSniff.php | 4 ++-- .../Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php | 4 ++-- .../Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 6 +++--- .../Sniffs/NamingConventions/ValidFunctionNameSniff.php | 2 +- WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php | 4 ++-- .../Sniffs/NamingConventions/ValidVariableNameSniff.php | 4 ++-- WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/DiscourageGotoSniff.php | 4 ++-- WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/DontExtractSniff.php | 4 ++-- WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php | 4 ++-- WordPress/Sniffs/PHP/POSIXFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php | 4 ++-- WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php | 4 ++-- WordPress/Sniffs/PHP/StrictComparisonsSniff.php | 4 ++-- WordPress/Sniffs/PHP/StrictInArraySniff.php | 4 ++-- WordPress/Sniffs/PHP/TypeCastsSniff.php | 4 ++-- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 4 ++-- WordPress/Sniffs/Security/EscapeOutputSniff.php | 4 ++-- WordPress/Sniffs/Security/NonceVerificationSniff.php | 4 ++-- WordPress/Sniffs/Security/PluginMenuSlugSniff.php | 4 ++-- WordPress/Sniffs/Security/SafeRedirectSniff.php | 4 ++-- WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php | 4 ++-- WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php | 4 ++-- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 4 ++-- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 4 ++-- WordPress/Sniffs/WP/CronIntervalSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedClassesSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php | 4 ++-- WordPress/Sniffs/WP/DeprecatedParametersSniff.php | 4 ++-- WordPress/Sniffs/WP/DiscouragedConstantsSniff.php | 4 ++-- WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php | 4 ++-- WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php | 4 ++-- WordPress/Sniffs/WP/EnqueuedResourcesSniff.php | 4 ++-- WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php | 4 ++-- WordPress/Sniffs/WP/I18nSniff.php | 6 +++--- WordPress/Sniffs/WP/PostsPerPageSniff.php | 4 ++-- WordPress/Sniffs/WP/TimezoneChangeSniff.php | 4 ++-- .../Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php | 4 ++-- WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php | 4 ++-- .../Sniffs/WhiteSpace/ControlStructureSpacingSniff.php | 4 ++-- WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php | 6 +++--- WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php | 2 +- WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php | 6 +++--- WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php | 2 +- WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php | 2 +- WordPress/Tests/Arrays/ArrayIndentationUnitTest.php | 2 +- .../Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php | 2 +- WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php | 2 +- .../Tests/Arrays/MultipleStatementAlignmentUnitTest.php | 2 +- WordPress/Tests/Classes/ClassInstantiationUnitTest.php | 2 +- .../Tests/CodeAnalysis/AssignmentInConditionUnitTest.php | 2 +- WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php | 2 +- WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php | 2 +- WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php | 2 +- WordPress/Tests/DB/PreparedSQLUnitTest.php | 2 +- WordPress/Tests/DB/RestrictedClassesUnitTest.php | 4 ++-- WordPress/Tests/DB/RestrictedFunctionsUnitTest.php | 2 +- WordPress/Tests/DB/SlowDBQueryUnitTest.php | 2 +- WordPress/Tests/Files/FileNameUnitTest.php | 2 +- .../Functions/FunctionCallSignatureNoParamsUnitTest.php | 2 +- .../Tests/NamingConventions/PrefixAllGlobalsUnitTest.php | 2 +- .../Tests/NamingConventions/ValidFunctionNameUnitTest.php | 2 +- WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php | 2 +- .../Tests/NamingConventions/ValidVariableNameUnitTest.php | 2 +- WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/DiscourageGotoUnitTest.php | 2 +- WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/DontExtractUnitTest.php | 2 +- WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php | 2 +- WordPress/Tests/PHP/POSIXFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php | 2 +- WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php | 2 +- WordPress/Tests/PHP/StrictComparisonsUnitTest.php | 2 +- WordPress/Tests/PHP/StrictInArrayUnitTest.php | 2 +- WordPress/Tests/PHP/TypeCastsUnitTest.php | 4 ++-- WordPress/Tests/PHP/YodaConditionsUnitTest.php | 2 +- WordPress/Tests/Security/EscapeOutputUnitTest.php | 2 +- WordPress/Tests/Security/NonceVerificationUnitTest.php | 2 +- WordPress/Tests/Security/PluginMenuSlugUnitTest.php | 2 +- WordPress/Tests/Security/SafeRedirectUnitTest.php | 2 +- .../Tests/Security/ValidatedSanitizedInputUnitTest.php | 2 +- WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php | 2 +- WordPress/Tests/WP/AlternativeFunctionsUnitTest.php | 2 +- WordPress/Tests/WP/CapitalPDangitUnitTest.php | 2 +- WordPress/Tests/WP/CronIntervalUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedClassesUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php | 2 +- WordPress/Tests/WP/DeprecatedParametersUnitTest.php | 2 +- WordPress/Tests/WP/DiscouragedConstantsUnitTest.php | 2 +- WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php | 2 +- WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php | 2 +- WordPress/Tests/WP/EnqueuedResourcesUnitTest.php | 2 +- WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php | 2 +- WordPress/Tests/WP/I18nUnitTest.php | 4 ++-- WordPress/Tests/WP/PostsPerPageUnitTest.php | 2 +- WordPress/Tests/WP/TimezoneChangeUnitTest.php | 2 +- .../WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php | 2 +- WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php | 2 +- .../Tests/WhiteSpace/ControlStructureSpacingUnitTest.php | 4 ++-- WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php | 2 +- WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php | 2 +- WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php | 4 ++-- WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php | 2 +- WordPress/ruleset.xml | 2 +- 129 files changed, 205 insertions(+), 203 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a70d94d195..861f5a6c56 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -51,9 +51,9 @@ To this end, the `WordPress\Sniff::has_whitelist_comment()` method was introduce Example usage: ```php -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; class NonceVerificationSniff extends Sniff { @@ -154,7 +154,7 @@ Lets take a look at what's inside `POSIXFunctionsUnitTest.php`: ```php ... -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index 1f9001a023..fff3a71fc8 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Restricts array assignment of certain keys. diff --git a/WordPress/AbstractClassRestrictionsSniff.php b/WordPress/AbstractClassRestrictionsSniff.php index f41cd138e8..05b0dcc5b7 100644 --- a/WordPress/AbstractClassRestrictionsSniff.php +++ b/WordPress/AbstractClassRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restricts usage of some classes. diff --git a/WordPress/AbstractFunctionParameterSniff.php b/WordPress/AbstractFunctionParameterSniff.php index df9350eb2b..5c059a6df2 100644 --- a/WordPress/AbstractFunctionParameterSniff.php +++ b/WordPress/AbstractFunctionParameterSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Advises about parameters used in function calls. diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 1b2dff3cab..416cffe049 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/PHPCSAliases.php b/WordPress/PHPCSAliases.php index f82bac41a1..ec2fead98e 100644 --- a/WordPress/PHPCSAliases.php +++ b/WordPress/PHPCSAliases.php @@ -64,10 +64,12 @@ class_alias( 'PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SemicolonSpacing spl_autoload_register( function ( $class ) { // Only try & load our own classes. - if ( stripos( $class, 'WordPress' ) !== 0 ) { + if ( stripos( $class, 'WordPressCS' ) !== 0 ) { return; } + $class = str_replace( 'WordPressCS\\', '', $class ); + // PHPCS handles the Test and Sniff classes without problem. if ( stripos( $class, '\Tests\\' ) !== false || stripos( $class, '\Sniffs\\' ) !== false ) { return; diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 7f20081559..9602e3c61d 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; use PHP_CodeSniffer_File as File; diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 92660c6a5b..96fa9978e4 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -7,12 +7,12 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress; +namespace WordPressCS\WordPress; use PHP_CodeSniffer_Sniff as PHPCS_Sniff; use PHP_CodeSniffer_File as File; use PHP_CodeSniffer_Tokens as Tokens; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards. diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 9d482c233c..59cd9a8613 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index 96eb4f0dfb..35aa361606 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\Sniff; +use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php index 9cd040fc14..0ef102e891 100644 --- a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Check for proper spacing in array key references. diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index 80ffde2727..648fc687cb 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php b/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php index d06994b883..ccecf224a7 100644 --- a/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php +++ b/WordPress/Sniffs/Arrays/MultipleStatementAlignmentSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Arrays; +namespace WordPressCS\WordPress\Sniffs\Arrays; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Enforces alignment of the double arrow assignment operator for multi-item, multi-line arrays. diff --git a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php index e68f0733b2..ca6c078de8 100644 --- a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php +++ b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Classes; +namespace WordPressCS\WordPress\Sniffs\Classes; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php index 901df2503e..cf61fa6d86 100644 --- a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\CodeAnalysis; +namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php index 2eff890987..927e89d714 100644 --- a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\CodeAnalysis; +namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index b1339e778f..fcc9467628 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php index b4dafe6a17..baf5f254e5 100644 --- a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 38f1e012fa..6084f1aabd 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/DB/RestrictedClassesSniff.php b/WordPress/Sniffs/DB/RestrictedClassesSniff.php index 3b6828cd7d..564a629ace 100644 --- a/WordPress/Sniffs/DB/RestrictedClassesSniff.php +++ b/WordPress/Sniffs/DB/RestrictedClassesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\AbstractClassRestrictionsSniff; +use WordPressCS\WordPress\AbstractClassRestrictionsSniff; /** * Verifies that no database related PHP classes are used. diff --git a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php index b80883b76f..1981f3a8e0 100644 --- a/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/DB/RestrictedFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Verifies that no database related PHP functions are used. diff --git a/WordPress/Sniffs/DB/SlowDBQuerySniff.php b/WordPress/Sniffs/DB/SlowDBQuerySniff.php index e7592df1af..6935aae40c 100644 --- a/WordPress/Sniffs/DB/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/DB/SlowDBQuerySniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\DB; +namespace WordPressCS\WordPress\Sniffs\DB; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag potentially slow queries. diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 057dc2bb6b..797d277d31 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Files; +namespace WordPressCS\WordPress\Sniffs\Files; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Ensures filenames do not contain underscores. diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php index 820abc09b5..39759683d4 100644 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Functions; +namespace WordPressCS\WordPress\Sniffs\Functions; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 43d5a2b9a7..f915c671ec 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use WordPress\AbstractFunctionParameterSniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index dc72792185..7b3c456aec 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; use PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; use PHP_CodeSniffer_File as File; diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index 7d7dcccff7..e72dd0992f 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Use lowercase letters in action and filter names. Separate words via underscores. diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 2325514ad2..67881d8cb3 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -7,12 +7,12 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\NamingConventions; +namespace WordPressCS\WordPress\Sniffs\NamingConventions; use PHP_CodeSniffer_Standards_AbstractVariableSniff as PHPCS_AbstractVariableSniff; use PHP_CodeSniffer_File as File; use PHP_CodeSniffer_Tokens as Tokens; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Checks the naming of variables and member variables. diff --git a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php index 0b910ce30e..79fe642bca 100644 --- a/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restrict the use of various development functions. diff --git a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php b/WordPress/Sniffs/PHP/DiscourageGotoSniff.php index f41433961e..5e2ce7ede5 100644 --- a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php +++ b/WordPress/Sniffs/PHP/DiscourageGotoSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Discourage the use of the PHP `goto` language construct. diff --git a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php index 8f275f4c6f..f7d613df83 100644 --- a/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Discourages the use of various native PHP functions and suggests alternatives. diff --git a/WordPress/Sniffs/PHP/DontExtractSniff.php b/WordPress/Sniffs/PHP/DontExtractSniff.php index be4f823bdc..6db447ad0d 100644 --- a/WordPress/Sniffs/PHP/DontExtractSniff.php +++ b/WordPress/Sniffs/PHP/DontExtractSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restricts the usage of extract(). diff --git a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php index fca1f28fd5..d80653ccaf 100644 --- a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php +++ b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php index b1631c7153..a7e1b0be7b 100644 --- a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Perl compatible regular expressions (PCRE, preg_ functions) should be used in preference diff --git a/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php b/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php index 87a668e086..f5e1a5a8ce 100644 --- a/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php +++ b/WordPress/Sniffs/PHP/PregQuoteDelimiterSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Flag calling preg_quote() without the second ($delimiter) parameter. diff --git a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php index 235db95e51..6bde3337d4 100644 --- a/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Forbids the use of various native PHP functions and suggests alternatives. diff --git a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php index ec43f504cd..97f3c4e406 100644 --- a/WordPress/Sniffs/PHP/StrictComparisonsSniff.php +++ b/WordPress/Sniffs/PHP/StrictComparisonsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Enforces Strict Comparison checks, based upon Squiz code. diff --git a/WordPress/Sniffs/PHP/StrictInArraySniff.php b/WordPress/Sniffs/PHP/StrictInArraySniff.php index c5ac94c9ed..f74f3f491d 100644 --- a/WordPress/Sniffs/PHP/StrictInArraySniff.php +++ b/WordPress/Sniffs/PHP/StrictInArraySniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Flag calling in_array(), array_search() and array_keys() without true as the third parameter. diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index c35afac4df..6c411bb9b9 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index cd1f2997db..554c3446fa 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\PHP; +namespace WordPressCS\WordPress\Sniffs\PHP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index abb66540d0..9f29183341 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/Security/NonceVerificationSniff.php b/WordPress/Sniffs/Security/NonceVerificationSniff.php index 4909a01f99..d42e544290 100644 --- a/WordPress/Sniffs/Security/NonceVerificationSniff.php +++ b/WordPress/Sniffs/Security/NonceVerificationSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Checks that nonce verification accompanies form processing. diff --git a/WordPress/Sniffs/Security/PluginMenuSlugSniff.php b/WordPress/Sniffs/Security/PluginMenuSlugSniff.php index 31b6447edb..65627ae624 100644 --- a/WordPress/Sniffs/Security/PluginMenuSlugSniff.php +++ b/WordPress/Sniffs/Security/PluginMenuSlugSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Warn about __FILE__ for page registration. diff --git a/WordPress/Sniffs/Security/SafeRedirectSniff.php b/WordPress/Sniffs/Security/SafeRedirectSniff.php index d4cebdf567..4d14631356 100644 --- a/WordPress/Sniffs/Security/SafeRedirectSniff.php +++ b/WordPress/Sniffs/Security/SafeRedirectSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Encourages use of wp_safe_redirect() to avoid open redirect vulnerabilities. diff --git a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php index 25756ce294..b79e56f4b7 100644 --- a/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Security; +namespace WordPressCS\WordPress\Sniffs\Security; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; /** * Flag any non-validated/sanitized input ( _GET / _POST / etc. ). diff --git a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php index e243c3d82a..9f5663af18 100644 --- a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php +++ b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\Utils; +namespace WordPressCS\WordPress\Sniffs\Utils; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index e5d700c506..b5daef4f98 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Discourages the use of various functions and suggests (WordPress) alternatives. diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index fbe621bded..d29d721bcf 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index 7cf2dd868d..0d9121dccb 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php index 9d46fddc70..a011d0fc3f 100644 --- a/WordPress/Sniffs/WP/DeprecatedClassesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedClassesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractClassRestrictionsSniff; +use WordPressCS\WordPress\AbstractClassRestrictionsSniff; /** * Restricts the use of deprecated WordPress classes and suggests alternatives. diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index df4ccdaeb4..15adbc5307 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Restricts the use of various deprecated WordPress functions and suggests alternatives. diff --git a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php index f49d7de011..32ca928cc7 100644 --- a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php index 4772cb08e1..08980292d6 100644 --- a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * Check for usage of deprecated parameters in WP functions and suggest alternative based on the parameter passed. diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index 125b68a48a..7b6268a8b4 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php index 92b3797b92..ba640858f6 100644 --- a/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Discourages the use of various WordPress functions and suggests alternatives. diff --git a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php index a2bbe39b7c..93007651f9 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index d3fa7861aa..900a10ba7a 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 1d628bbab3..9aae552517 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 427846d52e..0628a10b2f 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WP/PostsPerPageSniff.php b/WordPress/Sniffs/WP/PostsPerPageSniff.php index 22f7ef04f7..8e45afe78d 100644 --- a/WordPress/Sniffs/WP/PostsPerPageSniff.php +++ b/WordPress/Sniffs/WP/PostsPerPageSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag returning high or infinite posts_per_page. diff --git a/WordPress/Sniffs/WP/TimezoneChangeSniff.php b/WordPress/Sniffs/WP/TimezoneChangeSniff.php index 1755c7497f..5970e19b1c 100644 --- a/WordPress/Sniffs/WP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/WP/TimezoneChangeSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WP; +namespace WordPressCS\WordPress\Sniffs\WP; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Disallow the changing of timezone. diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php index 41df4a33c8..2a139f5f5a 100644 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index a239cb4d13..a71b7a7663 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 4f8317c774..0d46e52853 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -7,9 +7,9 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; +use WordPressCS\WordPress\Sniff; use PHP_CodeSniffer_Tokens as Tokens; /** diff --git a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php index 7d2411721b..6539def540 100644 --- a/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php +++ b/WordPress/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\Sniff; +use WordPressCS\WordPress\PHPCSHelper; /** * Enforces using spaces for mid-line alignment. diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 71e1e332b8..3b6499e012 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; use PHP_CodeSniffer_Tokens as Tokens; diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index b287d4a12b..646690cade 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use WordPress\Sniff; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\Sniff; +use WordPressCS\WordPress\PHPCSHelper; /** * Warn on line indentation ending with spaces for precision alignment. diff --git a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php index 6dfe818784..5a9b6511a0 100644 --- a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Sniffs\WhiteSpace; +namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff as PHPCS_Squiz_SemicolonSpacingSniff; use PHP_CodeSniffer_File as File; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php index ff6d212ae0..3114e175bf 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php index 2d8987ea6d..91cbb4ce78 100644 --- a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php index b2f53dfcd1..a688f67ef1 100644 --- a/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayKeySpacingRestrictionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php b/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php index dab0c93dda..7763f55ee5 100644 --- a/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php +++ b/WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php index 9342e9b413..58a0c04db7 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Arrays; +namespace WordPressCS\WordPress\Tests\Arrays; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Classes/ClassInstantiationUnitTest.php b/WordPress/Tests/Classes/ClassInstantiationUnitTest.php index dfb13722e1..d06cb98de0 100644 --- a/WordPress/Tests/Classes/ClassInstantiationUnitTest.php +++ b/WordPress/Tests/Classes/ClassInstantiationUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Classes; +namespace WordPressCS\WordPress\Tests\Classes; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php b/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php index 70cc630411..f92dcbeb02 100644 --- a/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/AssignmentInConditionUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\CodeAnalysis; +namespace WordPressCS\WordPress\Tests\CodeAnalysis; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php index 69b1e091c4..31e7bb55d4 100644 --- a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\CodeAnalysis; +namespace WordPressCS\WordPress\Tests\CodeAnalysis; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php index e51571a0bb..bb527e39f1 100644 --- a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php +++ b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php index f60e901a9b..87a35ea00a 100644 --- a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/PreparedSQLUnitTest.php b/WordPress/Tests/DB/PreparedSQLUnitTest.php index d29beeb41b..d0ef7ec47d 100644 --- a/WordPress/Tests/DB/PreparedSQLUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.php b/WordPress/Tests/DB/RestrictedClassesUnitTest.php index 3db48852bb..c15d35543a 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.php +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; /** * Unit test class for the DB_RestrictedClasses sniff. diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php index fda5c14b8a..362500ecfc 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/DB/SlowDBQueryUnitTest.php b/WordPress/Tests/DB/SlowDBQueryUnitTest.php index d16dc09764..2c0d64d2ef 100644 --- a/WordPress/Tests/DB/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/DB/SlowDBQueryUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\DB; +namespace WordPressCS\WordPress\Tests\DB; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index aeb4e6a902..363c0fa353 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Files; +namespace WordPressCS\WordPress\Tests\Files; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php b/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php index 4cd24ee675..ac3a917a03 100644 --- a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php +++ b/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Functions; +namespace WordPressCS\WordPress\Tests\Functions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index a1cec251b2..80a4872014 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php index b07e588a85..dc239337bc 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php index eaa60ad06e..b128f1da7b 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index 6f618af88a..792d62c3e6 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\NamingConventions; +namespace WordPressCS\WordPress\Tests\NamingConventions; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php index 32cb4129b2..aef75ef7e1 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DiscourageGotoUnitTest.php b/WordPress/Tests/PHP/DiscourageGotoUnitTest.php index 707e4ff71b..0caccfb4e9 100644 --- a/WordPress/Tests/PHP/DiscourageGotoUnitTest.php +++ b/WordPress/Tests/PHP/DiscourageGotoUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php index 13d0318de8..db73fe44bd 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/DontExtractUnitTest.php b/WordPress/Tests/PHP/DontExtractUnitTest.php index e98d40a58b..c8862b6b7f 100644 --- a/WordPress/Tests/PHP/DontExtractUnitTest.php +++ b/WordPress/Tests/PHP/DontExtractUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php index aab38db9bd..b9db72b0f5 100644 --- a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php +++ b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php index f9d6f0826f..13dbdecc3c 100644 --- a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php index 1ae222bc49..0615bbca22 100644 --- a/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php +++ b/WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php index f98c9b674d..e39e473eb5 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php index 4868462cc5..2f4c95d19c 100644 --- a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php +++ b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/StrictInArrayUnitTest.php b/WordPress/Tests/PHP/StrictInArrayUnitTest.php index 44a77f8ba7..66c9ed19b7 100644 --- a/WordPress/Tests/PHP/StrictInArrayUnitTest.php +++ b/WordPress/Tests/PHP/StrictInArrayUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.php b/WordPress/Tests/PHP/TypeCastsUnitTest.php index fbce6135c9..cdd88bbb68 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.php +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the TypeCasts sniff. diff --git a/WordPress/Tests/PHP/YodaConditionsUnitTest.php b/WordPress/Tests/PHP/YodaConditionsUnitTest.php index 8630b11e28..9640da2b7d 100644 --- a/WordPress/Tests/PHP/YodaConditionsUnitTest.php +++ b/WordPress/Tests/PHP/YodaConditionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\PHP; +namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index be2ef97053..91a97215dc 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index 0e1281f213..a7935c9557 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php index e3c56bb1c5..9141fa90a1 100644 --- a/WordPress/Tests/Security/PluginMenuSlugUnitTest.php +++ b/WordPress/Tests/Security/PluginMenuSlugUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/SafeRedirectUnitTest.php b/WordPress/Tests/Security/SafeRedirectUnitTest.php index 18919d8f9f..14e4686f11 100644 --- a/WordPress/Tests/Security/SafeRedirectUnitTest.php +++ b/WordPress/Tests/Security/SafeRedirectUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 5499dcf3e2..9eed79b4e8 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Security; +namespace WordPressCS\WordPress\Tests\Security; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php index 58d450a282..90e3df8ddd 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\Utils; +namespace WordPressCS\WordPress\Tests\Utils; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php index 2373403f0d..36ea1bcb51 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.php b/WordPress/Tests/WP/CapitalPDangitUnitTest.php index 4024166a70..494b03a72b 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.php +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/CronIntervalUnitTest.php b/WordPress/Tests/WP/CronIntervalUnitTest.php index 2f3b5fcf6c..be5cc9f6b8 100644 --- a/WordPress/Tests/WP/CronIntervalUnitTest.php +++ b/WordPress/Tests/WP/CronIntervalUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php index 76768770f6..c70673deb2 100644 --- a/WordPress/Tests/WP/DeprecatedClassesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php index f9bbc40a27..5fbce22ce0 100644 --- a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php index 0eac82ec29..f128e6fb34 100644 --- a/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php index d79572315d..ffbc573474 100644 --- a/WordPress/Tests/WP/DeprecatedParametersUnitTest.php +++ b/WordPress/Tests/WP/DeprecatedParametersUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php index 05a607fc49..8437893bb0 100644 --- a/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php +++ b/WordPress/Tests/WP/DiscouragedConstantsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php index 0aa80697fc..4491430637 100644 --- a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php +++ b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php b/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php index bcfbb15f92..8e60e6b57d 100644 --- a/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php +++ b/WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php index 77078c498a..2b0da6f255 100644 --- a/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php +++ b/WordPress/Tests/WP/EnqueuedResourcesUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php index 28340d8b9a..9739e83258 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/I18nUnitTest.php b/WordPress/Tests/WP/I18nUnitTest.php index 6dc1c4a098..6f617b03cc 100644 --- a/WordPress/Tests/WP/I18nUnitTest.php +++ b/WordPress/Tests/WP/I18nUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the I18n sniff. diff --git a/WordPress/Tests/WP/PostsPerPageUnitTest.php b/WordPress/Tests/WP/PostsPerPageUnitTest.php index 233609bd8a..22dd5c0715 100644 --- a/WordPress/Tests/WP/PostsPerPageUnitTest.php +++ b/WordPress/Tests/WP/PostsPerPageUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WP/TimezoneChangeUnitTest.php b/WordPress/Tests/WP/TimezoneChangeUnitTest.php index 6f16015319..2b623f644a 100644 --- a/WordPress/Tests/WP/TimezoneChangeUnitTest.php +++ b/WordPress/Tests/WP/TimezoneChangeUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WP; +namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php index 66c2ddfcc3..e2c3ef9218 100644 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php index 9cf81858e0..b90f1c1148 100644 --- a/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/CastStructureSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php index f8d50e74f1..93e58a47c1 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the ControlStructureSpacing sniff. diff --git a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php index fe446801d6..13ee511a2d 100644 --- a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php +++ b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php index 801cb15f09..ff7325c071 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index 714ed194cf..e62352c2fa 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -7,10 +7,10 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPress\PHPCSHelper; +use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the PrecisionAlignment sniff. diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php index 0dcd1950ef..1078620c1c 100644 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php @@ -7,7 +7,7 @@ * @license https://opensource.org/licenses/MIT MIT */ -namespace WordPress\Tests\WhiteSpace; +namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index bdcbff4736..f1a13d3860 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -1,5 +1,5 @@ - + WordPress Coding Standards ./PHPCSAliases.php From 9b70e001d9b34a9baa8ee6dc44bec1b392ae29c6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 16:20:45 +0100 Subject: [PATCH 09/64] WPCS 2.0.0: Adjust use statements to use PHPCS 3.x class names ... and remove the aliases. --- .../AbstractFunctionRestrictionsSniff.php | 2 +- WordPress/PHPCSAliases.php | 39 ------------------- WordPress/PHPCSHelper.php | 2 +- WordPress/Sniff.php | 6 +-- .../Arrays/ArrayDeclarationSpacingSniff.php | 2 +- .../Sniffs/Arrays/ArrayIndentationSniff.php | 2 +- .../Arrays/CommaAfterArrayItemSniff.php | 2 +- .../Classes/ClassInstantiationSniff.php | 2 +- .../AssignmentInConditionSniff.php | 2 +- .../CodeAnalysis/EmptyStatementSniff.php | 2 +- .../Sniffs/DB/DirectDatabaseQuerySniff.php | 2 +- .../DB/PreparedSQLPlaceholdersSniff.php | 2 +- WordPress/Sniffs/DB/PreparedSQLSniff.php | 2 +- .../FunctionCallSignatureNoParamsSniff.php | 2 +- .../PrefixAllGlobalsSniff.php | 2 +- .../ValidFunctionNameSniff.php | 4 +- .../ValidVariableNameSniff.php | 6 +-- .../Sniffs/PHP/NoSilencedErrorsSniff.php | 2 +- WordPress/Sniffs/PHP/TypeCastsSniff.php | 2 +- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 2 +- .../Sniffs/Security/EscapeOutputSniff.php | 2 +- .../Sniffs/Utils/I18nTextDomainFixerSniff.php | 2 +- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 2 +- WordPress/Sniffs/WP/CronIntervalSniff.php | 2 +- .../WP/DeprecatedParameterValuesSniff.php | 2 +- .../Sniffs/WP/DiscouragedConstantsSniff.php | 2 +- .../WP/EnqueuedResourceParametersSniff.php | 2 +- .../Sniffs/WP/EnqueuedResourcesSniff.php | 2 +- .../WP/GlobalVariablesOverrideSniff.php | 2 +- WordPress/Sniffs/WP/I18nSniff.php | 2 +- .../ArbitraryParenthesesSpacingSniff.php | 2 +- .../WhiteSpace/CastStructureSpacingSniff.php | 2 +- .../ControlStructureSpacingSniff.php | 2 +- .../WhiteSpace/OperatorSpacingSniff.php | 4 +- .../WhiteSpace/SemicolonSpacingSniff.php | 6 +-- 35 files changed, 42 insertions(+), 81 deletions(-) diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 416cffe049..1fbc24a4bd 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Restricts usage of some functions. diff --git a/WordPress/PHPCSAliases.php b/WordPress/PHPCSAliases.php index ec2fead98e..a2e1daabe0 100644 --- a/WordPress/PHPCSAliases.php +++ b/WordPress/PHPCSAliases.php @@ -8,46 +8,7 @@ * @since 0.13.0 */ -/* - * Alias a number of PHPCS 3.x classes to their PHPCS 2.x equivalents. - * - * This file is auto-loaded by PHPCS 3.x before any sniffs are loaded - * through the PHPCS 3.x `` ruleset directive. - * - * {@internal The PHPCS files have been reorganized in PHPCS 3.x, quite - * a few "old" classes have been split and spread out over several "new" - * classes. In other words, this will only work for a limited number - * of classes.}} - * - * {@internal The `class_exists` wrappers are needed to play nice with other - * external PHPCS standards creating cross-version compatibility in the same - * manner.}} - */ if ( ! \defined( 'WPCS_PHPCS_ALIASES_SET' ) ) { - // PHPCS base classes/interface. - if ( ! interface_exists( '\PHP_CodeSniffer_Sniff' ) ) { - class_alias( 'PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff' ); - } - if ( ! class_exists( '\PHP_CodeSniffer_File' ) ) { - class_alias( 'PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File' ); - } - if ( ! class_exists( '\PHP_CodeSniffer_Tokens' ) ) { - class_alias( 'PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens' ); - } - - // PHPCS classes which are being extended by WPCS sniffs. - if ( ! class_exists( '\PHP_CodeSniffer_Standards_AbstractVariableSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Sniffs\AbstractVariableSniff', '\PHP_CodeSniffer_Standards_AbstractVariableSniff' ); - } - if ( ! class_exists( '\PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff', '\PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff' ); - } - if ( ! class_exists( '\Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\OperatorSpacingSniff', '\Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff' ); - } - if ( ! class_exists( '\Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff' ) ) { - class_alias( 'PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SemicolonSpacingSniff', '\Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff' ); - } define( 'WPCS_PHPCS_ALIASES_SET', true ); diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 9602e3c61d..6e24f4a704 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -9,7 +9,7 @@ namespace WordPressCS\WordPress; -use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer\Files\File; /** * PHPCSHelper diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 96fa9978e4..4f63d8a002 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -9,9 +9,9 @@ namespace WordPressCS\WordPress; -use PHP_CodeSniffer_Sniff as PHPCS_Sniff; -use PHP_CodeSniffer_File as File; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Sniffs\Sniff as PHPCS_Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; use WordPressCS\WordPress\PHPCSHelper; /** diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 59cd9a8613..d417fe0ea8 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Arrays; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces WordPress array spacing format. diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index 35aa361606..2285a7cc79 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -11,7 +11,7 @@ use WordPressCS\WordPress\Sniff; use WordPressCS\WordPress\PHPCSHelper; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces WordPress array indentation for multi-line arrays. diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index 648fc687cb..a1b6626b6a 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Arrays; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces a comma after each array item and the spacing around it. diff --git a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php index ca6c078de8..37b942f6f0 100644 --- a/WordPress/Sniffs/Classes/ClassInstantiationSniff.php +++ b/WordPress/Sniffs/Classes/ClassInstantiationSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Classes; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verifies object instantiation statements. diff --git a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php index cf61fa6d86..fa3d9db7f5 100644 --- a/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/AssignmentInConditionSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Detects variable assignments being made within conditions. diff --git a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php index 927e89d714..2b92e1c7a1 100644 --- a/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php +++ b/WordPress/Sniffs/CodeAnalysis/EmptyStatementSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\CodeAnalysis; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Checks against empty statements. diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index fcc9467628..eecb3e757e 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\DB; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Flag Database direct queries. diff --git a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php index baf5f254e5..405eb094d0 100644 --- a/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\DB; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Check for incorrect use of the $wpdb->prepare method. diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 6084f1aabd..1f8fa9b3bc 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\DB; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Sniff for prepared SQL. diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php index 39759683d4..0aefd0a8ab 100644 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Functions; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces no whitespace between the parenthesis of a function call without parameters. diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index f915c671ec..437bc26923 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -11,7 +11,7 @@ use WordPressCS\WordPress\AbstractFunctionParameterSniff; use WordPressCS\WordPress\PHPCSHelper; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verify that everything defined in the global namespace is prefixed with a theme/plugin specific prefix. diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 7b3c456aec..3ee7c2ab31 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -9,8 +9,8 @@ namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; -use PHP_CodeSniffer_File as File; +use PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; +use PHP_CodeSniffer\Files\File; /** * Enforces WordPress function name and method name format, based upon Squiz code. diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 67881d8cb3..4e321c929e 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -9,9 +9,9 @@ namespace WordPressCS\WordPress\Sniffs\NamingConventions; -use PHP_CodeSniffer_Standards_AbstractVariableSniff as PHPCS_AbstractVariableSniff; -use PHP_CodeSniffer_File as File; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff as PHPCS_AbstractVariableSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; use WordPressCS\WordPress\Sniff; /** diff --git a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php index d80653ccaf..cc7b5fcb0c 100644 --- a/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php +++ b/WordPress/Sniffs/PHP/NoSilencedErrorsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Discourage the use of the PHP error silencing operator. diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 6c411bb9b9..343ddf1785 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verifies the correct usage of type cast keywords. diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index 554c3446fa..bd6738f69c 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces Yoda conditional statements. diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 9f29183341..05d9cbb5b5 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Security; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Verifies that all outputted strings are escaped. diff --git a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php index 9f5663af18..e61ef17b14 100644 --- a/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php +++ b/WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\Utils; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Comprehensive I18n text domain fixer tool. diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index d29d721bcf..c1b18f0ba9 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Capital P Dangit! diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index 0d9121dccb..56965e89fb 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Flag cron schedules less than 15 minutes. diff --git a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php index 32ca928cc7..7bbecee22f 100644 --- a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Check for usage of deprecated parameter values in WP functions and provide alternative based on the parameter passed. diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index 7b6268a8b4..e55254b749 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Warns against usage of discouraged WP CONSTANTS and recommends alternatives. diff --git a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php index 93007651f9..0a0d0a6245 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * This checks the enqueued 4th and 5th parameters to make sure the version and in_footer are set. diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index 900a10ba7a..05c642156f 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Makes sure scripts and styles are enqueued and not explicitly echo'd. diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 9aae552517..434fc1a8db 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Warns about overwriting WordPress native global variables. diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 0628a10b2f..c5dab418a9 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -11,7 +11,7 @@ use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; use WordPressCS\WordPress\PHPCSHelper; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Makes sure WP internationalization functions are used properly. diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php index 2a139f5f5a..fedb947ddc 100644 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Check & fix whitespace on the inside of arbitrary parentheses. diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index a71b7a7663..af87a7d634 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Ensure cast statements don't contain whitespace, but *are* surrounded by whitespace, based upon Squiz code. diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 0d46e52853..379424e171 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -10,7 +10,7 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Util\Tokens; /** * Enforces spacing around logical operators and assignments, based upon Squiz code. diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 3b6499e012..4dedca618a 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -9,8 +9,8 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use Squiz_Sniffs_WhiteSpace_OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\OperatorSpacingSniff as PHPCS_Squiz_OperatorSpacingSniff; +use PHP_CodeSniffer\Util\Tokens; /** * Verify operator spacing, uses the Squiz sniff, but additionally also sniffs for the `!` (boolean not) operator. diff --git a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php index 5a9b6511a0..d4a4ce787f 100644 --- a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php @@ -9,9 +9,9 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; -use Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff as PHPCS_Squiz_SemicolonSpacingSniff; -use PHP_CodeSniffer_File as File; -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SemicolonSpacingSniff as PHPCS_Squiz_SemicolonSpacingSniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Tokens; /** * Ensure there is no whitespace before a semicolon, while allowing for empty conditions in a `for`. From a71cd17f8c7e6553898ea1b64cea97a93df29afd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 18:15:47 +0100 Subject: [PATCH 10/64] WPCS 2.0.0: Remove unit test work-arounds for PHPCS 2.x The duplicates of the PHPCS 2.x test controller files can now be removed. We also no longer need to load our `PHPCSAliases` file, not even for the autoloading of the abstract classes as PHPCS 3.1.0+handles this without problem. For PHPUnit 7.x support, PHPCS does need a bootstrap file, but that is included with PHPCS, so all we need to do is reference that file in the command send to PHPUnit. --- .gitattributes | 1 - .github/CONTRIBUTING.md | 25 +- .phpcs.xml.dist | 4 - .travis.yml | 2 +- Test/AllTests.php | 72 ---- Test/Standards/AbstractSniffUnitTest.php | 460 ----------------------- Test/Standards/AllSniffs.php | 157 -------- Test/bootstrap.php | 42 --- Test/phpcs2-bootstrap.php | 53 --- Test/phpcs3-bootstrap.php | 61 --- bin/pre-commit | 2 +- phpunit.xml.dist | 1 - 12 files changed, 11 insertions(+), 869 deletions(-) delete mode 100644 Test/AllTests.php delete mode 100644 Test/Standards/AbstractSniffUnitTest.php delete mode 100644 Test/Standards/AllSniffs.php delete mode 100644 Test/bootstrap.php delete mode 100644 Test/phpcs2-bootstrap.php delete mode 100644 Test/phpcs3-bootstrap.php diff --git a/.gitattributes b/.gitattributes index 5e6e2b7903..c12f94cfb3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,7 +9,6 @@ /phpunit.xml.dist export-ignore /.github export-ignore /bin export-ignore -/Test export-ignore /WordPress/Tests export-ignore # diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 861f5a6c56..2693701a61 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -89,7 +89,7 @@ N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` If you already have PHPUnit installed on your system: Congrats, you're all set. If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies. -Alternatively, you can [install PHPUnit](https://phpunit.de/manual/5.7/en/installation.html) as a PHAR file. +Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file. ## Before running the unit tests @@ -111,37 +111,30 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your WP ## Running the unit tests -The WordPress Coding Standards are compatible with both PHPCS 2.x as well as 3.x. This has some implications for running the unit tests. - * Make sure you have registered the directory in which you installed WPCS with PHPCS using; ```sh phpcs --config-set installed_paths path/to/WPCS ``` * Navigate to the directory in which you installed WPCS. -* To run the unit tests with PHPCS 3.x: - ```sh - phpunit --bootstrap="./Test/phpcs3-bootstrap.php" --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php - ``` -* To run the unit tests with PHPCS 2.x: +* To run the unit tests: ```sh - phpunit --bootstrap="./Test/phpcs2-bootstrap.php" --filter WordPress ./Test/AllTests.php + phpunit --filter WordPress --bootstrap="/path/to/PHP_CodeSniffer/tests/bootstrap.php" /path/to/PHP_CodeSniffer/tests/AllTests.php ``` Expected output: ``` -PHPUnit 6.5.8 by Sebastian Bergmann and contributors. +PHPUnit 7.5.0 by Sebastian Bergmann and contributors. -Runtime: PHP 7.2.7 with Xdebug 2.6.0 +Runtime: PHP 7.2.13 Configuration: /WordPressCS/phpunit.xml -................................................................. 65 / 77 ( 84%) -............ 77 / 77 (100%) +............................................................ 60 / 60 (100%) -Tests generated 576 unique error codes; 51 were fixable (8.85%) +156 sniff test files generated 490 unique error codes; 59 were fixable (12.04%) -Time: 22.93 seconds, Memory: 40.00MB +Time: 18.02 seconds, Memory: 22.00MB -OK (77 tests, 0 assertions) +OK (60 tests, 0 assertions) ``` [![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 4bb6850731..84af17ae8a 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -7,11 +7,7 @@ - - /Test/AllTests.php - /Test/Standards/*.php /bin/class-ruleset-test.php - */vendor/* diff --git a/.travis.yml b/.travis.yml index 18cc71e459..e22e12dc6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,7 +65,7 @@ script: # Lint the PHP files against parse errors. - if [[ "$LINT" == "1" ]]; then if find . -path ./vendor -prune -o -path ./bin -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi; fi # Run the unit tests. - - phpunit --filter WordPress $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php + - phpunit --filter WordPress --bootstrap="$(pwd)/vendor/squizlabs/php_codesniffer/tests/bootstrap.php" $(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php # Test for fixer conflicts by running the auto-fixers of the complete WPCS over the test case files. # This is not an exhaustive test, but should give an early indication for typical fixer conflicts. # For the first run, the exit code will be 1 (= all fixable errors fixed). diff --git a/Test/AllTests.php b/Test/AllTests.php deleted file mode 100644 index de70f8ee19..0000000000 --- a/Test/AllTests.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use WordPressCS\Test\AllSniffs; -use PHP_CodeSniffer_AllTests; -use PHP_CodeSniffer_TestSuite; -/* End of WPCS adjustment */ - -/** - * A test class for running all PHP_CodeSniffer unit tests. - * - * Usage: phpunit AllTests.php - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class AllTests extends PHP_CodeSniffer_AllTests { - - /** - * Add all PHP_CodeSniffer test suites into a single test suite. - * - * @return PHPUnit_Framework_TestSuite - */ - public static function suite() - { - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = array(); - - // Use a special PHP_CodeSniffer test suite so that we can - // unset our autoload function after the run. - $suite = new PHP_CodeSniffer_TestSuite('PHP CodeSniffer'); - - /* Start of WPCS adjustment */ - // We need to point to the WPCS version of the referenced class - // and we may as well bypass the loading of the PHPCS core unit tests - // while we're at it too. - $suite->addTest(AllSniffs::suite()); - /* End of WPCS adjustment */ - - // Unregister this here because the PEAR tester loads - // all package suites before running then, so our autoloader - // will cause problems for the packages included after us. - spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload')); - - return $suite; - - }//end suite() - - -}//end class diff --git a/Test/Standards/AbstractSniffUnitTest.php b/Test/Standards/AbstractSniffUnitTest.php deleted file mode 100644 index b92b81386d..0000000000 --- a/Test/Standards/AbstractSniffUnitTest.php +++ /dev/null @@ -1,460 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use PHP_CodeSniffer; -use PHP_CodeSniffer_File; -use PHP_CodeSniffer_Exception; -use PHPUnit_Framework_TestCase; -use DirectoryIterator; -/* End of WPCS adjustment */ - -/** - * An abstract class that all sniff unit tests must extend. - * - * A sniff unit test checks a .inc file for expected violations of a single - * coding standard. Expected errors and warnings that are not found, or - * warnings and errors that are not expected, are considered test failures. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -abstract class AbstractSniffUnitTest extends PHPUnit_Framework_TestCase { - - /** - * Enable or disable the backup and restoration of the $GLOBALS array. - * Overwrite this attribute in a child class of TestCase. - * Setting this attribute in setUp() has no effect! - * - * @var boolean - */ - protected $backupGlobals = false; - - /** - * The PHP_CodeSniffer object used for testing. - * - * @var PHP_CodeSniffer - */ - protected static $phpcs = null; - - /** - * The path to the directory under which the sniff's standard lives. - * - * @var string - */ - public $standardsDir = null; - - - /** - * Sets up this unit test. - * - * @return void - */ - protected function setUp() - { - if (self::$phpcs === null) { - self::$phpcs = new PHP_CodeSniffer(); - } - - $class = \get_class($this); - $this->standardsDir = $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class]; - - }//end setUp() - - - /** - * Get a list of all test files to check. - * - * These will have the same base as the sniff name but different extensions. - * We ignore the .php file as it is the class. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles($testFileBase) - { - $testFiles = array(); - - $dir = substr($testFileBase, 0, strrpos($testFileBase, \DIRECTORY_SEPARATOR)); - $di = new DirectoryIterator($dir); - - foreach ($di as $file) { - $path = $file->getPathname(); - if (substr($path, 0, \strlen($testFileBase)) === $testFileBase) { - - /* Start of WPCS adjustment */ - // If we're changing things anyway, we may as well exclude backup files - // from the test runs ;-) - if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' - && substr($path, -3) !== 'bak' && substr($path, -4) !== 'orig' - ) { - $testFiles[] = $path; - } - /* End of WPCS adjustment */ - } - } - - // Put them in order. - sort($testFiles); - - return $testFiles; - - }//end getTestFiles() - - - /** - * Should this test be skipped for some reason. - * - * @return void - */ - protected function shouldSkipTest() - { - return false; - - }//end shouldSkipTest() - - - /** - * Tests the extending classes Sniff class. - * - * @return void - * @throws PHPUnit_Framework_Error - */ - public final function testSniff() - { - // Skip this test if we can't run in this environment. - if ($this->shouldSkipTest() === true) { - $this->markTestSkipped(); - } - - // The basis for determining file locations. - $basename = substr(\get_class($this), 0, -8); - - /* Start of WPCS adjustment */ - // Support the use of PHP namespaces. - if (strpos($basename, '\\') !== false) { - $basename = str_replace('\\', '_', $basename); - } - /* End of WPCS adjustment */ - - // The name of the coding standard we are testing. - $standardName = substr($basename, 0, strpos($basename, '_')); - - // The code of the sniff we are testing. - $parts = explode('_', $basename); - $sniffCode = $parts[0].'.'.$parts[2].'.'.$parts[3]; - - $testFileBase = $this->standardsDir.\DIRECTORY_SEPARATOR.str_replace('_', \DIRECTORY_SEPARATOR, $basename).'UnitTest.'; - - // Get a list of all test files to check. - $testFiles = $this->getTestFiles($testFileBase); - - self::$phpcs->initStandard($standardName, array($sniffCode)); - self::$phpcs->setIgnorePatterns(array()); - - $failureMessages = array(); - foreach ($testFiles as $testFile) { - $filename = basename($testFile); - - try { - $cliValues = $this->getCliValues($filename); - self::$phpcs->cli->setCommandLineValues($cliValues); - $phpcsFile = self::$phpcs->processFile($testFile); - } catch (\Exception $e) { - $this->fail('An unexpected exception has been caught: '.$e->getMessage()); - } - - $failures = $this->generateFailureMessages($phpcsFile); - $failureMessages = array_merge($failureMessages, $failures); - - if ($phpcsFile->getFixableCount() > 0) { - // Attempt to fix the errors. - $phpcsFile->fixer->fixFile(); - $fixable = $phpcsFile->getFixableCount(); - if ($fixable > 0) { - $failureMessages[] = "Failed to fix $fixable fixable violations in $filename"; - } - - // Check for a .fixed file to check for accuracy of fixes. - $fixedFile = $testFile.'.fixed'; - if (file_exists($fixedFile) === true) { - $diff = $phpcsFile->fixer->generateDiff($fixedFile); - if (trim($diff) !== '') { - $filename = basename($testFile); - $fixedFilename = basename($fixedFile); - $failureMessages[] = "Fixed version of $filename does not match expected version in $fixedFilename; the diff is\n$diff"; - } - } - } - }//end foreach - - if (empty($failureMessages) === false) { - $this->fail(implode(\PHP_EOL, $failureMessages)); - } - - }//end runTest() - - - /** - * Generate a list of test failures for a given sniffed file. - * - * @param PHP_CodeSniffer_File $file The file being tested. - * - * @return array - * @throws PHP_CodeSniffer_Exception - */ - public function generateFailureMessages(PHP_CodeSniffer_File $file) - { - $testFile = $file->getFilename(); - - $foundErrors = $file->getErrors(); - $foundWarnings = $file->getWarnings(); - $expectedErrors = $this->getErrorList(basename($testFile)); - $expectedWarnings = $this->getWarningList(basename($testFile)); - - if (\is_array($expectedErrors) === false) { - throw new PHP_CodeSniffer_Exception('getErrorList() must return an array'); - } - - if (\is_array($expectedWarnings) === false) { - throw new PHP_CodeSniffer_Exception('getWarningList() must return an array'); - } - - /* - We merge errors and warnings together to make it easier - to iterate over them and produce the errors string. In this way, - we can report on errors and warnings in the same line even though - it's not really structured to allow that. - */ - - $allProblems = array(); - $failureMessages = array(); - - foreach ($foundErrors as $line => $lineErrors) { - foreach ($lineErrors as $column => $errors) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $foundErrorsTemp = array(); - foreach ($allProblems[$line]['found_errors'] as $foundError) { - $foundErrorsTemp[] = $foundError; - } - - $errorsTemp = array(); - foreach ($errors as $foundError) { - $errorsTemp[] = $foundError['message'].' ('.$foundError['source'].')'; - - $source = $foundError['source']; - if (\in_array($source, $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']) === false) { - $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'][] = $source; - } - - if ($foundError['fixable'] === true - && \in_array($source, $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']) === false - ) { - $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'][] = $source; - } - } - - $allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp); - }//end foreach - - if (isset($expectedErrors[$line]) === true) { - $allProblems[$line]['expected_errors'] = $expectedErrors[$line]; - } else { - $allProblems[$line]['expected_errors'] = 0; - } - - unset($expectedErrors[$line]); - }//end foreach - - foreach ($expectedErrors as $line => $numErrors) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $allProblems[$line]['expected_errors'] = $numErrors; - } - - foreach ($foundWarnings as $line => $lineWarnings) { - foreach ($lineWarnings as $column => $warnings) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $foundWarningsTemp = array(); - foreach ($allProblems[$line]['found_warnings'] as $foundWarning) { - $foundWarningsTemp[] = $foundWarning; - } - - $warningsTemp = array(); - foreach ($warnings as $warning) { - $warningsTemp[] = $warning['message'].' ('.$warning['source'].')'; - } - - $allProblems[$line]['found_warnings'] = array_merge($foundWarningsTemp, $warningsTemp); - }//end foreach - - if (isset($expectedWarnings[$line]) === true) { - $allProblems[$line]['expected_warnings'] = $expectedWarnings[$line]; - } else { - $allProblems[$line]['expected_warnings'] = 0; - } - - unset($expectedWarnings[$line]); - }//end foreach - - foreach ($expectedWarnings as $line => $numWarnings) { - if (isset($allProblems[$line]) === false) { - $allProblems[$line] = array( - 'expected_errors' => 0, - 'expected_warnings' => 0, - 'found_errors' => array(), - 'found_warnings' => array(), - ); - } - - $allProblems[$line]['expected_warnings'] = $numWarnings; - } - - // Order the messages by line number. - ksort($allProblems); - - foreach ($allProblems as $line => $problems) { - $numErrors = \count($problems['found_errors']); - $numWarnings = \count($problems['found_warnings']); - $expectedErrors = $problems['expected_errors']; - $expectedWarnings = $problems['expected_warnings']; - - $errors = ''; - $foundString = ''; - - if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) { - $lineMessage = "[LINE $line]"; - $expectedMessage = 'Expected '; - $foundMessage = 'in '.basename($testFile).' but found '; - - if ($expectedErrors !== $numErrors) { - $expectedMessage .= "$expectedErrors error(s)"; - $foundMessage .= "$numErrors error(s)"; - if ($numErrors !== 0) { - $foundString .= 'error(s)'; - $errors .= implode(\PHP_EOL.' -> ', $problems['found_errors']); - } - - if ($expectedWarnings !== $numWarnings) { - $expectedMessage .= ' and '; - $foundMessage .= ' and '; - if ($numWarnings !== 0) { - if ($foundString !== '') { - $foundString .= ' and '; - } - } - } - } - - if ($expectedWarnings !== $numWarnings) { - $expectedMessage .= "$expectedWarnings warning(s)"; - $foundMessage .= "$numWarnings warning(s)"; - if ($numWarnings !== 0) { - $foundString .= 'warning(s)'; - if (empty($errors) === false) { - $errors .= \PHP_EOL.' -> '; - } - - $errors .= implode(\PHP_EOL.' -> ', $problems['found_warnings']); - } - } - - $fullMessage = "$lineMessage $expectedMessage $foundMessage."; - if ($errors !== '') { - $fullMessage .= " The $foundString found were:".\PHP_EOL." -> $errors"; - } - - $failureMessages[] = $fullMessage; - }//end if - }//end foreach - - return $failureMessages; - - }//end generateFailureMessages() - - - /** - * Get a list of CLI values to set before the file is tested. - * - * @param string $filename The name of the file being tested. - * - * @return array - */ - public function getCliValues($filename) - { - return array(); - - }//end getCliValues() - - - /** - * Returns the lines where errors should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of errors that should occur on that line. - * - * @return array(int => int) - */ - protected abstract function getErrorList(); - - - /** - * Returns the lines where warnings should occur. - * - * The key of the array should represent the line number and the value - * should represent the number of warnings that should occur on that line. - * - * @return array(int => int) - */ - protected abstract function getWarningList(); - - -}//end class diff --git a/Test/Standards/AllSniffs.php b/Test/Standards/AllSniffs.php deleted file mode 100644 index c3768adfca..0000000000 --- a/Test/Standards/AllSniffs.php +++ /dev/null @@ -1,157 +0,0 @@ - - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer - */ - -/* Start of WPCS adjustment */ -namespace WordPressCS\Test; - -use PHP_CodeSniffer_Standards_AllSniffs; -use PHP_CodeSniffer; -use PHPUnit_Framework_TestSuite; -use RecursiveIteratorIterator; -use RecursiveDirectoryIterator; -/* End of WPCS adjustment */ - -/** - * A test class for testing all sniffs for installed standards. - * - * Usage: phpunit AllSniffs.php - * - * This test class loads all unit tests for all installed standards into a - * single test suite and runs them. Errors are reported on the command line. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer - */ -class AllSniffs extends PHP_CodeSniffer_Standards_AllSniffs -{ - - /** - * Add all sniff unit tests into a test suite. - * - * Sniff unit tests are found by recursing through the 'Tests' directory - * of each installed coding standard. - * - * @return PHPUnit_Framework_TestSuite - */ - public static function suite() - { - $suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards'); - - /* Start of WPCS adjustment */ - // Set the correct path to PHPCS. - $isInstalled = !is_file(\PHPCS_DIR.'/CodeSniffer.php'); - /* End of WPCS adjustment */ - - // Optionally allow for ignoring the tests for one or more standards. - $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); - if ($ignoreTestsForStandards === false) { - $ignoreTestsForStandards = array(); - } else { - $ignoreTestsForStandards = explode(',', $ignoreTestsForStandards); - } - - $installedPaths = PHP_CodeSniffer::getInstalledStandardPaths(); - foreach ($installedPaths as $path) { - $path = realpath($path); - $origPath = $path; - $standards = PHP_CodeSniffer::getInstalledStandards(true, $path); - - // If the test is running PEAR installed, the built-in standards - // are split into different directories; one for the sniffs and - // a different file system location for tests. - if ($isInstalled === true - && is_dir($path.\DIRECTORY_SEPARATOR.'Generic') === true - ) { - $path = dirname(__FILE__); - } - - foreach ($standards as $standard) { - if (\in_array($standard, $ignoreTestsForStandards, true)) { - continue; - } - - $testsDir = $path.\DIRECTORY_SEPARATOR.$standard.\DIRECTORY_SEPARATOR.'Tests'.\DIRECTORY_SEPARATOR; - - if (is_dir($testsDir) === false) { - // No tests for this standard. - continue; - } - - $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testsDir)); - - foreach ($di as $file) { - // Skip hidden files. - if (substr($file->getFilename(), 0, 1) === '.') { - continue; - } - - // Tests must have the extension 'php'. - $parts = explode('.', $file); - $ext = array_pop($parts); - if ($ext !== 'php') { - continue; - } - - $filePath = $file->getPathname(); - $className = str_replace($path.\DIRECTORY_SEPARATOR, '', $filePath); - $className = substr($className, 0, -4); - $className = str_replace(\DIRECTORY_SEPARATOR, '_', $className); - - // Include the sniff here so tests can use it in their setup() methods. - $parts = explode('_', $className); - if (isset($parts[0],$parts[2],$parts[3]) === true) { - $sniffPath = $origPath.\DIRECTORY_SEPARATOR.$parts[0].\DIRECTORY_SEPARATOR.'Sniffs'.\DIRECTORY_SEPARATOR.$parts[2].\DIRECTORY_SEPARATOR.$parts[3]; - $sniffPath = substr($sniffPath, 0, -8).'Sniff.php'; - - if (file_exists($sniffPath) === true) { - include_once $sniffPath; - include_once $filePath; - - /* Start of WPCS adjustment */ - // Support the use of PHP namespaces. If the class name we included - // contains namespace separators instead of underscores, use this as the - // class name from now on. - $classNameNS = str_replace('_', '\\', $className); - if (class_exists($classNameNS, false) === true) { - $className = $classNameNS; - } - /* End of WPCS adjustment */ - - $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $path; - $suite->addTestSuite($className); - } else { - self::$orphanedTests[] = $filePath; - } - } else { - self::$orphanedTests[] = $filePath; - } - }//end foreach - }//end foreach - }//end foreach - - return $suite; - - }//end suite() - - -}//end class diff --git a/Test/bootstrap.php b/Test/bootstrap.php deleted file mode 100644 index 996c887ce3..0000000000 --- a/Test/bootstrap.php +++ /dev/null @@ -1,42 +0,0 @@ - From b79eb6428d65cb637f241317b42b0fb9f526a13f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 05:02:42 +0100 Subject: [PATCH 11/64] WPCS 2.0.0: Remove work-arounds for PHP < 5.4 and PHPCS < 3.3.1 --- .../Sniffs/Security/EscapeOutputSniff.php | 30 ------- .../ArbitraryParenthesesSpacingSniff.php | 5 -- .../Tests/Arrays/ArrayIndentationUnitTest.php | 20 ----- .../MultipleStatementAlignmentUnitTest.php | 20 ----- .../CodeAnalysis/EmptyStatementUnitTest.php | 2 +- WordPress/Tests/Files/FileNameUnitTest.php | 30 +------ .../Utils/I18nTextDomainFixerUnitTest.php | 20 ----- WordPress/Tests/WP/I18nUnitTest.php | 21 ----- .../ControlStructureSpacingUnitTest.php | 28 ------- .../WhiteSpace/DisallowInlineTabsUnitTest.php | 15 ---- .../WhiteSpace/PrecisionAlignmentUnitTest.php | 82 +++---------------- 11 files changed, 14 insertions(+), 259 deletions(-) diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 9de62c0e4c..2458ddcef0 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -177,18 +177,6 @@ public function register() { \T_OPEN_TAG_WITH_ECHO, ); - /* - * Check whether short open echo tags are disabled and if so, register the - * T_INLINE_HTML token which is how short open tags are being handled in that case. - * - * In PHP < 5.4, support for short open echo tags depended on whether the - * `short_open_tag` ini directive was set to `true`. - * For PHP >= 5.4, the `short_open_tag` no longer affects the short open - * echo tags and these are now always enabled. - */ - if ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) { - $tokens[] = \T_INLINE_HTML; - } return $tokens; } @@ -226,24 +214,6 @@ public function process_token( $stackPtr ) { $end_of_statement = ( $first_param['end'] + 1 ); unset( $first_param ); } - } elseif ( \T_INLINE_HTML === $this->tokens[ $stackPtr ]['code'] ) { - // Skip if no PHP short_open_tag is found in the string. - if ( false === strpos( $this->tokens[ $stackPtr ]['content'], '\S+|\[[^\]]+\]))*)[\s]*;?[\s]*\?\>`', $this->tokens[ $stackPtr ]['content'], $matches ) > 0 ) { - $this->phpcsFile->addError( - "All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '%s'.", - $stackPtr, - 'OutputNotEscapedShortEcho', - array( $matches[1] ) - ); - return; - } - - return; } // Checking for the ignore comment, ex: //xss ok. diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php index fedb947ddc..89c58ba60c 100644 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php @@ -77,11 +77,6 @@ public function register() { $this->ignoreTokens[ \T_LIST ] = \T_LIST; $this->ignoreTokens[ \T_DECLARE ] = \T_DECLARE; - // The below two tokens have been added to the Tokens::$functionNameTokens array in PHPCS 3.1.0, - // so they can be removed once the minimum PHPCS requirement of WPCS has gone up. - $this->ignoreTokens[ \T_SELF ] = \T_SELF; - $this->ignoreTokens[ \T_STATIC ] = \T_STATIC; - // Language constructs where the use of parentheses should be discouraged instead. $this->ignoreTokens[ \T_THROW ] = \T_THROW; $this->ignoreTokens[ \T_YIELD ] = \T_YIELD; diff --git a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php index 91cbb4ce78..3b6983ff21 100644 --- a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.php @@ -28,29 +28,9 @@ class ArrayIndentationUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Tab width setting is only needed for the tabbed file. - if ( 'ArrayIndentationUnitTest.1.inc' === $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php index 58a0c04db7..bc6cc60268 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.php @@ -31,29 +31,9 @@ class MultipleStatementAlignmentUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Tab width setting is only needed for the tabbed file. - if ( 'MultipleStatementAlignmentUnitTest.1.inc' === $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php index 31e7bb55d4..22ca38d56c 100644 --- a/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php +++ b/WordPress/Tests/CodeAnalysis/EmptyStatementUnitTest.php @@ -56,7 +56,7 @@ public function getWarningList( $testFile = '' ) { case 'EmptyStatementUnitTest.2.inc': return array( 1 => 1, // Internal.NoCode warning when short open tags is off, otherwise EmptyStatement warning. - 2 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, + 2 => 1, ); default: diff --git a/WordPress/Tests/Files/FileNameUnitTest.php b/WordPress/Tests/Files/FileNameUnitTest.php index 363c0fa353..af0a46c2f2 100644 --- a/WordPress/Tests/Files/FileNameUnitTest.php +++ b/WordPress/Tests/Files/FileNameUnitTest.php @@ -119,18 +119,6 @@ class FileNameUnitTest extends AbstractSniffUnitTest { */ protected function getTestFiles( $testFileBase ) { - // Work around for PHP 5.3/PHPCS 2.x. - if ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) { - unset( $this->expected_results['SomeView.inc'] ); - } - - // Work around for PHPCS < 3.2.0. The disables will be diregarded. - if ( ! \defined( '\T_PHPCS_DISABLE' ) && ! \defined( '\T_PHPCS_ENABLE' ) ) { - $this->expected_results['blanket-disable.inc'] = 1; - $this->expected_results['rule-disable.inc'] = 1; - $this->expected_results['wordpress-disable.inc'] = 1; - } - $sep = \DIRECTORY_SEPARATOR; $test_files = glob( dirname( $testFileBase ) . $sep . 'FileNameUnitTests{' . $sep . ',' . $sep . '*' . $sep . '}*.inc', \GLOB_BRACE ); @@ -161,24 +149,10 @@ public function getErrorList( $testFile = '' ) { /** * Returns the lines where warnings should occur. * - * @param string $testFile The name of the file being tested. - * * @return array => */ - public function getWarningList( $testFile = '' ) { - switch ( $testFile ) { - case 'SomeView.inc': - case 'some-view.inc': - $expected = array(); - if ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) { - $expected[1] = 1; // Internal.NoCode warning on PHP 5.3 icw short open tags off. - } - - return $expected; - - default: - return array(); - } + public function getWarningList() { + return array(); } } diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php index 90e3df8ddd..7f13fe3e88 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php @@ -27,29 +27,9 @@ class I18nTextDomainFixerUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Tab width setting is only needed for the file with the function calls. - if ( 'I18nTextDomainFixerUnitTest.4.inc' === $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/WP/I18nUnitTest.php b/WordPress/Tests/WP/I18nUnitTest.php index 6f617b03cc..bab594676f 100644 --- a/WordPress/Tests/WP/I18nUnitTest.php +++ b/WordPress/Tests/WP/I18nUnitTest.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Tests\WP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the I18n sniff. @@ -22,29 +21,9 @@ */ class I18nUnitTest extends AbstractSniffUnitTest { - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - // Test overruling the text domain from the command line for one test file. - if ( 'I18nUnitTest.3.inc' === $testFile ) { - PHPCSHelper::set_config_data( 'text_domain', 'something', true ); - } - - return array(); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php index 93e58a47c1..e295978e2b 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the ControlStructureSpacing sniff. @@ -22,33 +21,6 @@ */ class ControlStructureSpacingUnitTest extends AbstractSniffUnitTest { - /** - * Get a list of all test files to check. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles( $testFileBase ) { - - $testFiles = parent::getTestFiles( $testFileBase ); - - /* - * Testing whether the PHPCS annotations are properly handled is only useful on - * PHPCS versions which support the PHPCS annotations. - * Prior to PHPCS 3.2.0 they would be treated the same as ordinary comments - * for the purposes of this sniff. - */ - if ( version_compare( PHPCSHelper::get_version(), '3.2.0', '<' ) === true ) { - $key = array_search( $testFileBase . '2.inc', $testFiles, true ); - if ( false !== $key ) { - unset( $testFiles[ $key ] ); - } - } - - return $testFiles; - } - /** * Returns the lines where errors should occur. * diff --git a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php index 13ee511a2d..5f360ca429 100644 --- a/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php +++ b/WordPress/Tests/WhiteSpace/DisallowInlineTabsUnitTest.php @@ -28,24 +28,9 @@ class DisallowInlineTabsUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index e62352c2fa..7b600c1729 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Tests\WhiteSpace; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the PrecisionAlignment sniff. @@ -28,24 +27,9 @@ class PrecisionAlignmentUnitTest extends AbstractSniffUnitTest { */ private $tab_width = 4; - /** - * Get a list of CLI values to set before the file is tested. - * - * Used by PHPCS 2.x. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - public function getCliValues( $testFile ) { - return array( '--tab-width=' . $this->tab_width ); - } - /** * Set CLI values before the file is tested. * - * Used by PHPCS 3.x. - * * @param string $testFile The name of the file being tested. * @param \PHP_CodeSniffer\Config $config The config data for the test run. * @@ -54,37 +38,12 @@ public function getCliValues( $testFile ) { public function setCliValues( $testFile, $config ) { $config->tabWidth = $this->tab_width; - // Setting "--ignore-annotations" is only possible since PHPCS 3.0. + // Testing a file with "--ignore-annotations". if ( 'PrecisionAlignmentUnitTest.6.inc' === $testFile ) { $config->annotations = false; } } - /** - * Get a list of all test files to check. - * - * @param string $testFileBase The base path that the unit tests files will have. - * - * @return string[] - */ - protected function getTestFiles( $testFileBase ) { - - $testFiles = parent::getTestFiles( $testFileBase ); - - /* - * Testing whether the PHPCS annotations are properly respected is only useful on - * PHPCS versions which support the PHPCS annotations. - */ - if ( version_compare( PHPCSHelper::get_version(), '3.2.0', '<' ) === true ) { - $key = array_search( $testFileBase . '5.inc', $testFiles, true ); - if ( false !== $key ) { - unset( $testFiles[ $key ] ); - } - } - - return $testFiles; - } - /** * Returns the lines where errors should occur. * @@ -116,11 +75,11 @@ public function getWarningList( $testFile = '' ) { case 'PrecisionAlignmentUnitTest.4.inc': return array( - 1 => 1, // Will show a `Internal.NoCodeFound` warning in PHP 5.3 with short open tags off. - 2 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, - 3 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, - 4 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, - 5 => ( \PHP_VERSION_ID < 50400 && false === (bool) ini_get( 'short_open_tag' ) ) ? 0 : 1, + 1 => 1, + 2 => 1, + 3 => 1, + 4 => 1, + 5 => 1, ); case 'PrecisionAlignmentUnitTest.5.inc': @@ -128,38 +87,19 @@ public function getWarningList( $testFile = '' ) { 9 => 1, 14 => 1, 19 => 1, - 24 => 0, - 29 => 0, + 24 => 1, + 29 => 1, 34 => 1, 39 => 1, 44 => 1, - 54 => 0, - 56 => 0, - 58 => 0, + 54 => 1, + 56 => 1, + 58 => 1, ); - /* - * The PHPCS 3.2.x versions contained a bug in the selective disable/enable logic - * compared to the intended behaviour as documented, which prevented the particular - * messages being tested on these lines from being thrown. See upstream issue #1986. - */ - if ( version_compare( PHPCSHelper::get_version(), '3.3.0', '>=' ) === true ) { - $warnings[24] = 1; - $warnings[29] = 1; - $warnings[54] = 1; - $warnings[56] = 1; - $warnings[58] = 1; - } - return $warnings; case 'PrecisionAlignmentUnitTest.6.inc': - /* - * {@internal Always returns 1 warning, as for PHPCS < 3.2.0, the PHPCS annotation - * will be seen as a "normal" comment with precision alignment. - * For PHPCS 3.2.0+, it will be seen as a PHPCS annotation, but annotations are ignored - * for this test file, so the precision alignment will be reported.}} - */ return array( 4 => 1, ); From 0a080dd9951a9488c36d3bae2fdd6c6bd888d600 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 17:31:21 +0100 Subject: [PATCH 12/64] WPCS 2.0.0: Remove PHPCS 2.x code from PHPCSHelper class While strictly speaking the `PHPCSHelper` class is no longer needed at this moment, PHPCS 4.x may again contain breaking changes, so leaving it in place as a cross-version compatibility layer makes sense. All the same, the PHPCS 2.x specific code can now be removed. --- WordPress/PHPCSHelper.php | 55 ++++++++------------------------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 6e24f4a704..bdabb35bf1 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -33,13 +33,7 @@ class PHPCSHelper { * @return string */ public static function get_version() { - if ( \defined( '\PHP_CodeSniffer\Config::VERSION' ) ) { - // PHPCS 3.x. - return \PHP_CodeSniffer\Config::VERSION; - } else { - // PHPCS 2.x. - return \PHP_CodeSniffer::VERSION; - } + return \PHP_CodeSniffer\Config::VERSION; } /** @@ -56,13 +50,7 @@ public static function get_version() { * This will not write the config data to the config file. */ public static function set_config_data( $key, $value, $temp = false ) { - if ( method_exists( '\PHP_CodeSniffer\Config', 'setConfigData' ) ) { - // PHPCS 3.x. - \PHP_CodeSniffer\Config::setConfigData( $key, $value, $temp ); - } else { - // PHPCS 2.x. - \PHP_CodeSniffer::setConfigData( $key, $value, $temp ); - } + \PHP_CodeSniffer\Config::setConfigData( $key, $value, $temp ); } /** @@ -75,13 +63,7 @@ public static function set_config_data( $key, $value, $temp = false ) { * @return string|null */ public static function get_config_data( $key ) { - if ( method_exists( '\PHP_CodeSniffer\Config', 'getConfigData' ) ) { - // PHPCS 3.x. - return \PHP_CodeSniffer\Config::getConfigData( $key ); - } else { - // PHPCS 2.x. - return \PHP_CodeSniffer::getConfigData( $key ); - } + return \PHP_CodeSniffer\Config::getConfigData( $key ); } /** @@ -96,17 +78,8 @@ public static function get_config_data( $key ) { public static function get_tab_width( File $phpcsFile ) { $tab_width = 4; - if ( class_exists( '\PHP_CodeSniffer\Config' ) ) { - // PHPCS 3.x. - if ( isset( $phpcsFile->config->tabWidth ) && $phpcsFile->config->tabWidth > 0 ) { - $tab_width = $phpcsFile->config->tabWidth; - } - } else { - // PHPCS 2.x. - $cli_values = $phpcsFile->phpcs->cli->getCommandLineValues(); - if ( isset( $cli_values['tabWidth'] ) && $cli_values['tabWidth'] > 0 ) { - $tab_width = $cli_values['tabWidth']; - } + if ( isset( $phpcsFile->config->tabWidth ) && $phpcsFile->config->tabWidth > 0 ) { + $tab_width = $phpcsFile->config->tabWidth; } return $tab_width; @@ -122,20 +95,14 @@ public static function get_tab_width( File $phpcsFile ) { * @return bool True if annotations should be ignored, false otherwise. */ public static function ignore_annotations( File $phpcsFile = null ) { - if ( class_exists( '\PHP_CodeSniffer\Config' ) ) { - // PHPCS 3.x. - if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) { - return ! $phpcsFile->config->annotations; - } else { - $annotations = \PHP_CodeSniffer\Config::getConfigData( 'annotations' ); - if ( isset( $annotations ) ) { - return ! $annotations; - } + if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) { + return ! $phpcsFile->config->annotations; + } else { + $annotations = \PHP_CodeSniffer\Config::getConfigData( 'annotations' ); + if ( isset( $annotations ) ) { + return ! $annotations; } } - - // PHPCS 2.x does not support `--ignore-annotations`. - return false; } } From d22aca8fb0fb361c14477ae961ce29e7915fbc53 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 22 Aug 2018 02:54:45 +0200 Subject: [PATCH 13/64] ValidFunctionName: Add additional unit test for interfaces extending multiple interfaces Interfaces can extend multiple other interfaces. Looking at the sniff code, no changes are needed in the sniff to account for this, however, adding an additional unit test to warrant against sniff changes in the future which may not take this into account. N.B.: I've verified all other usages of the `T_INTERFACE` token in the whole of WPCS and this was the only one which looked at `extends/implements`, so the only one for which interfaces extending multiple other interfaces could be problematic. See: * http://php.net/manual/en/language.oop5.interfaces.php#example-208 Loosely related to: * https://github.com/squizlabs/PHP_CodeSniffer/pull/2128 --- .../Tests/NamingConventions/ValidFunctionNameUnitTest.inc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index a1b567c210..228d4348d0 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -104,3 +104,8 @@ class My_Soap extends somethingElse { } function __MyTemplateTags() {} // Bad x 2. + +// Verify that interfaces which extend multiple other interfaces do not throw unnecessary errors. +interface MyInterface extends InterfaceA, InterfaceB { + function __MyTemplateTags(); // OK. +} From b1a3ec7ca9d5363ed431cc791fa7d7d6ae4d1543 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 16:00:49 +0100 Subject: [PATCH 14/64] Rulesets: minor simplifications (PHPCS 3.0+) As of PHPCS 3.0.0, you can include individual error codes, not just complete sniffs. Where WPCS rulesets included sniffs, but excluded more than 50% of the error codes from that sniff, it makes sense to switch them over to include individual error codes instead. This also means that where previously, if the `type` and/or `message` of an individual error code was adjusted via the ruleset, the sniff needed to be included first and only after that, the details could be adjusted. Now, the inclusion can just be done based on error code, providing all error codes in the sniff are adjusted. To explain it better: * If a sniff contained five error codes and we adjusted the message for one, there is no real advantage to changing over. * If a sniff contained three error codes and we excluded one, and adjusted another, there is no real advantage to changing over. * However, if a sniff contained only one error code and we'd adjust that one anyway, the new way of including just the error code gets rid of some superfluous configuration. * Similarly, if a sniff contained five error codes, we'd exclude two and adjusted the details for the other three, changing over, again, is to our benefit. --- WordPress-Core/ruleset.xml | 6 +----- WordPress-Extra/ruleset.xml | 7 ------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index b9cd23a91f..98be047a62 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -18,10 +18,7 @@ --> - - - 0 - + @@ -408,7 +405,6 @@ - error eval() is a security risk so not allowed. diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 2e6a412f59..db44250893 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -42,13 +42,6 @@ - - - 0 - - - 0 - warning From efce48ae5a85d709a4967a1de3684916315c6c85 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 15:03:45 +0100 Subject: [PATCH 15/64] Rulesets: Start using the new XML array format (PHPCS 3.3+) A new format for passing array elements to PHPCS properties was added in PHPCS 3.3.0. This new array format is far more readable and less error prone than the old format. This commit implements using this new array format throughout WPCS, wherever relevant, including in property setting examples in the documentation. Ref: * squizlabs/PHP_CodeSniffer 1665 --- WordPress-Core/ruleset.xml | 6 +++++- WordPress/Sniff.php | 5 ++++- WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php | 6 ++++-- phpcs.xml.dist.sample | 9 +++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index b9cd23a91f..189532f2db 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -39,7 +39,11 @@ - + + + + + diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 4f63d8a002..68f1e3c8cb 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -96,7 +96,10 @@ abstract class Sniff implements PHPCS_Sniff { * Example usage: * * - * + * + * + * + * * * * diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index 646690cade..adef2d4d2d 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -50,8 +50,10 @@ class PrecisionAlignmentSniff extends Sniff { * * * - * + * + * + * + * * * * diff --git a/phpcs.xml.dist.sample b/phpcs.xml.dist.sample index d0fe264fe3..7c074a5173 100644 --- a/phpcs.xml.dist.sample +++ b/phpcs.xml.dist.sample @@ -73,13 +73,18 @@ - + + + + - + + + From 71aed7ae23216e529a38dee4bf7df9b2254473b4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 14:49:45 +0100 Subject: [PATCH 16/64] Rulesets: Add XSD schema tags and validate rulesets against schema (PHPCS 3.2+/3.3.2+) As of PHPCS 3.2.0, PHPCS includes an XSD schema for rulesets which defines what can be used in the XML ruleset file. In PHPCS 3.3.0 a new array format for properties was introduced and as of PHPCS 3.3.2, the new array format is now also covered by this schema. This commit: * Adds the schema tags to the `ruleset.xml` files, the WPCS native `.phpcs.xml.dist` file, as well as to the example ruleset. * Adds validation against the schema for the `ruleset.xml` files and the example ruleset to the Travis build. Note: The schema used in the tags points to the online schema in PHPCS `master` for two reasons: 1. While WPCS now has a minimum requirement of PHPCS 3.3.1, the schema in PHPCS `master` contains the changes which were made in PHPCS 3.3.2, so we can safely validate the rulesets against the schema. 2. While installation via Composer is supported for WPCS, it is **not** the _only_ supported installation method, so pointing to the version of the XSD schema in the `vendor` directory would be presumptuous. At the same time, using the URL in the Travis script appears to be problematic and as we're doing a composer install there anyway, we may as well use the version in the `vendor` directory for the actual validation. As the validation is done on a build with PHPCS `master`, there will be no difference anyway. Fixes 1477 --- .phpcs.xml.dist | 3 ++- .travis.yml | 4 ++-- WordPress-Core/ruleset.xml | 3 ++- WordPress-Docs/ruleset.xml | 3 ++- WordPress-Extra/ruleset.xml | 3 ++- WordPress/ruleset.xml | 3 ++- phpcs.xml.dist.sample | 3 ++- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 84af17ae8a..504fdf6c44 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -1,5 +1,6 @@ - + + The Coding standard for the WordPress Coding Standards itself. . diff --git a/.travis.yml b/.travis.yml index e22e12dc6c..b97e957b4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -85,8 +85,8 @@ script: - if [[ "$SNIFF" == "1" ]]; then $(pwd)/vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi # Validate the xml files. # @link http://xmlsoft.org/xmllint.html - - if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./*/ruleset.xml; fi - - if [[ "$SNIFF" == "1" ]]; then xmllint --noout ./phpcs.xml.dist.sample; fi + - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml; fi + - if [[ "$SNIFF" == "1" ]]; then xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./phpcs.xml.dist.sample; fi # Check the code-style consistency of the xml files. - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress/ruleset.xml <(xmllint --format "./WordPress/ruleset.xml"); fi - if [[ "$SNIFF" == "1" ]]; then diff -B --tabsize=4 ./WordPress-Core/ruleset.xml <(xmllint --format "./WordPress-Core/ruleset.xml"); fi diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index b9cd23a91f..659481ac6f 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -1,5 +1,6 @@ - + + Non-controversial generally-agreed upon WordPress Coding Standards ./../WordPress/PHPCSAliases.php diff --git a/WordPress-Docs/ruleset.xml b/WordPress-Docs/ruleset.xml index 02abd0e73d..fb74597d76 100644 --- a/WordPress-Docs/ruleset.xml +++ b/WordPress-Docs/ruleset.xml @@ -1,5 +1,6 @@ - + + WordPress Coding Standards for Inline Documentation and Comments From 06cec32de85a7630751073322d4a3c136bf979b9 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 18:24:59 +0100 Subject: [PATCH 17/64] PHPUnit: add Composer script to run the tests A `dev` requirement of `phpunit/phpunit` has been added to the `composer.json` file, as well as a script to run the unit tests. While PHPUnit is not strictly speaking a dependency of WPCS (but of PHPCS), this just makes life easier on WPCS developers who use the Composer install for development. If - as a WPCS sniff developer - you've installed WPCS using Composer, you can now run the unit tests, like so: ```bash composer run-tests ``` A note to this effect has been added to the `CONTRIBUTING.MD` file as well. Additionally: * While not strictly necessary, a `testsuite` directive has been added to the `phpunit.xml.dist` file to document where the tests are located and how they are named. * As `PHPCompatibility` will also be installed when using Composer to install WPCS and PHPCompatibility uses its own test setup, we need to prevent PHPCS from trying to load the test files for PHPCompatibility. The `PHPCS_IGNORE_TEST` environment variable in the `phpunit.xml.dist` file does just that. For more information about this, see squizlabs/PHP_CodeSniffer 1146 --- .github/CONTRIBUTING.md | 10 ++++------ composer.json | 6 ++++-- phpunit.xml.dist | 13 +++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2693701a61..d763055c2b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -97,16 +97,11 @@ N.B.: _If you used Composer to install the WordPress Coding Standards, you can s For the unit tests to work, you need to make sure PHPUnit can find your `PHP_CodeSniffer` install. -The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. Make sure to adjust the path to reflect your local setup. +The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. Copy the existing `phpunit.xml.dist` file and add the below `` directive within the `` section. Make sure to adjust the path to reflect your local setup. ```xml - - ``` ## Running the unit tests @@ -119,6 +114,9 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your WP * To run the unit tests: ```sh phpunit --filter WordPress --bootstrap="/path/to/PHP_CodeSniffer/tests/bootstrap.php" /path/to/PHP_CodeSniffer/tests/AllTests.php + + # Or if you've installed WPCS with Composer: + composer run-tests ``` Expected output: diff --git a/composer.json b/composer.json index f7511b0fb3..3b1adc8457 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "squizlabs/php_codesniffer": "^3.3.1" }, "require-dev": { - "phpcompatibility/php-compatibility": "^9.0" + "phpcompatibility/php-compatibility": "^9.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." @@ -30,7 +31,8 @@ "post-update-cmd": "@install-codestandards", "check-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs", "fix-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf", - "install-codestandards": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility" + "install-codestandards": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility", + "run-tests": "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress --bootstrap=\"./vendor/squizlabs/php_codesniffer/tests/bootstrap.php\" ./vendor/squizlabs/php_codesniffer/tests/AllTests.php" }, "support": { "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 71a1537d3c..ccacc14806 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,4 +5,17 @@ backupGlobals="true" beStrictAboutTestsThatDoNotTestAnything="false" colors="true"> + + + + ./WordPress/Tests/ + + + + + + + From 5dec0aa5e112acfbd163f053cbd18cb3000d8d2b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 17:59:29 +0100 Subject: [PATCH 18/64] PHPCS 3.1+: Start using the new Tokens::$ooScopeTokens array This new token array was introduced in PHPCS 3.1.0 via squizlabs/PHP_CodeSniffer 1415 and contains `T_CLASS`, `T_ANON_CLASS`, `T_INTERFACE` and `T_TRAIT`. --- WordPress/Sniff.php | 18 ++---------- .../PrefixAllGlobalsSniff.php | 23 ++++++--------- WordPress/Sniffs/WP/CapitalPDangitSniff.php | 17 ++--------- .../WP/GlobalVariablesOverrideSniff.php | 29 ++++++++----------- .../ControlStructureSpacingSniff.php | 7 ++--- 5 files changed, 27 insertions(+), 67 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 68f1e3c8cb..e8572b0bd3 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1171,26 +1171,14 @@ protected function is_token_in_test_method( $stackPtr ) { return false; } - /* - * Is this a method inside of a class or a trait ? If so, it is a test class/trait ? - * - * {@internal Once the minimum supported PHPCS version has gone up to 3.1.0, the - * local array here can be replace with Tokens::$ooScopeTokens.}} - */ - $oo_tokens = array( - \T_CLASS => true, - \T_TRAIT => true, - \T_ANON_CLASS => true, - ); $conditions = $this->tokens[ $stackPtr ]['conditions']; - foreach ( $conditions as $token => $condition ) { if ( $token === $functionToken ) { // Only examine the conditions the function is nested in, not those nested within the function. break; } - if ( isset( $oo_tokens[ $condition ] ) ) { + if ( isset( Tokens::$ooScopeTokens[ $condition ] ) ) { $is_test_class = $this->is_test_class( $token ); if ( true === $is_test_class ) { return true; @@ -1218,9 +1206,7 @@ protected function is_token_in_test_method( $stackPtr ) { */ protected function is_test_class( $stackPtr ) { - if ( ! isset( $this->tokens[ $stackPtr ] ) - || \in_array( $this->tokens[ $stackPtr ]['type'], array( 'T_CLASS', 'T_ANON_CLASS', 'T_TRAIT' ), true ) === false - ) { + if ( isset( $this->tokens[ $stackPtr ], Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) === false ) { return false; } diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 6ee6b1418b..8994e57130 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -181,17 +181,14 @@ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { * @return array */ public function register() { - $targets = array( - \T_NAMESPACE => \T_NAMESPACE, - \T_FUNCTION => \T_FUNCTION, - \T_CLASS => \T_CLASS, - \T_INTERFACE => \T_INTERFACE, - \T_TRAIT => \T_TRAIT, - \T_CONST => \T_CONST, - \T_VARIABLE => \T_VARIABLE, - \T_DOLLAR => \T_DOLLAR, // Variable variables. - \T_ANON_CLASS => \T_ANON_CLASS, // Only used for skipping over test classes. + $targets = array( + \T_NAMESPACE => \T_NAMESPACE, + \T_FUNCTION => \T_FUNCTION, + \T_CONST => \T_CONST, + \T_VARIABLE => \T_VARIABLE, + \T_DOLLAR => \T_DOLLAR, // Variable variables. ); + $targets += Tokens::$ooScopeTokens; // T_ANON_CLASS is only used for skipping over test classes. // Add function call target for hook names and constants defined using define(). $parent = parent::register(); @@ -259,9 +256,7 @@ public function process_token( $stackPtr ) { } // Ignore test classes. - if ( ( \T_CLASS === $this->tokens[ $stackPtr ]['code'] - || \T_TRAIT === $this->tokens[ $stackPtr ]['code'] - || \T_ANON_CLASS === $this->tokens[ $stackPtr ]['code'] ) + if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) && true === $this->is_test_class( $stackPtr ) ) { if ( $this->tokens[ $stackPtr ]['scope_condition'] === $stackPtr && isset( $this->tokens[ $stackPtr ]['scope_closer'] ) ) { @@ -345,7 +340,7 @@ public function process_token( $stackPtr ) { switch ( $this->tokens[ $stackPtr ]['type'] ) { case 'T_FUNCTION': // Methods in a class do not need to be prefixed. - if ( $this->phpcsFile->hasCondition( $stackPtr, array( \T_CLASS, \T_ANON_CLASS, \T_INTERFACE, \T_TRAIT ) ) === true ) { + if ( $this->phpcsFile->hasCondition( $stackPtr, Tokens::$ooScopeTokens ) === true ) { return; } diff --git a/WordPress/Sniffs/WP/CapitalPDangitSniff.php b/WordPress/Sniffs/WP/CapitalPDangitSniff.php index c1b18f0ba9..908e5d6cc8 100644 --- a/WordPress/Sniffs/WP/CapitalPDangitSniff.php +++ b/WordPress/Sniffs/WP/CapitalPDangitSniff.php @@ -75,19 +75,6 @@ class CapitalPDangitSniff extends Sniff { \T_COMMENT => \T_COMMENT, ); - /** - * Class-like structure tokens to listen for. - * - * Using proper spelling in class, interface and trait names does not conflict with the naming conventions. - * - * @var array - */ - private $class_tokens = array( - \T_CLASS => \T_CLASS, - \T_INTERFACE => \T_INTERFACE, - \T_TRAIT => \T_TRAIT, - ); - /** * Combined text string and comment tokens array. * @@ -108,7 +95,7 @@ public function register() { // Union the arrays - keeps the array keys. $this->text_and_comment_tokens = ( $this->text_string_tokens + $this->comment_text_tokens ); - $targets = ( $this->text_and_comment_tokens + $this->class_tokens ); + $targets = ( $this->text_and_comment_tokens + Tokens::$ooScopeTokens ); // Also sniff for array tokens to make skipping anything within those more efficient. $targets[ \T_ARRAY ] = \T_ARRAY; @@ -149,7 +136,7 @@ public function process_token( $stackPtr ) { * Deal with misspellings in class/interface/trait names. * These are not auto-fixable, but need the attention of a developer. */ - if ( isset( $this->class_tokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { + if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { $classname = $this->phpcsFile->getDeclarationName( $stackPtr ); if ( empty( $classname ) ) { return; diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 434fc1a8db..aef39075de 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -49,21 +49,13 @@ class GlobalVariablesOverrideSniff extends Sniff { * Scoped object and function structures to skip over as * variables will have a different scope within those. * - * {@internal Once the minimum PHPCS version goes up to PHPCS 3.1.0, - * this array can be partially created in the register() method - * using the upstream `Tokens::$ooScopeTokens` array.}} - * * @since 1.1.0 * * @var array */ private $skip_over = array( - \T_FUNCTION => true, - \T_CLOSURE => true, - \T_CLASS => true, - \T_ANON_CLASS => true, - \T_INTERFACE => true, - \T_TRAIT => true, + \T_FUNCTION => true, + \T_CLOSURE => true, ); /** @@ -75,15 +67,18 @@ class GlobalVariablesOverrideSniff extends Sniff { * @return array */ public function register() { - return array( + // Add the OO scope tokens to the $skip_over property. + $this->skip_over += Tokens::$ooScopeTokens; + + $targets = array( \T_GLOBAL, \T_VARIABLE, - - // Only used to skip over test classes. - \T_CLASS, - \T_TRAIT, - \T_ANON_CLASS, ); + + // Only used to skip over test classes. + $targets += Tokens::$ooScopeTokens; + + return $targets; } /** @@ -102,7 +97,7 @@ public function process_token( $stackPtr ) { $token = $this->tokens[ $stackPtr ]; // Ignore variable overrides in test classes. - if ( \T_CLASS === $token['code'] || \T_TRAIT === $token['code'] || \T_ANON_CLASS === $token['code'] ) { + if ( isset( Tokens::$ooScopeTokens[ $token['code'] ] ) ) { if ( true === $this->is_test_class( $stackPtr ) && $token['scope_condition'] === $stackPtr diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 379424e171..24a5409c70 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -404,17 +404,14 @@ public function process_token( $stackPtr ) { $firstContent = $this->phpcsFile->findNext( \T_WHITESPACE, ( $scopeOpener + 1 ), null, true ); // We ignore spacing for some structures that tend to have their own rules. - $ignore = array( + $ignore = array( \T_FUNCTION => true, \T_CLOSURE => true, - \T_CLASS => true, - \T_ANON_CLASS => true, - \T_INTERFACE => true, - \T_TRAIT => true, \T_DOC_COMMENT_OPEN_TAG => true, \T_CLOSE_TAG => true, \T_COMMENT => true, ); + $ignore += Tokens::$ooScopeTokens; if ( ! isset( $ignore[ $this->tokens[ $firstContent ]['code'] ] ) && $this->tokens[ $firstContent ]['line'] > ( $this->tokens[ $scopeOpener ]['line'] + 1 ) From 9455213a250a4fac44decf78127110f267c627db Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 17:28:34 +0100 Subject: [PATCH 19/64] PHPCS 3.2.3+: Remove the Sniff::$phpcsCommentTokens property The (protected) `Sniff::$phpcsCommentTokens` property was a work-around for the `Tokens::$phpcsCommentTokens` array not being available prior to PHPCS 3.2.3. This work-around is no longer needed now the minimum PHPCS version is 3.3.1. Note: This is a BC-break for external standards extending the WordPressCS `Sniff` class which may be using this property. They should adjust their code to use the PHPCS native `Tokens::$phpcsCommentTokens` array instead. --- WordPress/Sniff.php | 34 +++---------------- .../Arrays/ArrayDeclarationSpacingSniff.php | 2 +- .../Arrays/CommaAfterArrayItemSniff.php | 6 ++-- .../ControlStructureSpacingSniff.php | 6 ++-- .../WhiteSpace/PrecisionAlignmentSniff.php | 13 +++---- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 68f1e3c8cb..1523f812eb 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -781,32 +781,6 @@ abstract class Sniff implements PHPCS_Sniff { 'PHPUnit\Framework\TestCase' => true, ); - /** - * The token "type" values for the PHPCS 3.2+ whitelist comments. - * - * PHPCS cross-version compatibility layer to allow sniffs to - * allow for the new PHPCS annotation comments without breaking in older - * PHPCS versions. - * - * @internal Can be replaced with using the PHPCS native Token::$phpcsCommentTokens - * array once the minimum WPCS requirement for PHPCS has gone up - * to PHPCS 3.2.3. - * Note: The PHPCS native property uses the constants/ token "code", - * so code referring to this property will need to be adjusted when - * the property is removed. - * - * @since 1.0.0 - * - * @var array - */ - protected $phpcsCommentTokens = array( - 'T_PHPCS_ENABLE' => true, - 'T_PHPCS_DISABLE' => true, - 'T_PHPCS_SET' => true, - 'T_PHPCS_IGNORE' => true, - 'T_PHPCS_IGNORE_FILE' => true, - ); - /** * The current file being sniffed. * @@ -1122,8 +1096,8 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { if ( ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code'] && strpos( $this->tokens[ $lastPtr ]['content'], '@codingStandardsChangeSetting' ) === false ) - || ( isset( $this->phpcsCommentTokens[ $this->tokens[ $lastPtr ]['type'] ] ) - && 'T_PHPCS_SET' !== $this->tokens[ $lastPtr ]['type'] ) ) + || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) + && \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) ) && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $end_of_statement ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { @@ -1138,8 +1112,8 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { if ( ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code'] && strpos( $this->tokens[ $lastPtr ]['content'], '@codingStandardsChangeSetting' ) === false ) - || ( isset( $this->phpcsCommentTokens[ $this->tokens[ $lastPtr ]['type'] ] ) - && 'T_PHPCS_SET' !== $this->tokens[ $lastPtr ]['type'] ) ) + || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) + && \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) ) && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $stackPtr ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index d417fe0ea8..c46769d89f 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -384,7 +384,7 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) { // Ignore comments after array items if the next real content starts on a new line. if ( \T_COMMENT === $this->tokens[ $first_content ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $first_content ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $first_content ]['code'] ] ) ) { $next = $this->phpcsFile->findNext( array( \T_WHITESPACE, \T_DOC_COMMENT_WHITESPACE ), diff --git a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php index a1b6626b6a..296a406105 100644 --- a/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php +++ b/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php @@ -169,7 +169,7 @@ public function process_token( $stackPtr ) { $spaces += $this->tokens[ $i ]['length']; } } elseif ( \T_COMMENT === $this->tokens[ $i ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $i ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $i ]['code'] ] ) ) { break; } @@ -202,7 +202,7 @@ public function process_token( $stackPtr ) { $this->phpcsFile->fixer->replaceToken( $i, '' ); } elseif ( \T_COMMENT === $this->tokens[ $i ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $i ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $i ]['code'] ] ) ) { // We need to move the comma to before the comment. $this->phpcsFile->fixer->addContent( $last_content, ',' ); @@ -248,7 +248,7 @@ public function process_token( $stackPtr ) { || ( false === $single_line && $this->tokens[ $next_non_whitespace ]['line'] === $this->tokens[ $maybe_comma ]['line'] && ( \T_COMMENT === $this->tokens[ $next_non_whitespace ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $next_non_whitespace ]['type'] ] ) ) ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $next_non_whitespace ]['code'] ] ) ) ) ) { continue; } diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index 379424e171..1388a59608 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -474,7 +474,7 @@ public function process_token( $stackPtr ) { * conflict. */ if ( \T_COMMENT !== $this->tokens[ $lastContent ]['code'] - && ! isset( $this->phpcsCommentTokens[ $this->tokens[ $lastContent ]['type'] ] ) ) { + && ! isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastContent ]['code'] ] ) ) { $this->phpcsFile->fixer->addNewlineBefore( $j ); } @@ -500,7 +500,7 @@ public function process_token( $stackPtr ) { } if ( \T_COMMENT === $this->tokens[ $trailingContent ]['code'] - || isset( $this->phpcsCommentTokens[ $this->tokens[ $trailingContent ]['type'] ] ) + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $trailingContent ]['code'] ] ) ) { // Special exception for code where the comment about // an ELSE or ELSEIF is written between the control structures. @@ -561,7 +561,7 @@ public function process_token( $stackPtr ) { // TODO: Instead a separate error should be triggered when content comes right after closing brace. if ( \T_COMMENT !== $this->tokens[ $scopeCloser ]['code'] - && isset( $this->phpcsCommentTokens[ $this->tokens[ $scopeCloser ]['type'] ] ) === false + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $scopeCloser ]['code'] ] ) === false ) { $this->phpcsFile->fixer->addNewlineBefore( $trailingContent ); } diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index adef2d4d2d..5df4a72fea 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -11,6 +11,7 @@ use WordPressCS\WordPress\Sniff; use WordPressCS\WordPress\PHPCSHelper; +use PHP_CodeSniffer\Util\Tokens; /** * Warn on line indentation ending with spaces for precision alignment. @@ -96,18 +97,18 @@ public function process_token( $stackPtr ) { $ignoreAlignmentTokens = $this->merge_custom_array( $this->ignoreAlignmentTokens ); $check_tokens = array( - 'T_WHITESPACE' => true, - 'T_INLINE_HTML' => true, - 'T_DOC_COMMENT_WHITESPACE' => true, - 'T_COMMENT' => true, + \T_WHITESPACE => true, + \T_INLINE_HTML => true, + \T_DOC_COMMENT_WHITESPACE => true, + \T_COMMENT => true, ); - $check_tokens += $this->phpcsCommentTokens; + $check_tokens += Tokens::$phpcsCommentTokens; for ( $i = 0; $i < $this->phpcsFile->numTokens; $i++ ) { if ( 1 !== $this->tokens[ $i ]['column'] ) { continue; - } elseif ( isset( $check_tokens[ $this->tokens[ $i ]['type'] ] ) === false + } elseif ( isset( $check_tokens[ $this->tokens[ $i ]['code'] ] ) === false || ( isset( $this->tokens[ ( $i + 1 ) ] ) && \T_WHITESPACE === $this->tokens[ ( $i + 1 ) ]['code'] ) || $this->tokens[ $i ]['content'] === $this->phpcsFile->eolChar From 4503f13614ca1298219f9f6d8126ac94aef33e56 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 20:20:49 +0100 Subject: [PATCH 20/64] PHPCS 3.2+: Update inline annotations to PHPCS 3.2+ format --- WordPress/Sniff.php | 1 + WordPress/Sniffs/WP/CronIntervalSniff.php | 2 +- bin/class-ruleset-test.php | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 68f1e3c8cb..41c3ce02fd 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1756,6 +1756,7 @@ protected function is_validated( $stackPtr, $array_key = null, $in_condition_onl $bare_array_key = $this->strip_quotes( $array_key ); + // phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer.Found -- On purpose, see below. for ( $i = ( $scope_start + 1 ); $i < $scope_end; $i++ ) { if ( ! \in_array( $this->tokens[ $i ]['code'], array( \T_ISSET, \T_EMPTY, \T_UNSET ), true ) ) { diff --git a/WordPress/Sniffs/WP/CronIntervalSniff.php b/WordPress/Sniffs/WP/CronIntervalSniff.php index 56965e89fb..ae7efe50e9 100644 --- a/WordPress/Sniffs/WP/CronIntervalSniff.php +++ b/WordPress/Sniffs/WP/CronIntervalSniff.php @@ -178,7 +178,7 @@ public function process_token( $stackPtr ) { // If all digits and operators, eval! if ( preg_match( '#^[\s\d+*/-]+$#', $value ) > 0 ) { - $interval = eval( "return ( $value );" ); // @codingStandardsIgnoreLine - No harm here. + $interval = eval( "return ( $value );" ); // phpcs:ignore Squiz.PHP.Eval -- No harm here. break; } diff --git a/bin/class-ruleset-test.php b/bin/class-ruleset-test.php index 7d0d7a82c4..df174759bc 100644 --- a/bin/class-ruleset-test.php +++ b/bin/class-ruleset-test.php @@ -72,11 +72,11 @@ public function testing( $param_a, ?bool $param_b = false ): void { $d = new self(); $e = apply_filter( 'filter_name', $d, $c ); - if ( $a == $b ) { // WPCS: loose comparison OK. - $f = isset( $_GET['nonce'] ) ? 1 : 2; // WPCS: CSRF ok, input var ok. + if ( $a == $b ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison + $f = isset( $_GET['nonce'] ) ? 1 : 2; // phpcs:ignore WordPress.Security.NonceVerification.Recommended } - // @codingStandardsIgnoreLine + // phpcs:ignore Squiz.PHP.Eval,WordPress.PHP.NoSilencedErrors $g = @eval( 'return true;' ); switch ( $param_a ) { @@ -100,13 +100,13 @@ public function test_goto() { for ( ; $i < 100; $i++ ) { while ( $j-- ) { if ( 17 === $j ) { - // @codingStandardsIgnoreLine + // phpcs:ignore WordPress.PHP.DiscourageGoto.Found goto end; } } } - // @codingStandardsIgnoreLine + // phpcs:ignore WordPress.PHP.DiscourageGoto.Found end: echo 'This is a goto - it needs to be here to prevent parse errors'; } From bf7ff69baa73bb2edd7161e338806ca6008e0617 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 21:39:33 +0100 Subject: [PATCH 21/64] PHPCS 3.2+: Update unit test case annotations [1] Change `@codingStandardsChangeSetting` to `phpcs:set` (PHPCS 3.2.0) for non-array properties. --- .../ArrayDeclarationSpacingUnitTest.1.inc | 4 +- ...rrayDeclarationSpacingUnitTest.1.inc.fixed | 4 +- .../ArrayDeclarationSpacingUnitTest.2.inc | 4 +- ...rrayDeclarationSpacingUnitTest.2.inc.fixed | 4 +- .../Arrays/ArrayIndentationUnitTest.2.inc | 4 +- .../ArrayIndentationUnitTest.2.inc.fixed | 4 +- .../MultipleStatementAlignmentUnitTest.1.inc | 56 +++++++++---------- ...ipleStatementAlignmentUnitTest.1.inc.fixed | 56 +++++++++---------- .../MultipleStatementAlignmentUnitTest.2.inc | 56 +++++++++---------- ...ipleStatementAlignmentUnitTest.2.inc.fixed | 56 +++++++++---------- .../ValidHookNameUnitTest.2.inc | 4 +- .../ValidHookNameUnitTest.3.inc | 4 +- .../Tests/PHP/NoSilencedErrorsUnitTest.inc | 4 +- .../Utils/I18nTextDomainFixerUnitTest.1.inc | 4 +- .../Utils/I18nTextDomainFixerUnitTest.2.inc | 4 +- .../Utils/I18nTextDomainFixerUnitTest.3.inc | 6 +- .../I18nTextDomainFixerUnitTest.3.inc.fixed | 6 +- .../Utils/I18nTextDomainFixerUnitTest.4.inc | 4 +- .../I18nTextDomainFixerUnitTest.4.inc.fixed | 4 +- .../Utils/I18nTextDomainFixerUnitTest.css | 8 +-- .../I18nTextDomainFixerUnitTest.css.fixed | 8 +-- .../Tests/WP/AlternativeFunctionsUnitTest.inc | 10 ++-- WordPress/Tests/WP/CronIntervalUnitTest.inc | 6 +- .../WP/GlobalVariablesOverrideUnitTest.3.inc | 4 +- WordPress/Tests/WP/I18nUnitTest.1.inc | 4 +- WordPress/Tests/WP/I18nUnitTest.1.inc.fixed | 4 +- WordPress/Tests/WP/PostsPerPageUnitTest.inc | 6 +- .../ArbitraryParenthesesSpacingUnitTest.inc | 12 ++-- ...itraryParenthesesSpacingUnitTest.inc.fixed | 12 ++-- .../ControlStructureSpacingUnitTest.1.inc | 16 +++--- ...ontrolStructureSpacingUnitTest.1.inc.fixed | 16 +++--- .../ControlStructureSpacingUnitTest.2.inc | 4 +- ...ontrolStructureSpacingUnitTest.2.inc.fixed | 4 +- 33 files changed, 201 insertions(+), 201 deletions(-) diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc index e3120a8816..c5e1eb35d3 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc @@ -103,12 +103,12 @@ $fields = array( $bad = array('key' => 'value'); // Bad, spacing around parenthesis. $bad = array( 'key' => 'value' ); // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = array( 'key' => 'value' ); // Bad. $bad = array( 'key1' => 'value1', 'key2' => 'value2' ); // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed index 71b8d9c8f3..53e935b11f 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed @@ -153,7 +153,7 @@ $fields = array( $bad = array( 'key' => 'value' ); // Bad, spacing around parenthesis. $bad = array( 'key' => 'value' ); // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = array( 'key' => 'value' @@ -163,7 +163,7 @@ $bad = array( 'key2' => 'value2' ); // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc index ff971e9177..e9157b7981 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc @@ -86,12 +86,12 @@ $fields = [ $bad = ['key' => 'value']; // Bad, spacing around parenthesis. $bad = [ 'key' => 'value' ]; // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = [ 'key' => 'value' ]; // Bad. $bad = [ 'key1' => 'value1', 'key2' => 'value2' ]; // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed index 23c25a07b2..1dfa3c8e9f 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed @@ -137,7 +137,7 @@ $fields = [ $bad = [ 'key' => 'value' ]; // Bad, spacing around parenthesis. $bad = [ 'key' => 'value' ]; // Bad, spacing around parenthesis. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays false $bad = [ 'key' => 'value' @@ -147,7 +147,7 @@ $bad = [ 'key2' => 'value2' ]; // Bad. -// @codingStandardsChangeSetting WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true +// phpcs:set WordPress.Arrays.ArrayDeclarationSpacing allow_single_item_single_line_associative_arrays true $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode diff --git a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc index f6dd726bdc..ec646ebcbc 100644 --- a/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayIndentationUnitTest.2.inc @@ -1,5 +1,5 @@ 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = array( 'a' => 'b', ); @@ -95,7 +95,7 @@ $array = array( 'g' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,17 +107,17 @@ $array = array( 'ccc' => 'd', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = array( 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = array( 'a' => 'b', @@ -147,14 +147,14 @@ $array = array( 'g' => 'h', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = array( 'a' => 'b', 'ccc' => 'd', @@ -177,10 +177,10 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = array( 'a' => 'b', @@ -220,12 +220,12 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = array( 'a' => 'b', @@ -267,9 +267,9 @@ $array = array( 'kkkkkkkkkkkk' => 'l', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -330,7 +330,7 @@ $deprecated_functions = array( ), ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = array( @@ -381,24 +381,24 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = array( @@ -462,7 +462,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = array( @@ -523,7 +523,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = array( 'single1' => 'something', // Bad. @@ -571,4 +571,4 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed index 7169de6e9a..969373f2b1 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.1.inc.fixed @@ -70,7 +70,7 @@ $array = array( => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = array( 'a' => 'b', ); @@ -95,7 +95,7 @@ $array = array( 'g' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,15 +107,15 @@ $array = array( 'ccc' => 'd', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = array( 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = array( 'a' => 'b', @@ -141,14 +141,14 @@ $array = array( 'ee' => 'f', 'g' => 'h', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = array( 'a' => 'b', 'ccc' => 'd', @@ -171,10 +171,10 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = array( 'a' => 'b', @@ -214,12 +214,12 @@ $array = array( 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = array( 'a' => 'b', @@ -253,9 +253,9 @@ $array = array( 'i' => 'j', // Bad. 'kkkkkkkkkkkk' => 'l', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -316,7 +316,7 @@ $deprecated_functions = array( ), ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = array( @@ -367,24 +367,24 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = array( 'a' => 'b', ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = array( @@ -448,7 +448,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = array( @@ -509,7 +509,7 @@ $deprecated_functions = array( string', // Bad - no space. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = array( 'single1' => 'something', // Bad. @@ -557,4 +557,4 @@ $deprecated_functions = array( string', // Bad. ); -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc index d26927cd41..66507e4342 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc @@ -70,7 +70,7 @@ $array = [ => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = [ 'a' => 'b', ]; @@ -95,7 +95,7 @@ $array = [ 'g' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,17 +107,17 @@ $array = [ 'ccc' => 'd', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = [ 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = [ 'a' => 'b', @@ -147,14 +147,14 @@ $array = [ 'g' => 'h', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = [ 'a' => 'b', 'ccc' => 'd', @@ -177,10 +177,10 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = [ 'a' => 'b', @@ -220,12 +220,12 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = [ 'a' => 'b', @@ -267,9 +267,9 @@ $array = [ 'kkkkkkkkkkkk' => 'l', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -330,7 +330,7 @@ $deprecated_functions = [ ), ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = [ @@ -381,24 +381,24 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = [ @@ -462,7 +462,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = [ @@ -523,7 +523,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = [ 'single1' => 'something', // Bad. @@ -571,4 +571,4 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed index ccd188dcb7..f171336722 100644 --- a/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/MultipleStatementAlignmentUnitTest.2.inc.fixed @@ -70,7 +70,7 @@ $array = [ => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false $array = [ 'a' => 'b', ]; @@ -95,7 +95,7 @@ $array = [ 'g' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true /* @@ -107,15 +107,15 @@ $array = [ 'ccc' => 'd', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false $array = [ 'a' => 'b', // Bad. 'ccc' => 'd', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined ignore new lines false + exact false. $array = [ 'a' => 'b', @@ -141,14 +141,14 @@ $array = [ 'ee' => 'f', 'g' => 'h', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* * Test with maxColumn value set. */ -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 $array = [ 'a' => 'b', 'ccc' => 'd', @@ -171,10 +171,10 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', // Bad - too much space before. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 // Test combined maxColumn value set + exact false. $array = [ 'a' => 'b', @@ -214,12 +214,12 @@ $array = [ 'ee' => 'f', // Bad. 'gggggggggg' => 'h', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact false -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 12 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact false +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 12 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines false // Test combined maxColumn value set + exact false + ignore new lines false. $array = [ 'a' => 'b', @@ -253,9 +253,9 @@ $array = [ 'i' => 'j', // Bad. 'kkkkkkkkkkkk' => 'l', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment exact true -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment exact true +// phpcs:set WordPress.Arrays.MultipleStatementAlignment maxColumn 1000 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment ignoreNewlines true /* @@ -316,7 +316,7 @@ $deprecated_functions = [ ), ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems never // OK - alignments to the expected column. $deprecated_functions = [ @@ -367,24 +367,24 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems sometimes // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems =103 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !50 // Test invalid property value error. $array = [ 'a' => 'b', ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <25 // OK - alignments to the expected column. $deprecated_functions = [ @@ -448,7 +448,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems <=50% // Test with value 50 and test validation for incorrectly passed % sign. $deprecated_functions = [ @@ -509,7 +509,7 @@ $deprecated_functions = [ string', // Bad - no space. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems !=100 $deprecated_functions = [ 'single1' => 'something', // Bad. @@ -557,4 +557,4 @@ $deprecated_functions = [ string', // Bad. ]; -// @codingStandardsChangeSetting WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always +// phpcs:set WordPress.Arrays.MultipleStatementAlignment alignMultilineItems always diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc index 084a176612..99b42d3b2b 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.2.inc @@ -1,6 +1,6 @@ screen->id}", $this->_actions ); // Warning - use underscore. apply_filters( "current_theme/supports-{$feature}", true, $args, $_wp_theme_features[$feature] ); // Warning - use underscore. -// @codingStandardsChangeSetting WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ +// phpcs:set WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ diff --git a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc index e58cc75781..61b854c582 100644 --- a/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc +++ b/WordPress/Tests/NamingConventions/ValidHookNameUnitTest.3.inc @@ -1,6 +1,6 @@ screen->id}", $this->_actions ); // Warning - use underscore. apply_filters( "current_theme#supports-{$feature}", true, $args, $_wp_theme_features[$feature] ); // Warning - use underscore. -// @codingStandardsChangeSetting WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ +// phpcs:set WordPress.NamingConventions.ValidHookName additionalWordDelimiters _ diff --git a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc index 18b0faaa77..38869c11f9 100644 --- a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc +++ b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc @@ -52,7 +52,7 @@ $unserialized = @unserialize( $str ); /* * ... and test the same principle again, but now without using the whitelist. */ -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors use_default_whitelist false +// phpcs:set WordPress.PHP.NoSilencedErrors use_default_whitelist false // File extension. if ( @&file_exists( $filename ) && @ /*comment*/ is_readable( $filename ) ) { // Bad x2. @@ -79,4 +79,4 @@ echo @some_userland_function( $param ); // Bad. $decoded = @hex2bin( $data ); // @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist false -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors use_default_whitelist true +// phpcs:set WordPress.PHP.NoSilencedErrors use_default_whitelist true diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc index 08665c16f5..02526739e9 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.1.inc @@ -1,6 +1,6 @@ ' ); // OK. -// @codingStandardsChangeSetting WordPress.WP.AlternativeFunctions minimum_supported_version 4.0 +// phpcs:set WordPress.WP.AlternativeFunctions minimum_supported_version 4.0 parse_url($url, PHP_URL_QUERY); // OK. -// @codingStandardsChangeSetting WordPress.WP.AlternativeFunctions minimum_supported_version 4.7 +// phpcs:set WordPress.WP.AlternativeFunctions minimum_supported_version 4.7 parse_url($url, PHP_URL_SCHEME); // Warning. -// @codingStandardsChangeSetting WordPress.WP.AlternativeFunctions minimum_supported_version 4.6 +// phpcs:set WordPress.WP.AlternativeFunctions minimum_supported_version 4.6 file_get_contents( $local_file, true ); // OK. file_get_contents( $url, false ); // Warning. diff --git a/WordPress/Tests/WP/CronIntervalUnitTest.inc b/WordPress/Tests/WP/CronIntervalUnitTest.inc index 78da5bb0bb..712eb64072 100644 --- a/WordPress/Tests/WP/CronIntervalUnitTest.inc +++ b/WordPress/Tests/WP/CronIntervalUnitTest.inc @@ -81,7 +81,7 @@ add_filter( 'cron_schedules', function ( $schedules ) { return $schedules; } ); // Warning: time undetermined. -// @codingStandardsChangeSetting WordPress.WP.CronInterval min_interval 600 +// phpcs:set WordPress.WP.CronInterval min_interval 600 add_filter( 'cron_schedules', function ( $schedules ) { $schedules['every_2_mins'] = array( 'interval' => 2 * 60, @@ -104,7 +104,7 @@ add_filter( 'cron_schedules', function ( $schedules ) { return $schedules; } ); // OK: > 10 min. -// @codingStandardsChangeSetting WordPress.WP.CronInterval min_interval 1800 +// phpcs:set WordPress.WP.CronInterval min_interval 1800 add_filter( 'cron_schedules', function ( $schedules ) { $schedules['every_2_mins'] = array( 'interval' => 2 * 60, @@ -127,7 +127,7 @@ add_filter( 'cron_schedules', function ( $schedules ) { return $schedules; } ); // Ok: > 30 min. -// @codingStandardsChangeSetting WordPress.WP.CronInterval min_interval 900 +// phpcs:set WordPress.WP.CronInterval min_interval 900 add_filter( 'cron_schedules', function ( $schedules ) { diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc index 9dd7f6c876..c6cf922415 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.3.inc @@ -6,7 +6,7 @@ * For this file, none of the variables overrides should throw errors, for the sister-file they all should. */ -// @codingStandardsChangeSetting WordPress.WP.GlobalVariablesOverride treat_files_as_scoped true +// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped true // Overrides in the global namespace should be detected no matter what. No need for a `global` statement. $pagenow = 'abc'; // OK. @@ -28,4 +28,4 @@ $domain['subkey'] = 'something else'; // OK. $GLOBALS['domain']['subkey'] = 'something else'; // Still bad. -// @codingStandardsChangeSetting WordPress.WP.GlobalVariablesOverride treat_files_as_scoped false +// phpcs:set WordPress.WP.GlobalVariablesOverride treat_files_as_scoped false diff --git a/WordPress/Tests/WP/I18nUnitTest.1.inc b/WordPress/Tests/WP/I18nUnitTest.1.inc index 249e902c37..fc2abd2547 100644 --- a/WordPress/Tests/WP/I18nUnitTest.1.inc +++ b/WordPress/Tests/WP/I18nUnitTest.1.inc @@ -1,6 +1,6 @@ extra !== $extra)) {} // Bad x 4. if (( null !== $extra ) && ( $row->extra !== $extra )) {} @@ -114,7 +114,7 @@ if ( $success && ('nothumb' == $target || 'all' == $target) ) {} // Bad x 2. $directory = ('/' == $file[ strlen($file)-1 ]); // Bad x 2. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 /* * Test handling of ignoreNewlines. @@ -132,7 +132,7 @@ $a = ( null !== $extra ); // Bad x 2, 1 x line 131, 1 x line 133. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 if ( ( null !== $extra @@ -144,9 +144,9 @@ if ( $a = ( null !== $extra ); // Bad x 2, 1 x line 144, 1 x line 146. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true if ( ( null !== $extra @@ -158,4 +158,4 @@ if ( $a = ( null !== $extra ); -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed index 64c9edd4a7..c75771237c 100644 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed +++ b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed @@ -86,7 +86,7 @@ if ( $success && ('nothumb' == $target || 'all' == $target) ) {} $directory = ('/' == $file[ strlen($file)-1 ]); -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 if (( null !== $extra ) && ( $row->extra !== $extra )) {} // Bad x 4. if (( null !== $extra ) && ( $row->extra !== $extra )) {} @@ -114,7 +114,7 @@ if ( $success && ( 'nothumb' == $target || 'all' == $target ) ) {} // Bad x 2. $directory = ( '/' == $file[ strlen($file)-1 ] ); // Bad x 2. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 /* * Test handling of ignoreNewlines. @@ -126,15 +126,15 @@ if ( $a = (null !== $extra); // Bad x 2, 1 x line 131, 1 x line 133. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 if ( ( null !== $extra ) && ( $row->extra !== $extra ) ) {} // Bad x 4, 1 x line 137, 2 x line 139, 1 x line 141. $a = ( null !== $extra ); // Bad x 2, 1 x line 144, 1 x line 146. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true if ( ( null !== $extra @@ -146,4 +146,4 @@ if ( $a = ( null !== $extra ); -// @codingStandardsChangeSetting WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false +// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc index c8cede58b7..ab0d8568b6 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc @@ -45,7 +45,7 @@ endif; if ( false ) : else : endif; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $a = function($arg){}; // Bad. $a = function ( $arg ) { // Ok. @@ -74,7 +74,7 @@ function testA() function &return_by_ref() {} // Ok. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 $a = function() {}; // Ok. $a = function( $arg ) {}; // Ok. @@ -84,7 +84,7 @@ $a = function () {}; // Bad. $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. @@ -100,7 +100,7 @@ $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // // Namespaces. use Foo\Admin; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 $a = function( $arg ) {}; // Ok. $a = function ( $arg ) {}; // Ok. @@ -139,12 +139,12 @@ try{ // Bad. } // Upstream bug PEAR #20248. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true // Bad. if ( $one ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Upstream bug PEAR #20247. do { @@ -152,7 +152,7 @@ do { } while ($blah); // Bad. // Upstream bug GH #782 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true if ( $foo ) { @@ -173,7 +173,7 @@ if ( $foo ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Check for too many spaces as long as the next non-blank token is on the same line. function test( $blah ) {} // Bad. diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed index bed9205f68..ef625e6362 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.1.inc.fixed @@ -43,7 +43,7 @@ endif; if ( false ) : else : endif; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $a = function ( $arg ) {}; // Bad. $a = function ( $arg ) { // Ok. @@ -70,7 +70,7 @@ function testA() {} // Bad. function &return_by_ref() {} // Ok. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 0 $a = function() {}; // Ok. $a = function( $arg ) {}; // Ok. @@ -80,7 +80,7 @@ $a = function() {}; // Bad. $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. $closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Bad. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren 1 $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // Ok. @@ -96,7 +96,7 @@ $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // // Namespaces. use Foo\Admin; -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1 $a = function( $arg ) {}; // Ok. $a = function ( $arg ) {}; // Ok. @@ -135,11 +135,11 @@ try { // Bad. } // Upstream bug PEAR #20248. -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true // Bad. if ( $one ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Upstream bug PEAR #20247. do { @@ -147,7 +147,7 @@ do { } while ( $blah ); // Bad. // Upstream bug GH #782 -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check true if ( $foo ) { @@ -168,7 +168,7 @@ if ( $foo ) { } -// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false +// phpcs:set WordPress.WhiteSpace.ControlStructureSpacing blank_line_check false // Check for too many spaces as long as the next non-blank token is on the same line. function test( $blah ) {} // Bad. diff --git a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc index 44f7bd2b95..f35ba950bb 100644 --- a/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc +++ b/WordPress/Tests/WhiteSpace/ControlStructureSpacingUnitTest.2.inc @@ -1,7 +1,7 @@ Date: Sat, 15 Dec 2018 21:42:40 +0100 Subject: [PATCH 22/64] PHPCS 3.2+/3.3+: Update unit test case annotations [2] * Change `@codingStandardsChangeSetting` to `phpcs:set` (PHPCS 3.2.0) for array properties. * Change properties to use the new array format (PHPCS 3.3.0). --- .../Tests/DB/DirectDatabaseQueryUnitTest.inc | 14 ++++++------ .../Tests/DB/RestrictedClassesUnitTest.1.inc | 6 ++--- .../PrefixAllGlobalsUnitTest.1.inc | 22 +++++++++---------- .../PrefixAllGlobalsUnitTest.2.inc | 4 ++-- .../PrefixAllGlobalsUnitTest.3.inc | 4 ++-- .../PrefixAllGlobalsUnitTest.4.inc | 8 +++---- .../ValidVariableNameUnitTest.inc | 4 ++-- .../PHP/DevelopmentFunctionsUnitTest.inc | 6 ++--- .../Tests/PHP/NoSilencedErrorsUnitTest.inc | 8 +++---- .../Tests/Security/EscapeOutputUnitTest.inc | 12 +++++----- .../Security/NonceVerificationUnitTest.inc | 14 ++++++------ .../ValidatedSanitizedInputUnitTest.inc | 10 ++++----- .../Utils/I18nTextDomainFixerUnitTest.3.inc | 12 +++++----- .../I18nTextDomainFixerUnitTest.3.inc.fixed | 12 +++++----- .../Utils/I18nTextDomainFixerUnitTest.4.inc | 4 ++-- .../I18nTextDomainFixerUnitTest.4.inc.fixed | 4 ++-- .../Utils/I18nTextDomainFixerUnitTest.css | 6 ++--- .../I18nTextDomainFixerUnitTest.css.fixed | 6 ++--- .../WP/GlobalVariablesOverrideUnitTest.1.inc | 4 ++-- .../WP/GlobalVariablesOverrideUnitTest.4.inc | 4 ++-- WordPress/Tests/WP/I18nUnitTest.1.inc | 10 ++++----- WordPress/Tests/WP/I18nUnitTest.1.inc.fixed | 10 ++++----- WordPress/Tests/WP/I18nUnitTest.2.inc | 4 ++-- .../PrecisionAlignmentUnitTest.2.inc | 4 ++-- .../PrecisionAlignmentUnitTest.7a.inc | 2 +- .../PrecisionAlignmentUnitTest.7c.inc | 2 +- 26 files changed, 98 insertions(+), 98 deletions(-) diff --git a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc index a6cb54414a..2f735dd7f5 100644 --- a/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc +++ b/WordPress/Tests/DB/DirectDatabaseQueryUnitTest.inc @@ -119,9 +119,9 @@ $b = function () { /* * Test using custom properties, setting & unsetting (resetting). */ -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheGetFunctions my_cacheget -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheSetFunctions my_cacheset,my_other_cacheset -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions my_cachedel +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheGetFunctions[] my_cacheget +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheSetFunctions[] my_cacheset,my_other_cacheset +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions[] my_cachedel function cache_customA() { global $wpdb; @@ -149,8 +149,8 @@ function cache_customC() { my_cachedel( 'key', 'group' ); } -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheSetFunctions my_cacheset -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions false +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheSetFunctions[] my_cacheset +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheDeleteFunctions[] function cache_customD() { global $wpdb; @@ -179,8 +179,8 @@ function cache_customF() { my_cachedel( 'key', 'group' ); } -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheGetFunctions false -// @codingStandardsChangeSetting WordPress.DB.DirectDatabaseQuery customCacheSetFunctions false +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheGetFunctions[] +// phpcs:set WordPress.DB.DirectDatabaseQuery customCacheSetFunctions[] function cache_customG() { global $wpdb; diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc index c5dbdc3897..60d70609bb 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc @@ -45,21 +45,21 @@ $db9 = new \My\DBlayer; * Test exclude property. */ // Exclude one group: -// @codingStandardsChangeSetting WordPress.DB.RestrictedClasses exclude test +// phpcs:set WordPress.DB.RestrictedClasses exclude[] test $db9 = new \My\DBlayer; // Ok - within excluded group. echo mysqli::$affected_rows; // Error. class YourMysqliA extends \mysqli {} // Error. // Exclude all groups: -// @codingStandardsChangeSetting WordPress.DB.RestrictedClasses exclude test,mysql +// phpcs:set WordPress.DB.RestrictedClasses exclude[] test,mysql $db9 = new \My\DBlayer; // Ok - within excluded group. echo mysqli::$affected_rows; // Ok - within excluded group. class YourMysqliB extends \mysqli {} // Ok - within excluded group. // Reset group exclusions. -// @codingStandardsChangeSetting WordPress.DB.RestrictedClasses exclude false +// phpcs:set WordPress.DB.RestrictedClasses exclude[] $db9 = new \My\DBlayer; // Error. echo mysqli::$affected_rows; // Error. diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc index 4098a17e94..10b79f3a86 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc @@ -3,14 +3,14 @@ /* * Bad: invalid prefix passed */ -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes wp +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] wp function wp_do_something() {} -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes ^%& +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] ^%& function ^%&_do_something() {} // Now let's set the real prefixes we want to test for. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes acronym,tgmpa +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] acronym,tgmpa /* * Bad - not prefixed. @@ -181,7 +181,7 @@ class Example extends WP_UnitTestCase { function do_something() {} } -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist My_TestClass +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist[] My_TestClass class Test_Class_D extends My_TestClass { const SOME_CONSTANT = 'value'; @@ -190,7 +190,7 @@ class Test_Class_D extends My_TestClass { function do_something() {} } -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist false +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals custom_test_class_whitelist[] /* @@ -379,7 +379,7 @@ define( 'FORCE_SSL_ADMIN', true ); const SCRIPT_DEBUG = $develop_src; // Allow for hook name prefixes with less conventional separators. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes test-this,myplugin\ +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] test-this,myplugin\ do_action( 'test-this-hookname' ); // OK. apply_filters( 'myplugin\filtername', $var ); // OK. @@ -398,18 +398,18 @@ class Some_Test_Class extends NonTestClass { // Bad. } } -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes wordpress,somethingelse +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] wordpress,somethingelse // The above line adds an issue to line 1 about a blacklisted prefix. function wordpress_do_something() {} // Bad. function somethingelse_do_something() {} // OK. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes my_wordpress_plugin +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] my_wordpress_plugin apply_filters( 'my_wordpress_plugin_filtername', $var ); // OK. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes test-this +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] test-this do_action( 'Test-THIS-hookname' ); // OK. -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes acronym,tgmpa +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] acronym,tgmpa // Issue #1495 - throw the error on the line with the non-prefixed name. $acronym = apply_filters( 'content-types-post-types', // Bad. @@ -424,4 +424,4 @@ define( [ 1, 2, 3 ] ); -// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes false +// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[] diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc index d83f0564fc..7a9193871a 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.2.inc @@ -1,5 +1,5 @@ DOMProperty; // Ok, whitelisted. echo $object->varName; // Ok, whitelisted. -// @codingStandardsChangeSetting WordPress.NamingConventions.ValidVariableName customPropertiesWhitelist false +// phpcs:set WordPress.NamingConventions.ValidVariableName customPropertiesWhitelist[] echo $object->varName; // Bad, no longer whitelisted. diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc index ab9fa0bfc5..5039be590e 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc @@ -19,16 +19,16 @@ error_reporting(); // Error. * Test exclude property. */ // Exclude one group: -// @codingStandardsChangeSetting WordPress.PHP.DevelopmentFunctions exclude error_log +// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] error_log trigger_error(); // Ok - within excluded group. phpinfo(); // Error. // Exclude all groups: -// @codingStandardsChangeSetting WordPress.PHP.DevelopmentFunctions exclude error_log,prevent_path_disclosure +// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] error_log,prevent_path_disclosure trigger_error(); // Ok - within excluded group. phpinfo(); // Ok - within excluded group. // Reset group exclusions. -// @codingStandardsChangeSetting WordPress.PHP.DevelopmentFunctions exclude false +// phpcs:set WordPress.PHP.DevelopmentFunctions exclude[] trigger_error(); // Error. phpinfo(); // Error. diff --git a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc index 38869c11f9..3e52794bc9 100644 --- a/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc +++ b/WordPress/Tests/PHP/NoSilencedErrorsUnitTest.inc @@ -39,11 +39,11 @@ if ( @ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0 ) ) { // Bad. } @ftp_close($conn_id); // Bad. -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist fgetcsv,hex2bin +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] fgetcsv,hex2bin while ( ( $csvdata = @fgetcsv( $handle, 2000, $separator ) ) !== false ) {} echo @some_userland_function( $param ); // Bad. $decoded = @hex2bin( $data ); -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist false +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] $decoded = @hex2bin( $data ); // Bad. @@ -73,10 +73,10 @@ $files1 = @ & scandir($dir); // Bad. /* * Custom whitelist will be respected even when `use_default_whitelist` is set to false. */ -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist fgetcsv,hex2bin +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] fgetcsv,hex2bin while ( ( $csvdata = @fgetcsv( $handle, 2000, $separator ) ) !== false ) {} echo @some_userland_function( $param ); // Bad. $decoded = @hex2bin( $data ); -// @codingStandardsChangeSetting WordPress.PHP.NoSilencedErrors custom_whitelist false +// phpcs:set WordPress.PHP.NoSilencedErrors custom_whitelist[] // phpcs:set WordPress.PHP.NoSilencedErrors use_default_whitelist true diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.inc b/WordPress/Tests/Security/EscapeOutputUnitTest.inc index d27ec631f1..bd7adb3930 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.inc +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.inc @@ -186,21 +186,21 @@ echo add_filter( get_the_excerpt( get_the_ID() ) ; // Bad, but ignored as code c /* * Test using custom properties, setting & unsetting (resetting). */ -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customPrintingFunctions to_screen,my_print +// phpcs:set WordPress.Security.EscapeOutput customPrintingFunctions[] to_screen,my_print to_screen( $var1, esc_attr( $var2 ) ); // Bad x 1. my_print( $var1, $var2 ); // Bad x 2. -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customEscapingFunctions esc_form_field -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customAutoEscapedFunctions post_info,cpt_info +// phpcs:set WordPress.Security.EscapeOutput customEscapingFunctions[] esc_form_field +// phpcs:set WordPress.Security.EscapeOutput customAutoEscapedFunctions[] post_info,cpt_info echo esc_form_field( $var ); // Ok. echo post_info( $post_id, 'field' ); // Ok. echo cpt_info( $post_type, 'query' ); // Ok. to_screen( esc_form_field( $var1), esc_attr( $var2 ) ); // Ok. -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customPrintingFunctions false -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customEscapingFunctions false -// @codingStandardsChangeSetting WordPress.Security.EscapeOutput customAutoEscapedFunctions false +// phpcs:set WordPress.Security.EscapeOutput customPrintingFunctions[] +// phpcs:set WordPress.Security.EscapeOutput customEscapingFunctions[] +// phpcs:set WordPress.Security.EscapeOutput customAutoEscapedFunctions[] echo esc_form_field( $var ); // Bad. echo post_info( $post_id, 'field' ); // Bad. diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.inc b/WordPress/Tests/Security/NonceVerificationUnitTest.inc index 953ef4a134..b5387355de 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.inc +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.inc @@ -129,9 +129,9 @@ $b = function () { /* * Test using custom properties, setting & unsetting (resetting). */ -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customNonceVerificationFunctions my_nonce_check -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customSanitizingFunctions sanitize_pc,sanitize_twitter -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customUnslashingSanitizingFunctions do_something +// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[] my_nonce_check +// phpcs:set WordPress.Security.NonceVerification customSanitizingFunctions[] sanitize_pc,sanitize_twitter +// phpcs:set WordPress.Security.NonceVerification customUnslashingSanitizingFunctions[] do_something function foo_6() { @@ -140,8 +140,8 @@ function foo_6() { my_nonce_check( do_something( $_POST['tweet'] ) ); // OK. } -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customSanitizingFunctions sanitize_pc -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customUnslashingSanitizingFunctions false +// phpcs:set WordPress.Security.NonceVerification customSanitizingFunctions[] sanitize_pc +// phpcs:set WordPress.Security.NonceVerification customUnslashingSanitizingFunctions[] function foo_7() { @@ -151,8 +151,8 @@ function foo_7() { my_nonce_check( sanitize_twitter( $_POST['tweet'] ) ); // OK. } -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customNonceVerificationFunctions false -// @codingStandardsChangeSetting WordPress.Security.NonceVerification customSanitizingFunctions false +// phpcs:set WordPress.Security.NonceVerification customNonceVerificationFunctions[] +// phpcs:set WordPress.Security.NonceVerification customSanitizingFunctions[] function foo_8() { diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 3e99770deb..9a8e6c4844 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -131,21 +131,21 @@ function test_this() { $abc = sanitize_color( wp_unslash( $_POST['abc_field'] ) ); // Bad x1 - sanitize. - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions sanitize_color,sanitize_twitter_handle + // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] sanitize_color,sanitize_twitter_handle $abc = sanitize_color( wp_unslash( $_POST['abc_field'] ) ); // OK. $abc = sanitize_facebook_id( wp_unslash( $_POST['abc_field'] ) ); // Bad x1 - sanitize. $abc = sanitize_twitter_handle( $_POST['abc_field'] ); // Bad x1 - unslash. - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions sanitize_color,sanitize_facebook_id - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions sanitize_twitter_handle + // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] sanitize_color,sanitize_facebook_id + // phpcs:set WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions[] sanitize_twitter_handle $abc = sanitize_color( wp_unslash( $_POST['abc_field'] ) ); // OK. $abc = sanitize_facebook_id( wp_unslash( $_POST['abc_field'] ) ); // OK. $abc = sanitize_twitter_handle( $_POST['abc_field'] ); // OK. - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions false - // @codingStandardsChangeSetting WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions false + // phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] + // phpcs:set WordPress.Security.ValidatedSanitizedInput customUnslashingSanitizingFunctions[] $abc = sanitize_twitter_handle( $_POST['abc_field'] ); // Bad x2, sanitize + unslash. } diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc index 780315e84f..adf61b3332 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.3.inc @@ -1,5 +1,5 @@ translate( $string ); // OK, not a function, but a method call. Something\esc_html_e( $string ); // OK, not the WP function, but namespaced function call. @@ -177,5 +177,5 @@ $offset_or_tz = _x( '0', 'default GMT offset or timezone string', 'my-slug' ); $test = __( '%1$s %2$s', 'my-slug' ); // OK(ish), placeholder order may change depending on language. $test = __( ' %s ', 'my-slug' ); // Bad, no translatable content. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain false +// phpcs:set WordPress.WP.I18n text_domain[] // phpcs:set WordPress.WP.I18n check_translator_comments true diff --git a/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed b/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed index 42c5132505..7689308bcd 100644 --- a/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed +++ b/WordPress/Tests/WP/I18nUnitTest.1.inc.fixed @@ -5,7 +5,7 @@ __( 'string' ); // OK - no text domain known, so not checked. __( 'string', 'something' ); // OK - no text domain known, so not checked. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug +// phpcs:set WordPress.WP.I18n text_domain[] my-slug __( 'string' ); // Bad - no text domain passed. __( 'string', 'something' ); // Bad - text domain mismatch. @@ -147,20 +147,20 @@ really. EOD , 'my-slug' ); // OK. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug,default +// phpcs:set WordPress.WP.I18n text_domain[] my-slug,default __( "String default text domain.", "my-slug" ); // Ok. __( "String default text domain.", "default" ); // Ok. __( "String default text domain.", 'something' ); // Bad, text domain mismatch. __( 'String default text domain.' ); // Warning, use default. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain default +// phpcs:set WordPress.WP.I18n text_domain[] default __( 'String default text domain.', 'my-slug' ); // Bad because text_domain is only 'default'. __( 'String default text domain.' ); // Warning, text domain can be omitted. __( 'String default text domain.', /* Explicitly set for reason. */ 'default' ); // Warning, text domain can be omitted (not auto-fixable). __( 'String default text domain.' ); // Ok because default domain is 'default' and it matches one of the supplied configured text domains. // Issue #1266. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug +// phpcs:set WordPress.WP.I18n text_domain[] my-slug $mo->translate( $string ); // OK, not a function, but a method call. Something\esc_html_e( $string ); // OK, not the WP function, but namespaced function call. @@ -177,5 +177,5 @@ $offset_or_tz = _x( '0', 'default GMT offset or timezone string', 'my-slug' ); $test = __( '%1$s %2$s', 'my-slug' ); // OK(ish), placeholder order may change depending on language. $test = __( ' %s ', 'my-slug' ); // Bad, no translatable content. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain false +// phpcs:set WordPress.WP.I18n text_domain[] // phpcs:set WordPress.WP.I18n check_translator_comments true diff --git a/WordPress/Tests/WP/I18nUnitTest.2.inc b/WordPress/Tests/WP/I18nUnitTest.2.inc index 4ad5e2895b..eac6892a4d 100644 --- a/WordPress/Tests/WP/I18nUnitTest.2.inc +++ b/WordPress/Tests/WP/I18nUnitTest.2.inc @@ -2,7 +2,7 @@ /* * Test sniffing for translator comments. */ -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain my-slug +// phpcs:set WordPress.WP.I18n text_domain[] my-slug /* Basic test ****************************************************************/ __( 'No placeholders here.', 'my-slug' ); // Ok, no placeholders, so no translators comment needed. @@ -107,4 +107,4 @@ _e(); // Bad. // phpcs:ignore Standard.Category.Sniff -- testing that the PHPCS annotations are handled correctly. printf( __( 'There are %1$d monkeys in the %2$s', 'my-slug' ), intval( $number ), esc_html( $string ) ); // Bad. -// @codingStandardsChangeSetting WordPress.WP.I18n text_domain false +// phpcs:set WordPress.WP.I18n text_domain[] diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc index ce007868ea..8ee264ae22 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.2.inc @@ -1,4 +1,4 @@ -@codingStandardsChangeSetting WordPress.WhiteSpace.PrecisionAlignment ignoreAlignmentTokens T_COMMENT,T_DOC_COMMENT_WHITESPACE,T_INLINE_HTML,T_FUNCTION +phpcs:set WordPress.WhiteSpace.PrecisionAlignment ignoreAlignmentTokens[] T_COMMENT,T_DOC_COMMENT_WHITESPACE,T_INLINE_HTML,T_FUNCTION Date: Sun, 16 Dec 2018 13:44:27 +0100 Subject: [PATCH 23/64] PHPCS 3.2+/3.3+: Update unit test case annotations [3] Change for the `FileName` sniff unit tests. * Change `@codingStandardsChangeSetting` to `phpcs:set` (PHPCS 3.2.0). * Change array properties to use the new array format (PHPCS 3.3.0). * Move the annotations away from line 1. If a line just and only contains a PHPCS annotation, no errors will be thrown on it. As the `FileName` sniff will always throw errors on line 1, this means that the settings change annotations _cannot_ be on line 1 for the tests to work correctly. --- .../NonStrictClassNames/ClassNonStrictClass.inc | 5 +++-- .../NonStrictClassNames/non-strict-class.inc | 5 +++-- .../NonStrictClassNames/unrelated-filename.inc | 5 +++-- .../FileNameUnitTests/TestFiles/test-sample-custom-unit.inc | 5 +++-- .../TestFiles/test-sample-global-namespace-extends.1.inc | 5 +++-- .../TestFiles/test-sample-global-namespace-extends.2.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.1.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.2.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.3.inc | 5 +++-- .../TestFiles/test-sample-namespaced-declaration.4.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.1.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.2.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.3.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.4.inc | 5 +++-- .../TestFiles/test-sample-namespaced-extends.5.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/FrontPage.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/application_flash.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/archive-post_type.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/author-nice_name.inc | 5 +++-- .../ThemeExceptions/category-another_slug.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/category-slug.inc | 5 +++-- .../ThemeExceptions/content-another_slug.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/content-slug.inc | 5 +++-- .../ThemeExceptions/embed-post_type-post_format.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/embed-post_type.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/front-page.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/front_page.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/page-slug_slug.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/single-post-type.inc | 5 +++-- .../ThemeExceptions/single-post_type-slug.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/single-post_type.inc | 5 +++-- .../FileNameUnitTests/ThemeExceptions/tag-another_slug.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/tag-slug.inc | 5 +++-- .../ThemeExceptions/taxonomy-my_taxonomy-term.inc | 5 +++-- .../ThemeExceptions/taxonomy-my_taxonomy.inc | 5 +++-- .../taxonomy-post_format-post-format-link.inc | 5 +++-- .../ThemeExceptions/taxonomy-post_format.inc | 5 +++-- .../Tests/Files/FileNameUnitTests/ThemeExceptions/text.inc | 5 +++-- .../Files/FileNameUnitTests/ThemeExceptions/text_plain.inc | 5 +++-- 39 files changed, 117 insertions(+), 78 deletions(-) diff --git a/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc b/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc index c4d4103a48..fb6d0ab14e 100644 --- a/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc +++ b/WordPress/Tests/Files/FileNameUnitTests/NonStrictClassNames/ClassNonStrictClass.inc @@ -1,7 +1,8 @@ -@codingStandardsChangeSetting WordPress.Files.FileName strict_class_file_names false + +phpcs:set WordPress.Files.FileName strict_class_file_names false +phpcs:set WordPress.Files.FileName strict_class_file_names false +phpcs:set WordPress.Files.FileName strict_class_file_names false +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] My_TestClass +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName custom_test_class_whitelist[] Some\Name\TestSample +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true +phpcs:set WordPress.Files.FileName is_theme true Date: Mon, 17 Dec 2018 04:28:44 +0100 Subject: [PATCH 24/64] Core: Remove `encoding` (PHPCS 3.0.0) The default encoding as of PHPCS 3.0.0 is `utf-8`, so there is no need to set this anymore in the ruleset. --- WordPress-Core/ruleset.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index a01712e9c3..99483c11c6 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -5,9 +5,6 @@ ./../WordPress/PHPCSAliases.php - - - From 61b8ab424b2403c34f9fda20cf25d7c32d0e5f2c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 29 Aug 2017 22:22:28 +0200 Subject: [PATCH 25/64] Extra: Defer to upstream `Generic.Files.OneObjectStructurePerFile` sniff (PHPCS 3.1.0) PHPCS 3.1.0 includes a new `Generic.Files.OneObjectStructurePerFile` sniff. We previously included the `Generic.Files.OneClassPerFile`, `Generic.Files.OneInterfacePerFile` and the `Generic.Files.OneTraitPerFile` sniffs. Each of those would only throw an error is a second object structure of the same kind was found in a file, i.e. two classes in one file, but would allow files which contained more than one object structure, but of different types, through without any errors being thrown, i.e. an interface and a class in the same file. The new `Generic.Files.OneObjectStructurePerFile` sniff fixes this and can effectively replace the previously included sniffs. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniffs. Refs: * squizlabs/PHP_CodeSniffer 1627 * squizlabs/PHP_CodeSniffer 1630 --- WordPress-Extra/ruleset.xml | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index f96cd4e977..87acba16a9 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -63,22 +63,9 @@ - - - + warning - Best practice suggestion: Declare only one class in a file. - - - - warning - Best practice suggestion: Declare only one interface in a file. - - - - warning - Best practice suggestion: Declare only one trait in a file. + Best practice suggestion: Declare only one class/interface/trait in a file. - diff --git a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php b/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php deleted file mode 100644 index 0aefd0a8ab..0000000000 --- a/WordPress/Sniffs/Functions/FunctionCallSignatureNoParamsSniff.php +++ /dev/null @@ -1,91 +0,0 @@ -phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); - - if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $openParenthesis ]['code'] ) { - // Not a function call. - return; - } - - if ( ! isset( $this->tokens[ $openParenthesis ]['parenthesis_closer'] ) ) { - // Not a function call. - return; - } - - // Find the previous non-empty token. - $search = Tokens::$emptyTokens; - $search[] = \T_BITWISE_AND; - $previous = $this->phpcsFile->findPrevious( $search, ( $stackPtr - 1 ), null, true ); - if ( \T_FUNCTION === $this->tokens[ $previous ]['code'] ) { - // It's a function definition, not a function call. - return; - } - - $closer = $this->tokens[ $openParenthesis ]['parenthesis_closer']; - - if ( ( $closer - 1 ) === $openParenthesis ) { - return; - } - - $nextNonWhitespace = $this->phpcsFile->findNext( \T_WHITESPACE, ( $openParenthesis + 1 ), null, true ); - - if ( $nextNonWhitespace !== $closer ) { - // Function has params or comment between parenthesis. - return; - } - - $fix = $this->phpcsFile->addFixableError( - 'Function calls without parameters should have no spaces between the parenthesis.', - ( $openParenthesis + 1 ), - 'WhitespaceFound' - ); - if ( true === $fix ) { - // If there is only whitespace between the parenthesis, it will just be the one token. - $this->phpcsFile->fixer->replaceToken( ( $openParenthesis + 1 ), '' ); - } - } - -} diff --git a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.inc b/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.inc deleted file mode 100644 index 788da75df0..0000000000 --- a/WordPress/Tests/Functions/FunctionCallSignatureNoParamsUnitTest.inc +++ /dev/null @@ -1,9 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 4 => 1, - 5 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - } - -} From cf3205f7fdc8ce5f5d9706020a5e039bbd47e615 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 22:15:27 +0100 Subject: [PATCH 28/64] Readme: Recommend/mention dot prefixed config files (PHPCS 3.1.1) Since PHPCS 3.1.0, the config file can be dot-prefixed, i.e. `.phpcs.xml` or `.phpcs.xml.dist`. Since PHPCS 3.1.1, the loading order has been corrected for the config files. So, as the minimum PHPCS version is now well passed those versions, let's mention this in the readme. Refs: * squizlabs/PHP_CodeSniffer 1566 * squizlabs/PHP_CodeSniffer 1693 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e9fc04d31..c4b644d5d2 100644 --- a/README.md +++ b/README.md @@ -138,11 +138,11 @@ The `WordPress-VIP` ruleset was originally intended to aid with the [WordPress.c ### Using a custom ruleset -If you need to further customize the selection of sniffs for your project - you can create a custom ruleset file. When you name this file either `phpcs.xml` or `phpcs.xml.dist`, PHP_CodeSniffer will automatically locate it as long as it is placed in the directory from which you run the CodeSniffer or in a directory above it. If you follow these naming conventions you don't have to supply a `--standard` arg. For more info, read about [using a default configuration file](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file). See also provided [`phpcs.xml.dist.sample`](phpcs.xml.dist.sample) file and [fully annotated example](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) in the PHP_CodeSniffer documentation. +If you need to further customize the selection of sniffs for your project - you can create a custom ruleset file. When you name this file either `.phpcs.xml`, `phpcs.xml`, `.phpcs.xml.dist` or `phpcs.xml.dist`, PHP_CodeSniffer will automatically locate it as long as it is placed in the directory from which you run the CodeSniffer or in a directory above it. If you follow these naming conventions you don't have to supply a `--standard` arg. For more info, read about [using a default configuration file](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file). See also provided [`phpcs.xml.dist.sample`](phpcs.xml.dist.sample) file and [fully annotated example](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) in the PHP_CodeSniffer documentation. ### Customizing sniff behaviour -The WordPress Coding Standard contains a number of sniffs which are configurable. This means that you can turn parts of the sniff on or off, or change the behaviour by setting a property for the sniff in your custom `phpcs.xml` file. +The WordPress Coding Standard contains a number of sniffs which are configurable. This means that you can turn parts of the sniff on or off, or change the behaviour by setting a property for the sniff in your custom `.phpcs.xml.dist` file. You can find a complete list of all the properties you can change in the [wiki](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties). From 73a8cd1951b6b751e140289c8686463ab86078ca Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 17:49:36 +0100 Subject: [PATCH 29/64] Core: Defer to upstream `Generic.PHP.DiscourageGoto` sniff (PHPCS 3.2.0) PHPCS 3.2.0 includes the same `DiscourageGoto` sniff as was previously pulled to WPCS. As the minimum PHPCS requirement has gone up to beyond 3.2.0 now, we can switch over to use the upstream version instead. Note: Deprecating the WPCS version of the sniff and letting it extend the upstream version and throwing a deprecation message would be useless in this case, as: * When doing so, the error codes for the normal messages would not change, so people would not be able to update their custom rulesets and/or inline annotations. * If both sniffs - the WPCS one and the PHPCS version - would be included in the ruleset, we'd need to silence the error codes from one or the other to prevent duplicate messages from being thrown. - If we'd silence the PHPCS messages, the net effect would be the same as just keeping the WPCS sniff and people would still not be able to adjust their rulesets/annotations. - If we'd silence the WPCS messages, the net effect would be the same as this PR minus the deprecation message. So, as this will be going into a major release anyway, we may as well get the change over with. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniff. Refs: * squizlabs/PHP_CodeSniffer 1662 * squizlabs/PHP_CodeSniffer 1664 --- WordPress-Core/ruleset.xml | 5 +- WordPress/Sniffs/PHP/DiscourageGotoSniff.php | 50 ------------------- .../Tests/PHP/DiscourageGotoUnitTest.inc | 18 ------- .../Tests/PHP/DiscourageGotoUnitTest.php | 46 ----------------- bin/class-ruleset-test.php | 4 +- 5 files changed, 3 insertions(+), 120 deletions(-) delete mode 100644 WordPress/Sniffs/PHP/DiscourageGotoSniff.php delete mode 100644 WordPress/Tests/PHP/DiscourageGotoUnitTest.inc delete mode 100644 WordPress/Tests/PHP/DiscourageGotoUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..e32592ad3d 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -398,10 +398,7 @@ - - - + error The "goto" language construct should not be used. diff --git a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php b/WordPress/Sniffs/PHP/DiscourageGotoSniff.php deleted file mode 100644 index 5e2ce7ede5..0000000000 --- a/WordPress/Sniffs/PHP/DiscourageGotoSniff.php +++ /dev/null @@ -1,50 +0,0 @@ -phpcsFile->addWarning( 'Using the "goto" language construct is discouraged', $stackPtr, 'Found' ); - } - -} diff --git a/WordPress/Tests/PHP/DiscourageGotoUnitTest.inc b/WordPress/Tests/PHP/DiscourageGotoUnitTest.inc deleted file mode 100644 index f564215b05..0000000000 --- a/WordPress/Tests/PHP/DiscourageGotoUnitTest.inc +++ /dev/null @@ -1,18 +0,0 @@ - => - */ - public function getErrorList() { - return array(); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 3 => 1, - 6 => 1, - 11 => 1, - 16 => 1, - ); - } - -} diff --git a/bin/class-ruleset-test.php b/bin/class-ruleset-test.php index df174759bc..e9a85899c4 100644 --- a/bin/class-ruleset-test.php +++ b/bin/class-ruleset-test.php @@ -100,13 +100,13 @@ public function test_goto() { for ( ; $i < 100; $i++ ) { while ( $j-- ) { if ( 17 === $j ) { - // phpcs:ignore WordPress.PHP.DiscourageGoto.Found + // phpcs:ignore Generic.PHP.DiscourageGoto.Found goto end; } } } - // phpcs:ignore WordPress.PHP.DiscourageGoto.Found + // phpcs:ignore Generic.PHP.DiscourageGoto.Found end: echo 'This is a goto - it needs to be here to prevent parse errors'; } From c7bc2f78b413e4079410cc0ab07287177b1272aa Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 18:51:59 +0100 Subject: [PATCH 30/64] Core: Defer to upstream `Squiz.WhiteSpace.SemicolonSpacing` sniff (PHPCS 3.2.0) The WPCS native `SemicolonSpacing` sniff was only ever meant as a temporary solution to get round a bug in the upstream sniff. The bugfix was merged in PHPCS 3.2.0, so we as the minimum PHPCS requirement has gone up to beyond that now, we can defer to the upstream sniff instead. Note: Deprecating the WPCS version of the sniff and letting it extend the upstream version and throwing a deprecation message would be useless in this case, as: * When doing so, the error codes for the normal messages would not change, so people would not be able to update their custom rulesets and/or inline annotations. * If both sniffs - the WPCS one and the PHPCS version - would be included in the ruleset, we'd need to silence the error codes from one or the other to prevent duplicate messages from being thrown. - If we'd silence the PHPCS messages, the net effect would be the same as just keeping the WPCS sniff and people would still not be able to adjust their rulesets/annotations. - If we'd silence the WPCS messages, the net effect would be the same as this PR minus the deprecation message. So, as this will be going into a major release anyway, we may as well get the change over with. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniff. Refs: * 1163 * squizlabs/PHP_CodeSniffer 1690 * squizlabs/PHP_CodeSniffer 1691 --- WordPress-Core/ruleset.xml | 5 +- .../WhiteSpace/SemicolonSpacingSniff.php | 66 ------------------- .../WhiteSpace/SemicolonSpacingUnitTest.inc | 12 ---- .../SemicolonSpacingUnitTest.inc.fixed | 12 ---- .../WhiteSpace/SemicolonSpacingUnitTest.php | 46 ------------- 5 files changed, 1 insertion(+), 140 deletions(-) delete mode 100644 WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php delete mode 100644 WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc delete mode 100644 WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed delete mode 100644 WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..262c64eef8 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -456,10 +456,7 @@ - - + diff --git a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php deleted file mode 100644 index d4a4ce787f..0000000000 --- a/WordPress/Sniffs/WhiteSpace/SemicolonSpacingSniff.php +++ /dev/null @@ -1,66 +0,0 @@ -getTokens(); - - // Don't examine semi-colons for empty conditions in `for()` control structures. - if ( isset( $tokens[ $stackPtr ]['nested_parenthesis'] ) ) { - $nested_parenthesis = $tokens[ $stackPtr ]['nested_parenthesis']; - $close_parenthesis = end( $nested_parenthesis ); - - if ( isset( $tokens[ $close_parenthesis ]['parenthesis_owner'] ) ) { - $owner = $tokens[ $close_parenthesis ]['parenthesis_owner']; - - if ( \T_FOR === $tokens[ $owner ]['code'] ) { - $previous = $phpcsFile->findPrevious( - Tokens::$emptyTokens, - ( $stackPtr - 1 ), - $tokens[ $owner ]['parenthesis_opener'], - true - ); - - if ( false !== $previous - && ( $previous === $tokens[ $owner ]['parenthesis_opener'] - || \T_SEMICOLON === $tokens[ $previous ]['code'] ) - ) { - return; - } - } - } - } - - return parent::process( $phpcsFile, $stackPtr ); - } - -} diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc deleted file mode 100644 index ec7f406707..0000000000 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc +++ /dev/null @@ -1,12 +0,0 @@ -= 0; $ptr-- ) {} -for ( ; ; ) {} - -// But it should when the whitespace is between a condition and a semi-colon. -for ( $i = 1 ; ; $i++ ) {} diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed deleted file mode 100644 index 0a0820f150..0000000000 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.inc.fixed +++ /dev/null @@ -1,12 +0,0 @@ -= 0; $ptr-- ) {} -for ( ; ; ) {} - -// But it should when the whitespace is between a condition and a semi-colon. -for ( $i = 1; ; $i++ ) {} diff --git a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php deleted file mode 100644 index 1078620c1c..0000000000 --- a/WordPress/Tests/WhiteSpace/SemicolonSpacingUnitTest.php +++ /dev/null @@ -1,46 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 12 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array(); - } - -} From 90963b862cfe51d0d286194a3286cf74a8cd21df Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:05:08 +0100 Subject: [PATCH 31/64] Sniff::has_whitelist_comment(): Deprecate use of the WPCS native whitelist comments (PHPCS 3.2.0) The WPCS native whitelist comments were introduced for lack of the ability to selectively ignore one or more sniffs for a piece of code. PHPCS 3.2.0 introduced native PHPCS annotations which allow for selective ignoring/disabling of sniffs and while those were originally a bit buggy, all known bugs have been fixed since, making the WPCS native whitelist comments redundant. This commit deprecates the method within WPCS which is used to check for the WPCS native whitelist comments. It also introduces a warning which will be thrown whenever a WPCS native whitelist comment is encountered to alert people to this change and encourage them to switch over to the PHPCS native annotations. Notes: * No deprecation notice will be thrown when a WPCS whitelist comment is combined with a PHPCS native annotation, i.e. `// phpcs:ignore WP.Security.EscapeOutput -- WPCS: XSS ok.` * As a sniff may be triggered several times for different tokens, a light weight (static) cache variable has been introduced to prevent the deprecation notice being thrown more than once for each WPCS whitelist comment encountered. The `Sniff::has_whitelist_comment()` method and all calls to it should be removed in WPCS 3.0.0. - [ ] References to the WPCS native whitelist comments need to be removed from the wiki and/or replaced with an upgrade guide. - [ ] Open an issue about removing the `Sniff::has_whitelist_comment()` method and calls to it in WPCS 3.0.0. Note: all unit tests testing that the WPCS native whitelist comments are being respected should also be removed at that time. Or alternatively, they can remain and it should be verified that the WPCS native whitelist comment makes no difference anymore. Refs: * squizlabs/PHP_CodeSniffer 604 --- .github/CONTRIBUTING.md | 35 ++--------------------------------- WordPress/Sniff.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d763055c2b..babd323861 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -37,40 +37,9 @@ When you introduce new `public` sniff properties, or your sniff extends a class > **Important**: > PHPCS 3.2.0 introduced new selective ignore annotations, which can be considered an improved version of the whitelist mechanism which WPCS contains. > -> There is a [tentative intention to drop support for the WPCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1048#issuecomment-340698249) in WPCS 2.0.0. -> -> Considering that, the introduction of new whitelist comments is discouraged. +> Support for the WPCS native whitelist comments has been deprecated in WPCS 2.0.0 and will be removed in WPCS 3.0.0. > -> The below information remains as guidance for exceptional cases and to aid in understanding the previous implementation. - -Sometimes, a sniff will flag code which upon further inspection by a human turns out to be OK. - -If the sniff you are writing is susceptible to this, please consider adding the ability to [whitelist lines of code](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors). - -To this end, the `WordPress\Sniff::has_whitelist_comment()` method was introduced. - -Example usage: -```php -namespace WordPressCS\WordPress\Sniffs\Security; - -use WordPressCS\WordPress\Sniff; - -class NonceVerificationSniff extends Sniff { - - public function process_token( $stackPtr ) { - - // Check something. - - if ( $this->has_whitelist_comment( 'CSRF', $stackPtr ) ) { - return; - } - - $this->phpcsFile->addError( ... ); - } -} -``` - -When you introduce a new whitelist comment, please don't forget to update the [whitelisting code wiki page](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors) with the relevant details once your PR has been merged into the `develop` branch. +> With that in mind, (new) sniffs should not introduce new WPCS native whitelist comments. # Unit Testing diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 75917a2c25..141f285b0e 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1066,6 +1066,8 @@ protected function get_wp_version_from_cl() { * @since 0.4.0 * @since 0.14.0 Whitelist comments at the end of the statement are now also accepted. * + * @deprecated 2.0.0 Use the PHPCS native `phpcs:ignore` annotations instead. + * * @param string $comment Comment to find. * @param integer $stackPtr The position of the current token in the stack passed * in $tokens. @@ -1079,6 +1081,12 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { return false; } + static $thrown_notices = array(); + + $deprecation_notice = 'Using the WPCS native whitelist comments is deprecated. Please use the PHPCS native "phpcs:ignore Standard.Category.SniffName.ErrorCode" annotations instead. Found: %s'; + $deprecation_code = 'DeprecatedWhitelistCommentFound'; + $filename = $this->phpcsFile->getFileName(); + $regex = '#\b' . preg_quote( $comment, '#' ) . '\b#i'; // There is a findEndOfStatement() method, but it considers more tokens than @@ -1101,6 +1109,19 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $end_of_statement ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { + if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false + ) { + $this->phpcsFile->addWarning( + $deprecation_notice, + $lastPtr, + $deprecation_code, + array( $this->tokens[ $lastPtr ]['content'] ) + ); + + $thrown_notices[ $filename ][ $lastPtr ] = true; + } + return true; } } @@ -1117,6 +1138,19 @@ protected function has_whitelist_comment( $comment, $stackPtr ) { && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $stackPtr ]['line'] && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 ) { + if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false + ) { + $this->phpcsFile->addWarning( + $deprecation_notice, + $lastPtr, + $deprecation_code, + array( $this->tokens[ $lastPtr ]['content'] ) + ); + + $thrown_notices[ $filename ][ $lastPtr ] = true; + } + return true; } From 18c6c7e6551adbeaba91db6ea3e6ef809143142b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:06:43 +0100 Subject: [PATCH 32/64] WPCS native PHPCS ruleset: ignore a whitelist deprecation notice The deprecation notice in this case is actually a false positive, however as the WPCS native whitelisting is now deprecated, fixing that false positive is a moot point. --- .phpcs.xml.dist | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 504fdf6c44..fd5ccc1510 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -46,4 +46,10 @@ + + + /WordPress/AbstractClassRestrictionsSniff\.php$ + + From a6dfef615bc9d852e3786302529ba9ea123961c5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:09:34 +0100 Subject: [PATCH 33/64] SlowDBQuery: remove the warning about the deprecated `tax_query` whitelist comment As the whole WPCS whitelist comment system is now deprecated, a notice will be thrown about that comment already. No need to also throw one about the comment using an old whitelist comment. --- WordPress/Sniffs/DB/SlowDBQuerySniff.php | 16 +--------------- WordPress/Tests/DB/SlowDBQueryUnitTest.php | 2 +- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/WordPress/Sniffs/DB/SlowDBQuerySniff.php b/WordPress/Sniffs/DB/SlowDBQuerySniff.php index 6935aae40c..d0e547d4a7 100644 --- a/WordPress/Sniffs/DB/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/DB/SlowDBQuerySniff.php @@ -61,21 +61,7 @@ public function process_token( $stackPtr ) { if ( $this->has_whitelist_comment( 'slow query', $stackPtr ) ) { return; - } - - if ( $this->has_whitelist_comment( 'tax_query', $stackPtr ) ) { - /* - * Only throw the warning about a deprecated comment when the sniff would otherwise - * have been triggered on the array key. - */ - if ( \in_array( $this->tokens[ $stackPtr ]['code'], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { - $this->phpcsFile->addWarning( - 'The "tax_query" whitelist comment is deprecated in favor of the "slow query" whitelist comment.', - $stackPtr, - 'DeprecatedWhitelistFlagFound' - ); - } - + } elseif ( $this->has_whitelist_comment( 'tax_query', $stackPtr ) ) { return; } diff --git a/WordPress/Tests/DB/SlowDBQueryUnitTest.php b/WordPress/Tests/DB/SlowDBQueryUnitTest.php index 2c0d64d2ef..6cc4a5763b 100644 --- a/WordPress/Tests/DB/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/DB/SlowDBQueryUnitTest.php @@ -44,7 +44,7 @@ public function getWarningList() { 16 => 1, 19 => 2, 30 => 1, - 32 => 1, // Warning about deprecated whitelist comment. + 32 => 1, // Whitelist comment deprecation warning. ); } From bc44bf6145cdd88581e558e7ab0890a7718178ea Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:11:45 +0100 Subject: [PATCH 34/64] Unit tests: account for the new WPCS whitelist comment deprecation notices A number of unit test case files contain WPCS whitelist comments to test that those are correctly being respected. As of now, a deprecation warning for use of the WPCS whitelist comments will be thrown on those lines, so we need to make sure that PHPCS expects those warnings. --- .../Tests/DB/PreparedSQLPlaceholdersUnitTest.php | 2 ++ WordPress/Tests/DB/PreparedSQLUnitTest.php | 7 ++++++- WordPress/Tests/DB/SlowDBQueryUnitTest.php | 2 ++ .../NamingConventions/PrefixAllGlobalsUnitTest.php | 5 +++++ WordPress/Tests/PHP/StrictComparisonsUnitTest.php | 1 + WordPress/Tests/Security/EscapeOutputUnitTest.php | 9 ++++++++- .../Tests/Security/NonceVerificationUnitTest.php | 4 +++- .../Security/ValidatedSanitizedInputUnitTest.php | 4 +++- WordPress/Tests/WP/CapitalPDangitUnitTest.php | 1 + .../Tests/WP/GlobalVariablesOverrideUnitTest.php | 14 ++++++++++++-- .../WhiteSpace/PrecisionAlignmentUnitTest.php | 1 + 11 files changed, 44 insertions(+), 6 deletions(-) diff --git a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php index 87a35ea00a..3259bb0b5c 100644 --- a/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php @@ -85,7 +85,9 @@ public function getWarningList() { 57 => 1, 58 => 1, 61 => 1, + 62 => 1, // Whitelist comment deprecation warning. 66 => 1, + 68 => 1, // Whitelist comment deprecation warning. 126 => 1, 139 => 1, 160 => 2, diff --git a/WordPress/Tests/DB/PreparedSQLUnitTest.php b/WordPress/Tests/DB/PreparedSQLUnitTest.php index d0ef7ec47d..f525dde0e6 100644 --- a/WordPress/Tests/DB/PreparedSQLUnitTest.php +++ b/WordPress/Tests/DB/PreparedSQLUnitTest.php @@ -57,7 +57,12 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 11 => 1, // Whitelist comment deprecation warning. + 12 => 1, // Whitelist comment deprecation warning. + 97 => 1, // Whitelist comment deprecation warning. + 99 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/DB/SlowDBQueryUnitTest.php b/WordPress/Tests/DB/SlowDBQueryUnitTest.php index 6cc4a5763b..24af5c213d 100644 --- a/WordPress/Tests/DB/SlowDBQueryUnitTest.php +++ b/WordPress/Tests/DB/SlowDBQueryUnitTest.php @@ -44,7 +44,9 @@ public function getWarningList() { 16 => 1, 19 => 2, 30 => 1, + 31 => 1, // Whitelist comment deprecation warning. 32 => 1, // Whitelist comment deprecation warning. + 35 => 1, // Whitelist comment deprecation warning. ); } diff --git a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php index 80a4872014..6db20b24ae 100644 --- a/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php +++ b/WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php @@ -99,6 +99,11 @@ public function getWarningList( $testFile = 'PrefixAllGlobalsUnitTest.1.inc' ) { case 'PrefixAllGlobalsUnitTest.1.inc': return array( 1 => 3, // 3 x warning for potentially incorrect prefix passed. + 201 => 1, // Whitelist comment deprecation warning. + 208 => 1, // Whitelist comment deprecation warning. + 212 => 1, // Whitelist comment deprecation warning. + 215 => 1, // Whitelist comment deprecation warning. + 216 => 1, // Whitelist comment deprecation warning. 249 => 1, 250 => 1, 253 => 1, diff --git a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php index 2f4c95d19c..79a42f6991 100644 --- a/WordPress/Tests/PHP/StrictComparisonsUnitTest.php +++ b/WordPress/Tests/PHP/StrictComparisonsUnitTest.php @@ -40,6 +40,7 @@ public function getWarningList() { 3 => 1, 10 => 1, 12 => 1, + 19 => 1, // Whitelist comment deprecation warning. 24 => 1, 29 => 1, ); diff --git a/WordPress/Tests/Security/EscapeOutputUnitTest.php b/WordPress/Tests/Security/EscapeOutputUnitTest.php index 91a97215dc..6fc0837e54 100644 --- a/WordPress/Tests/Security/EscapeOutputUnitTest.php +++ b/WordPress/Tests/Security/EscapeOutputUnitTest.php @@ -88,7 +88,14 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 126 => 1, // Whitelist comment deprecation warning. + 127 => 1, // Whitelist comment deprecation warning. + 128 => 1, // Whitelist comment deprecation warning. + 241 => 1, // Whitelist comment deprecation warning. + 243 => 1, // Whitelist comment deprecation warning. + 250 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/Security/NonceVerificationUnitTest.php b/WordPress/Tests/Security/NonceVerificationUnitTest.php index a7935c9557..d937edb1e9 100644 --- a/WordPress/Tests/Security/NonceVerificationUnitTest.php +++ b/WordPress/Tests/Security/NonceVerificationUnitTest.php @@ -55,7 +55,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 88 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php index 9eed79b4e8..02b7e9d4ae 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.php @@ -63,7 +63,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 76 => 1, // Whitelist comment deprecation warning. + ); } } diff --git a/WordPress/Tests/WP/CapitalPDangitUnitTest.php b/WordPress/Tests/WP/CapitalPDangitUnitTest.php index 494b03a72b..1139ee348e 100644 --- a/WordPress/Tests/WP/CapitalPDangitUnitTest.php +++ b/WordPress/Tests/WP/CapitalPDangitUnitTest.php @@ -59,6 +59,7 @@ public function getWarningList() { 101 => 1, 139 => 1, 146 => 0, // False negative. + 167 => 1, // Whitelist comment deprecation warning. 173 => 1, 181 => 1, ); diff --git a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php index 9739e83258..0f77e278e0 100644 --- a/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php +++ b/WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.php @@ -85,10 +85,20 @@ public function getErrorList( $testFile = '' ) { /** * Returns the lines where warnings should occur. * + * @param string $testFile The name of the file being tested. + * * @return array => */ - public function getWarningList() { - return array(); + public function getWarningList( $testFile = '' ) { + switch ( $testFile ) { + case 'GlobalVariablesOverrideUnitTest.1.inc': + return array( + 11 => 1, // Whitelist comment deprecation warning. + ); + + default: + return array(); + } } } diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index 7b600c1729..a928640dc3 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -69,6 +69,7 @@ public function getWarningList( $testFile = '' ) { 30 => 1, 31 => 1, 32 => 1, + 34 => 1, // Whitelist comment deprecation warning. 39 => 1, 65 => 1, ); From dd7566023277912d4e8284d35cd5f939621a121d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 16 Dec 2018 18:34:35 +0100 Subject: [PATCH 35/64] Core: Defer to upstream `Generic.WhiteSpace.ArbitraryParenthesesSpacing` sniff (PHPCS 3.3.0) PHPCS 3.3.0 includes the same `ArbitraryParenthesesSpacing` sniff as was previously pulled to WPCS. As the minimum PHPCS requirement has gone up to beyond 3.3.0 now, we can switch over to use the upstream version instead. Note: Deprecating the WPCS version of the sniff and letting it extend the upstream version and throwing a deprecation message would be useless in this case, as: * When doing so, the error codes for the normal messages would not change, so people would not be able to update their custom rulesets and/or inline annotations. * If both sniffs - the WPCS one and the PHPCS version - would be included in the ruleset, we'd need to silence the error codes from one or the other to prevent duplicate messages from being thrown. - If we'd silence the PHPCS messages, the net effect would be the same as just keeping the WPCS sniff and people would still not be able to adjust their rulesets/annotations. - If we'd silence the WPCS messages, the net effect would be the same as this PR minus the deprecation message. So, as this will be going into a major release anyway, we may as well get the change over with. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previously included sniff. Refs: * squizlabs/PHP_CodeSniffer 1701 --- WordPress-Core/ruleset.xml | 6 +- .../ArbitraryParenthesesSpacingSniff.php | 250 ------------------ .../ArbitraryParenthesesSpacingUnitTest.inc | 161 ----------- ...itraryParenthesesSpacingUnitTest.inc.fixed | 149 ----------- .../ArbitraryParenthesesSpacingUnitTest.php | 75 ------ 5 files changed, 2 insertions(+), 639 deletions(-) delete mode 100644 WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php delete mode 100644 WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc delete mode 100644 WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed delete mode 100644 WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..26d183f164 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -260,11 +260,9 @@ - - + - + diff --git a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php deleted file mode 100644 index 89c58ba60c..0000000000 --- a/WordPress/Sniffs/WhiteSpace/ArbitraryParenthesesSpacingSniff.php +++ /dev/null @@ -1,250 +0,0 @@ -ignoreTokens = Tokens::$functionNameTokens; - $this->ignoreTokens[ \T_VARIABLE ] = \T_VARIABLE; - $this->ignoreTokens[ \T_CLOSE_PARENTHESIS ] = \T_CLOSE_PARENTHESIS; - $this->ignoreTokens[ \T_CLOSE_CURLY_BRACKET ] = \T_CLOSE_CURLY_BRACKET; - $this->ignoreTokens[ \T_CLOSE_SQUARE_BRACKET ] = \T_CLOSE_SQUARE_BRACKET; - $this->ignoreTokens[ \T_CLOSE_SHORT_ARRAY ] = \T_CLOSE_SHORT_ARRAY; - $this->ignoreTokens[ \T_ANON_CLASS ] = \T_ANON_CLASS; - $this->ignoreTokens[ \T_USE ] = \T_USE; - $this->ignoreTokens[ \T_LIST ] = \T_LIST; - $this->ignoreTokens[ \T_DECLARE ] = \T_DECLARE; - - // Language constructs where the use of parentheses should be discouraged instead. - $this->ignoreTokens[ \T_THROW ] = \T_THROW; - $this->ignoreTokens[ \T_YIELD ] = \T_YIELD; - $this->ignoreTokens[ \T_YIELD_FROM ] = \T_YIELD_FROM; - $this->ignoreTokens[ \T_CLONE ] = \T_CLONE; - - return array( - \T_OPEN_PARENTHESIS, - \T_CLOSE_PARENTHESIS, - ); - } - - /** - * Processes this test, when one of its tokens is encountered. - * - * @since 0.14.0 - * - * @param int $stackPtr The position of the current token in the stack. - * - * @return int|void Integer stack pointer to skip forward or void to continue - * normal file processing. - */ - public function process_token( $stackPtr ) { - - if ( isset( $this->tokens[ $stackPtr ]['parenthesis_owner'] ) ) { - // This parenthesis is owned by a function/control structure etc. - return; - } - - // More checking for the type of parenthesis we *don't* want to handle. - $opener = $stackPtr; - if ( \T_CLOSE_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] ) { - if ( ! isset( $this->tokens[ $stackPtr ]['parenthesis_opener'] ) ) { - // Parse error. - return; - } - - $opener = $this->tokens[ $stackPtr ]['parenthesis_opener']; - } - - $preOpener = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $opener - 1 ), null, true ); - if ( false !== $preOpener && isset( $this->ignoreTokens[ $this->tokens[ $preOpener ]['code'] ] ) ) { - // Function or language construct call. - return; - } - - /* - * Check for empty parentheses. - */ - if ( \T_OPEN_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] - && isset( $this->tokens[ $stackPtr ]['parenthesis_closer'] ) - ) { - $nextNonEmpty = $this->phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true ); - if ( $nextNonEmpty === $this->tokens[ $stackPtr ]['parenthesis_closer'] ) { - $this->phpcsFile->addWarning( 'Empty set of arbitrary parentheses found.', $stackPtr, 'FoundEmpty' ); - - return ( $this->tokens[ $stackPtr ]['parenthesis_closer'] + 1 ); - } - } - - /* - * Check the spacing on the inside of the parentheses. - */ - $this->spacingInside = (int) $this->spacingInside; - - if ( \T_OPEN_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] - && isset( $this->tokens[ ( $stackPtr + 1 ) ], $this->tokens[ ( $stackPtr + 2 ) ] ) - ) { - $nextToken = $this->tokens[ ( $stackPtr + 1 ) ]; - - if ( \T_WHITESPACE !== $nextToken['code'] ) { - $inside = 0; - } else { - if ( $this->tokens[ ( $stackPtr + 2 ) ]['line'] !== $this->tokens[ $stackPtr ]['line'] ) { - $inside = 'newline'; - } else { - $inside = $nextToken['length']; - } - } - - if ( $this->spacingInside !== $inside - && ( 'newline' !== $inside || false === $this->ignoreNewlines ) - ) { - $error = 'Expected %s space after open parenthesis; %s found'; - $data = array( - $this->spacingInside, - $inside, - ); - $fix = $this->phpcsFile->addFixableError( $error, $stackPtr, 'SpaceAfterOpen', $data ); - - if ( true === $fix ) { - $expected = ''; - if ( $this->spacingInside > 0 ) { - $expected = str_repeat( ' ', $this->spacingInside ); - } - - if ( 0 === $inside ) { - if ( '' !== $expected ) { - $this->phpcsFile->fixer->addContent( $stackPtr, $expected ); - } - } elseif ( 'newline' === $inside ) { - $this->phpcsFile->fixer->beginChangeset(); - for ( $i = ( $stackPtr + 2 ); $i < $this->phpcsFile->numTokens; $i++ ) { - if ( \T_WHITESPACE !== $this->tokens[ $i ]['code'] ) { - break; - } - $this->phpcsFile->fixer->replaceToken( $i, '' ); - } - $this->phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), $expected ); - $this->phpcsFile->fixer->endChangeset(); - } else { - $this->phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), $expected ); - } - } - } - } - - if ( \T_CLOSE_PARENTHESIS === $this->tokens[ $stackPtr ]['code'] - && isset( $this->tokens[ ( $stackPtr - 1 ) ], $this->tokens[ ( $stackPtr - 2 ) ] ) - ) { - $prevToken = $this->tokens[ ( $stackPtr - 1 ) ]; - - if ( \T_WHITESPACE !== $prevToken['code'] ) { - $inside = 0; - } else { - if ( $this->tokens[ ( $stackPtr - 2 ) ]['line'] !== $this->tokens[ $stackPtr ]['line'] ) { - $inside = 'newline'; - } else { - $inside = $prevToken['length']; - } - } - - if ( $this->spacingInside !== $inside - && ( 'newline' !== $inside || false === $this->ignoreNewlines ) - ) { - $error = 'Expected %s space before close parenthesis; %s found'; - $data = array( - $this->spacingInside, - $inside, - ); - $fix = $this->phpcsFile->addFixableError( $error, $stackPtr, 'SpaceBeforeClose', $data ); - - if ( true === $fix ) { - $expected = ''; - if ( $this->spacingInside > 0 ) { - $expected = str_repeat( ' ', $this->spacingInside ); - } - - if ( 0 === $inside ) { - if ( '' !== $expected ) { - $this->phpcsFile->fixer->addContentBefore( $stackPtr, $expected ); - } - } elseif ( 'newline' === $inside ) { - $this->phpcsFile->fixer->beginChangeset(); - for ( $i = ( $stackPtr - 2 ); $i > 0; $i-- ) { - if ( \T_WHITESPACE !== $this->tokens[ $i ]['code'] ) { - break; - } - $this->phpcsFile->fixer->replaceToken( $i, '' ); - } - $this->phpcsFile->fixer->replaceToken( ( $stackPtr - 1 ), $expected ); - $this->phpcsFile->fixer->endChangeset(); - } else { - $this->phpcsFile->fixer->replaceToken( ( $stackPtr - 1 ), $expected ); - } - } - } - } - } - -} diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc deleted file mode 100644 index 7ec5d639e8..0000000000 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc +++ /dev/null @@ -1,161 +0,0 @@ -{$var}( $foo,$bar ); - -(function( $a, $b ) { - return function( $c, $d ) use ( $a, $b ) { - echo $a, $b, $c, $d; - }; -})( 'a','b' )( 'c','d' ); - -$closure( $foo,$bar ); -$var = $closure() + $closure( $foo,$bar ) + self::$closure( $foo,$bar ); - -class Test { - public static function baz( $foo, $bar ) { - $a = new self( $foo,$bar ); - $b = new static( $foo,$bar ); - } -} - -/* - * Test warning for empty parentheses. - */ -$a = 4 + (); // Warning. -$a = 4 + ( ); // Warning. -$a = 4 + (/* Not empty */); - -/* - * Test the actual sniff. - */ -if ((null !== $extra) && ($row->extra !== $extra)) {} - -if (( null !== $extra ) && ( $row->extra !== $extra )) {} // Bad x 4. - -if (( null !== $extra // Bad x 1. - && is_int($extra)) - && ( $row->extra !== $extra // Bad x 1. - || $something ) // Bad x 1. -) {} - -if (( null !== $extra ) // Bad x 2. - && ( $row->extra !== $extra ) // Bad x 2. -) {} - -$a = (null !== $extra); -$a = ( null !== $extra ); // Bad x 2. - -$sx = $vert ? ($w - 1) : 0; - -$this->is_overloaded = ( ( ini_get("mbstring.func_overload") & 2 ) != 0 ) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 ); - -if ( $success && ('nothumb' == $target || 'all' == $target) ) {} - -$directory = ('/' == $file[ strlen($file)-1 ]); - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if ((null !== $extra) && ($row->extra !== $extra)) {} // Bad x 4. - -if (( null !== $extra ) && ( $row->extra !== $extra )) {} - -if (( null !== $extra // Bad x 1. - && is_int($extra)) // Bad x 1. - && ( $row->extra !== $extra - || $something ) // Bad x 1. -) {} - -if ((null !== $extra) // Bad x 2. - && ($row->extra !== $extra) // Bad x 2. -) {} - -$a = (null !== $extra); // Bad x 2. -$a = ( null !== $extra ); - -$sx = $vert ? ($w - 1) : 0; // Bad x 2. - -$this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 ); // Bad x 4. - -if ( $success && ('nothumb' == $target || 'all' == $target) ) {} // Bad x 2. - -$directory = ('/' == $file[ strlen($file)-1 ]); // Bad x 2. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -/* - * Test handling of ignoreNewlines. - */ -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} // Bad x 4, 1 x line 123, 2 x line 125, 1 x line 127. - - -$a = ( - null !== $extra -); // Bad x 2, 1 x line 131, 1 x line 133. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} // Bad x 4, 1 x line 137, 2 x line 139, 1 x line 141. - -$a = ( - null !== $extra -); // Bad x 2, 1 x line 144, 1 x line 146. -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} - -$a = ( - null !== $extra -); -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed deleted file mode 100644 index c75771237c..0000000000 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed +++ /dev/null @@ -1,149 +0,0 @@ -{$var}( $foo,$bar ); - -(function( $a, $b ) { - return function( $c, $d ) use ( $a, $b ) { - echo $a, $b, $c, $d; - }; -})( 'a','b' )( 'c','d' ); - -$closure( $foo,$bar ); -$var = $closure() + $closure( $foo,$bar ) + self::$closure( $foo,$bar ); - -class Test { - public static function baz( $foo, $bar ) { - $a = new self( $foo,$bar ); - $b = new static( $foo,$bar ); - } -} - -/* - * Test warning for empty parentheses. - */ -$a = 4 + (); // Warning. -$a = 4 + ( ); // Warning. -$a = 4 + (/* Not empty */); - -/* - * Test the actual sniff. - */ -if ((null !== $extra) && ($row->extra !== $extra)) {} - -if ((null !== $extra) && ($row->extra !== $extra)) {} // Bad x 4. - -if ((null !== $extra // Bad x 1. - && is_int($extra)) - && ($row->extra !== $extra // Bad x 1. - || $something) // Bad x 1. -) {} - -if ((null !== $extra) // Bad x 2. - && ($row->extra !== $extra) // Bad x 2. -) {} - -$a = (null !== $extra); -$a = (null !== $extra); // Bad x 2. - -$sx = $vert ? ($w - 1) : 0; - -$this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 ); - -if ( $success && ('nothumb' == $target || 'all' == $target) ) {} - -$directory = ('/' == $file[ strlen($file)-1 ]); - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if (( null !== $extra ) && ( $row->extra !== $extra )) {} // Bad x 4. - -if (( null !== $extra ) && ( $row->extra !== $extra )) {} - -if (( null !== $extra // Bad x 1. - && is_int($extra) ) // Bad x 1. - && ( $row->extra !== $extra - || $something ) // Bad x 1. -) {} - -if (( null !== $extra ) // Bad x 2. - && ( $row->extra !== $extra ) // Bad x 2. -) {} - -$a = ( null !== $extra ); // Bad x 2. -$a = ( null !== $extra ); - -$sx = $vert ? ( $w - 1 ) : 0; // Bad x 2. - -$this->is_overloaded = ( ( ini_get("mbstring.func_overload") & 2 ) != 0 ) && function_exists('mb_substr'); // Bad x 4. - -$image->flip( ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 ); // Bad x 4. - -if ( $success && ( 'nothumb' == $target || 'all' == $target ) ) {} // Bad x 2. - -$directory = ( '/' == $file[ strlen($file)-1 ] ); // Bad x 2. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -/* - * Test handling of ignoreNewlines. - */ -if ( - (null !== $extra) && ($row->extra !== $extra) -) {} // Bad x 4, 1 x line 123, 2 x line 125, 1 x line 127. - - -$a = (null !== $extra); // Bad x 2, 1 x line 131, 1 x line 133. - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 1 -if ( - ( null !== $extra ) && ( $row->extra !== $extra ) -) {} // Bad x 4, 1 x line 137, 2 x line 139, 1 x line 141. - -$a = ( null !== $extra ); // Bad x 2, 1 x line 144, 1 x line 146. -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing spacingInside 0 - -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines true -if ( - ( - null !== $extra - ) && ( - $row->extra !== $extra - ) -) {} - -$a = ( - null !== $extra -); -// phpcs:set WordPress.WhiteSpace.ArbitraryParenthesesSpacing ignoreNewlines false diff --git a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php deleted file mode 100644 index e2c3ef9218..0000000000 --- a/WordPress/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.php +++ /dev/null @@ -1,75 +0,0 @@ - => - */ - public function getErrorList() { - return array( - 64 => 4, - 66 => 1, - 68 => 1, - 69 => 1, - 72 => 2, - 73 => 2, - 77 => 2, - 81 => 4, - 90 => 4, - 94 => 1, - 95 => 1, - 97 => 1, - 100 => 2, - 101 => 2, - 104 => 2, - 107 => 2, - 109 => 4, - 111 => 4, - 113 => 2, - 115 => 2, - 123 => 1, - 125 => 2, - 127 => 1, - 131 => 1, - 133 => 1, - 137 => 1, - 139 => 2, - 141 => 1, - 144 => 1, - 146 => 1, - ); - } - - /** - * Returns the lines where warnings should occur. - * - * @return array => - */ - public function getWarningList() { - return array( - 55 => 1, - 56 => 1, - ); - } - -} From ac5c1a88a2fadfef033e1512c9b14f56e1e54f12 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 03:17:29 +0100 Subject: [PATCH 36/64] Core: Defer to upstream `Generic.PHP.LowerCaseType` sniff (PHPCS 3.3.0) PHPCS 3.3.0 includes a new `Generic.PHP.LowerCaseType` sniff which has some overlap with the WPCS native `WordPress.PHP.TypeCasts` sniff. The native `WordPress.PHP.TypeCasts`, which was introduced in WPCS 1.2.0, checked: * Whether the correct form (short & normalized) of type casts is used. * Whether the type cast is lowercase. * Discourages the use of the `(unset)` and `(binary)` casts. The upstream `Generic.PHP.LowerCaseType` sniff checks: * Whether a type cast is lowercase. * Whether the type of a (non-object) parameter type declarations is lowercase. * Whether the type of a (non-object) return type declaration is lowerase. In this PR, I'm removing the "lowercase" check from the WPCS `WordPress.PHP.TypeCasts` sniff in favour of including the upstream sniff. This does mean that the case of parameter and return type declaration will now also be checked. As having those be lowercase would be consistent with the existing WP rules regarding type casts and other PHP keywords being lowercase, as well as be consistent with PSR-12, I believe this is an acceptable addition. Note: this is a BC-break for anyone using a custom ruleset or PHPCS annotations referencing the previous WPCS native errorcode for the lowercase check. Refs: * 1483 * https://github.com/squizlabs/PHP_CodeSniffer/commit/5a989395a4318475590c6515512f17e2b8e4df8f * squizlabs/PHP_CodeSniffer 2023 --- WordPress-Core/ruleset.xml | 2 ++ WordPress/Sniffs/PHP/TypeCastsSniff.php | 32 +++---------------- WordPress/Tests/PHP/TypeCastsUnitTest.inc | 28 ---------------- .../Tests/PHP/TypeCastsUnitTest.inc.fixed | 28 ---------------- WordPress/Tests/PHP/TypeCastsUnitTest.php | 32 ++----------------- 5 files changed, 8 insertions(+), 114 deletions(-) diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 99483c11c6..5b75ee0c39 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -250,6 +250,8 @@ + + diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 343ddf1785..166c0f5a1f 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -36,7 +36,10 @@ class TypeCastsSniff extends Sniff { * @return array */ public function register() { - return Tokens::$castTokens; + $targets = Tokens::$castTokens; + unset( $targets[ \T_ARRAY_CAST ], $targets[ \T_OBJECT_CAST ] ); + + return $targets; } /** @@ -122,33 +125,6 @@ public function process_token( $stackPtr ) { ); break; } - - /* - * {@internal Once the minimum PHPCS version has gone up to PHPCS 3.3.0+, the lowercase - * check below can be removed in favour of adding the `Generic.PHP.LowerCaseType` sniff - * to the ruleset. - * Note: the `register()` function also needs adjusting in that case to only register the - * targetted type casts above and the metrics recording should probably be adjusted as well. - * The above mentioned Generic sniff records metrics about the case of typecasts, so we - * don't need to worry about those no longer being recorded. They will be, just slightly - * differently.}} - */ - if ( $typecast_lc !== $typecast ) { - $data = array( - $typecast_lc, - $typecast, - ); - - $fix = $this->phpcsFile->addFixableError( - 'PHP type casts must be lowercase; expected "%s" but found "%s"', - $stackPtr, - 'NonLowercaseFound', - $data - ); - if ( true === $fix ) { - $this->phpcsFile->fixer->replaceToken( $stackPtr, $typecast_lc ); - } - } } } diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.inc b/WordPress/Tests/PHP/TypeCastsUnitTest.inc index a69c06b379..8d0fd9e74f 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.inc +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.inc @@ -20,34 +20,6 @@ $a = (binary) $b; // Warning. $a = b"binary string"; // Warning. $a = b"binary $string"; // Warning. -// Error: Mixed case. -$a = (Bool) $b; -$a = (Boolean) $b; // + wrong form. -$a = (Int) $b; -$a = (Integer) $b; // + wrong form. -$a = (Float) $b; -$a = (Double) $b; // + wrong form. -$a = (Real) $b; // + wrong form. -$a = (String) $b; -$a = (Array) $b; -$a = (Object) $b; -$a = (Unset) $b; // + discouraged. -$a = (Binary) $b; // + discouraged. - -// Error: Uppercase. -$a = (BOOL) $b; -$a = (BOOLEAN) $b; // + wrong form. -$a = (INT) $b; -$a = (INTEGER) $b; // + wrong form. -$a = (FLOAT) $b; -$a = (DOUBLE) $b; // + wrong form. -$a = (REAL) $b; // + wrong form. -$a = (STRING) $b; -$a = (ARRAY) $b; -$a = (OBJECT) $b; -$a = (UNSET) $b; // + discouraged. -$a = (BINARY) $b; // + discouraged. - // Test recognition with whitespace within the cast. // OK. $a = ( bool ) $b; diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed b/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed index 076ed30bd2..3ce98e66cf 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.inc.fixed @@ -20,34 +20,6 @@ $a = (binary) $b; // Warning. $a = b"binary string"; // Warning. $a = b"binary $string"; // Warning. -// Error: Mixed case. -$a = (bool) $b; -$a = (bool) $b; // + wrong form. -$a = (int) $b; -$a = (int) $b; // + wrong form. -$a = (float) $b; -$a = (float) $b; // + wrong form. -$a = (float) $b; // + wrong form. -$a = (string) $b; -$a = (array) $b; -$a = (object) $b; -$a = (unset) $b; // + discouraged. -$a = (binary) $b; // + discouraged. - -// Error: Uppercase. -$a = (bool) $b; -$a = (bool) $b; // + wrong form. -$a = (int) $b; -$a = (int) $b; // + wrong form. -$a = (float) $b; -$a = (float) $b; // + wrong form. -$a = (float) $b; // + wrong form. -$a = (string) $b; -$a = (array) $b; -$a = (object) $b; -$a = (unset) $b; // + discouraged. -$a = (binary) $b; // + discouraged. - // Test recognition with whitespace within the cast. // OK. $a = ( bool ) $b; diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.php b/WordPress/Tests/PHP/TypeCastsUnitTest.php index cdd88bbb68..11aa665c2b 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.php +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.php @@ -32,34 +32,10 @@ public function getErrorList() { 13 => 1, 14 => 1, 15 => 1, - 24 => 1, - 25 => 2, - 26 => 1, - 27 => 2, - 28 => 1, - 29 => 2, - 30 => 2, - 31 => 1, 32 => 1, 33 => 1, 34 => 1, 35 => 1, - 38 => 1, - 39 => 2, - 40 => 1, - 41 => 2, - 42 => 1, - 43 => 2, - 44 => 2, - 45 => 1, - 46 => 1, - 47 => 1, - 48 => 1, - 49 => 1, - 60 => 1, - 61 => 1, - 62 => 1, - 63 => 1, ); } @@ -74,12 +50,8 @@ public function getWarningList() { 19 => 1, 20 => ( version_compare( PHPCSHelper::get_version(), '3.4.0', '<' ) === true ? 0 : 1 ), 21 => 1, - 34 => 1, - 35 => 1, - 48 => 1, - 49 => 1, - 64 => 1, - 65 => 1, + 36 => 1, + 37 => 1, ); } } From 645568859a85fcf1849226e3e6b01a8bad3593ea Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 00:37:12 +0100 Subject: [PATCH 37/64] Sniff::merge_custom_array(): Remove support for incorrectly set custom array properties Array properties passed in from a custom ruleset need to have a `type="array"` attribute. Until now WPCS was lenient when this attribute was missing and would convert an array passed as a comma delimited string to an array. This functionality was deprecated for the only property which still "officially" allowed for a comma-delimited string list in WPCS 1.0.0 and will now be removed. The only exception are the two array properties which can also be set via the command-line, i.e. the `prefixes` property for the `WordPress.NamingConventions.PrefixAllGlobals` sniff and the `text_domain` property for the `WordPress.WP.I18n` sniff. If - and only if - these properties are set from the command-line, the sniffs will still convert the received string to an array. Refs: * 1390 This also removes the leniency for spaces surrounding array values. PHPCS 3.2.0 includes a similar fix as was previously made in PR 1185, which means that properties passed as arrays will already be trimmed, so no need to do it again. Refs: * 1185 * squizlabs/PHP_CodeSniffer 1689 --- WordPress/Sniff.php | 30 +++++++------------ .../PrefixAllGlobalsSniff.php | 2 +- WordPress/Sniffs/WP/I18nSniff.php | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index f95829a866..8341e10def 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -943,10 +943,8 @@ protected function string_to_errorcode( $base_string ) { } /** - * Merge a pre-set array with a ruleset provided array or inline provided string. + * Merge a pre-set array with a ruleset provided array. * - * - Will correctly handle custom array properties which were set without - * the `type="array"` indicator. * - By default flips custom lists to allow for using `isset()` instead * of `in_array()`. * - When `$flip` is true: @@ -961,14 +959,14 @@ protected function string_to_errorcode( $base_string ) { * which extends an upstream sniff can also use it.}} * * @since 0.11.0 - * - * @param array|string $custom Custom list as provided via a ruleset. - * Can be either a comma-delimited string or - * an array of values. - * @param array $base Optional. Base list. Defaults to an empty array. - * Expects `value => true` format when `$flip` is true. - * @param bool $flip Optional. Whether or not to flip the custom list. - * Defaults to true. + * @since 2.0.0 No longer supports custom array properties which were incorrectly + * passed as a string. + * + * @param array $custom Custom list as provided via a ruleset. + * @param array $base Optional. Base list. Defaults to an empty array. + * Expects `value => true` format when `$flip` is true. + * @param bool $flip Optional. Whether or not to flip the custom list. + * Defaults to true. * @return array */ public static function merge_custom_array( $custom, $base = array(), $flip = true ) { @@ -976,18 +974,10 @@ public static function merge_custom_array( $custom, $base = array(), $flip = tru $base = array_filter( $base ); } - if ( empty( $custom ) || ( ! \is_array( $custom ) && ! \is_string( $custom ) ) ) { + if ( empty( $custom ) || ! \is_array( $custom ) ) { return $base; } - // Allow for a comma delimited list. - if ( \is_string( $custom ) ) { - $custom = explode( ',', $custom ); - } - - // Always trim whitespace from the values. - $custom = array_filter( array_map( 'trim', $custom ) ); - if ( true === $flip ) { $custom = array_fill_keys( $custom, false ); } diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 8994e57130..5656b2c7e8 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -240,7 +240,7 @@ public function process_token( $stackPtr ) { // Allow overruling the prefixes set in a ruleset via the command line. $cl_prefixes = trim( PHPCSHelper::get_config_data( 'prefixes' ) ); if ( ! empty( $cl_prefixes ) ) { - $this->prefixes = $cl_prefixes; + $this->prefixes = array_filter( array_map( 'trim', explode( ',', $cl_prefixes ) ) ); } $this->prefixes = $this->merge_custom_array( $this->prefixes, array(), false ); diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index c5dab418a9..7eff323ef3 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -192,7 +192,7 @@ public function process_token( $stack_ptr ) { // Allow overruling the text_domain set in a ruleset via the command line. $cl_text_domain = trim( PHPCSHelper::get_config_data( 'text_domain' ) ); if ( ! empty( $cl_text_domain ) ) { - $this->text_domain = $cl_text_domain; + $this->text_domain = array_filter( array_map( 'trim', explode( ',', $cl_text_domain ) ) ); } $this->text_domain = $this->merge_custom_array( $this->text_domain, array(), false ); From 698eade1b4d5c6107486ccd2a8d525a5a8c5f44d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:32:42 +0100 Subject: [PATCH 38/64] Extra: Use the new `Generic.WhiteSpace.LanguageConstructSpacing` sniff (PHPCS 3.3.0) The `Squiz.WhiteSpace.LanguageConstructSpacing` sniff has been deprecated in PHPCS 3.3.0 and will be removed in PHPCS 4, in favour of the newly introduced `Generic.WhiteSpace.LanguageConstructSpacing` sniff. Ref: * 1328 * squizlabs/PHP_CodeSniffer 1337 --- WordPress-Extra/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 87acba16a9..14529fc79b 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -56,7 +56,7 @@ - + From 1c5e627b5ae2e01b8c85df47eba26abda4a4a5f2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 02:17:27 +0100 Subject: [PATCH 39/64] ValidVariableName: Defer to the upstream `$phpReservedVars` property (PHPCS 3.3.0) The upstream `PHP_CodeSniffer\Sniffs\AbstractVariableSniff` contains the same list of PHP reserved variables since PHPCS 3.3.0, so no need to maintain it ourselves. Refs: * squizlabs/PHP_CodeSniffer 1888 --- .../ValidVariableNameSniff.php | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 049b3ebab9..8c9f6a891d 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -23,6 +23,7 @@ * * @since 0.9.0 * @since 0.13.0 Class name changed: this class is now namespaced. + * @since 2.0.0 Defers to the upstream `$phpReservedVars` property. * * Last synced with base class June 2018 at commit 78ddbae97cac078f09928bf89e3ab9e53ad2ace0. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -31,29 +32,6 @@ */ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { - /** - * PHP Reserved Vars. - * - * @since 0.9.0 - * @since 0.11.0 Changed visibility from public to protected. - * - * @var array - */ - protected $php_reserved_vars = array( - '_SERVER' => true, - '_GET' => true, - '_POST' => true, - '_REQUEST' => true, - '_SESSION' => true, - '_ENV' => true, - '_COOKIE' => true, - '_FILES' => true, - 'GLOBALS' => true, - 'http_response_header' => true, - 'HTTP_RAW_POST_DATA' => true, - 'php_errormsg' => true, - ); - /** * Mixed-case variables used by WordPress. * @@ -131,7 +109,7 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { $var_name = ltrim( $tokens[ $stack_ptr ]['content'], '$' ); // If it's a php reserved var, then its ok. - if ( isset( $this->php_reserved_vars[ $var_name ] ) ) { + if ( isset( $this->phpReservedVars[ $var_name ] ) ) { return; } @@ -254,7 +232,7 @@ protected function processVariableInString( File $phpcs_file, $stack_ptr ) { foreach ( $matches[1] as $var_name ) { // If it's a php reserved var, then its ok. - if ( isset( $this->php_reserved_vars[ $var_name ] ) ) { + if ( isset( $this->phpReservedVars[ $var_name ] ) ) { continue; } From 366b8fb21e91fb047fd9c486040d2e30b2992ce4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 04:09:12 +0100 Subject: [PATCH 40/64] Extra: Document why two WPCS native sniffs are not (yet) replaced by upstream sniffs --- WordPress-Extra/ruleset.xml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 87acba16a9..f324e74648 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -27,7 +27,9 @@ + https://github.com/squizlabs/PHP_CodeSniffer/pull/1594 + Note: the "assignment in ternary" part of the sniff is currently not yet covered in + the upstream version. This needs to be pulled first before we can defer to upstream. --> + https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/919 + Note: there is a similar upstream sniff `PSR12.Classes.ClassInstantiation`, however + that sniff: + - does not cover JS files; + - does not demand parentheses for PHP anonymous classes; + - does not check the whitespace between the class name and the parentheses; + - does not check for PHP new by reference. + For those reasons, the WPCS version should remain. --> From fbd87ae372cb6928721158b817fcc1c3320d51d4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 17 Dec 2018 05:43:40 +0100 Subject: [PATCH 41/64] GH: Remove superseded issue template --- .github/issue_template.md | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .github/issue_template.md diff --git a/.github/issue_template.md b/.github/issue_template.md deleted file mode 100644 index f6e4f49872..0000000000 --- a/.github/issue_template.md +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file From 8e7019f6d83ed1bf51419bd267ca9039b1eedfa8 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 8 Jul 2018 00:29:19 +0200 Subject: [PATCH 42/64] ArrayDeclarationSpacing: improve handling of multi-line trailing comments In a multi-line array, if an array item was followed by a multi-line trailing comment and the next item started on the same line as the end of the trailing comment, no error was thrown, nor was this auto-fixed. This commit fixes that. Loosely related to 1384 --- .../Arrays/ArrayDeclarationSpacingSniff.php | 27 ++++++++-- .../ArrayDeclarationSpacingUnitTest.1.inc | 10 ++++ ...rrayDeclarationSpacingUnitTest.1.inc.fixed | 11 ++++ .../ArrayDeclarationSpacingUnitTest.2.inc | 10 ++++ ...rrayDeclarationSpacingUnitTest.2.inc.fixed | 11 ++++ .../ArrayDeclarationSpacingUnitTest.php | 50 ++++++++++--------- 6 files changed, 91 insertions(+), 28 deletions(-) diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index c46769d89f..949d818d95 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -383,12 +383,31 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) { ); // Ignore comments after array items if the next real content starts on a new line. - if ( \T_COMMENT === $this->tokens[ $first_content ]['code'] - || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $first_content ]['code'] ] ) + if ( $this->tokens[ $first_content ]['line'] === $this->tokens[ $end_of_last_item ]['line'] + && ( \T_COMMENT === $this->tokens[ $first_content ]['code'] + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $first_content ]['code'] ] ) ) ) { + $end_of_comment = $first_content; + + // Find the end of (multi-line) /* */- style trailing comments. + if ( substr( ltrim( $this->tokens[ $end_of_comment ]['content'] ), 0, 2 ) === '/*' ) { + while ( ( \T_COMMENT === $this->tokens[ $end_of_comment ]['code'] + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $end_of_comment ]['code'] ] ) ) + && substr( rtrim( $this->tokens[ $end_of_comment ]['content'] ), -2 ) !== '*/' + && ( $end_of_comment + 1 ) < $end_of_this_item + ) { + $end_of_comment++; + } + + if ( $this->tokens[ $end_of_comment ]['line'] !== $this->tokens[ $end_of_last_item ]['line'] ) { + // Multi-line trailing comment. + $end_of_last_item = $end_of_comment; + } + } + $next = $this->phpcsFile->findNext( array( \T_WHITESPACE, \T_DOC_COMMENT_WHITESPACE ), - ( $first_content + 1 ), + ( $end_of_comment + 1 ), $end_of_this_item, true ); @@ -422,7 +441,7 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) { $this->phpcsFile->fixer->beginChangeset(); - if ( $item['start'] <= ( $first_content - 1 ) + if ( ( $end_of_last_item + 1 ) <= ( $first_content - 1 ) && \T_WHITESPACE === $this->tokens[ ( $first_content - 1 ) ]['code'] ) { // Remove whitespace which would otherwise becoming trailing diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc index c5e1eb35d3..0a241823d1 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc @@ -114,3 +114,13 @@ $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); + +// Test for fixing array with multi-line comments between values. +$bad = array( + 'key1' => 'value1', /* comment + end */ 'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed index 53e935b11f..244b5787e4 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.1.inc.fixed @@ -169,3 +169,14 @@ $foo = array( 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ); + +// Test for fixing array with multi-line comments between values. +$bad = array( + 'key1' => 'value1', /* comment + end */ +'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +); diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc index e9157b7981..fc659e3612 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc @@ -97,3 +97,13 @@ $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; + +// Test for fixing array with multi-line comments between values. +$bad = [ + 'key1' => 'value1', /* comment + end */ 'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +]; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed index 1dfa3c8e9f..58adaa3bdf 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.2.inc.fixed @@ -153,3 +153,14 @@ $foo = [ 'meta_key' => 'foo', // phpcs:ignore Standard.Category.SniffName.ErrorCode 'meta_value' => 'bar', // phpcs:ignore Standard.Category.SniffName.ErrorCode ]; + +// Test for fixing array with multi-line comments between values. +$bad = [ + 'key1' => 'value1', /* comment + end */ +'key2' => 'value2', // Bad. + /* Non-trailing comment. */ + 'key3' => 'value3', /* comment + end */ + 'key4' => 'value4' +]; diff --git a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php index 3114e175bf..713d8b8cb5 100644 --- a/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php +++ b/WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php @@ -62,35 +62,37 @@ public function getErrorList( $testFile = '' ) { 104 => 2, 108 => 1, 109 => 1, + 121 => 1, ); // Short arrays. case 'ArrayDeclarationSpacingUnitTest.2.inc': return array( - 8 => 2, - 11 => 2, - 16 => 4, - 20 => 2, - 22 => 1, - 26 => 1, - 29 => 1, - 32 => 1, - 45 => 1, - 46 => 1, - 47 => 1, - 67 => 1, - 68 => 1, - 71 => 1, - 72 => 2, - 75 => 3, - 77 => 1, - 80 => 1, - 81 => 2, - 84 => 1, - 86 => 2, - 87 => 2, - 91 => 1, - 92 => 1, + 8 => 2, + 11 => 2, + 16 => 4, + 20 => 2, + 22 => 1, + 26 => 1, + 29 => 1, + 32 => 1, + 45 => 1, + 46 => 1, + 47 => 1, + 67 => 1, + 68 => 1, + 71 => 1, + 72 => 2, + 75 => 3, + 77 => 1, + 80 => 1, + 81 => 2, + 84 => 1, + 86 => 2, + 87 => 2, + 91 => 1, + 92 => 1, + 104 => 1, ); default: From 34ccaee1ce051c39df7b552c25840f100e9db266 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Dec 2018 16:26:22 +0100 Subject: [PATCH 43/64] Composer: some tweaks * Make the scripts section more readable by setting each script up as an array. * `require-dev` the DealerDirect Composer plugin to make live easier on WPCS devs using Composer for their dev environment. Includes: - Adjusting the `install-codestandards` script to use the plugin. - Removing the `post-install-cmd` and `post-update-cmd` which shouldn't be needed anymore as the plugin automatically takes care of installing the standards. * Includes updating the inline documentation in the Travis script to be inline with these changes. --- .travis.yml | 2 +- composer.json | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index b97e957b4e..64fe800947 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ before_install: - | if [[ "$SNIFF" == "1" ]]; then composer install --dev --no-suggest - # The post-install-cmd script takes care of the installed_paths. + # The `dev` required DealerDirect Composer plugin takes care of the installed_paths. else # The above require already does the install. $(pwd)/vendor/bin/phpcs --config-set installed_paths $(pwd) diff --git a/composer.json b/composer.json index 3b1adc8457..7e6f35545b 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "squizlabs/php_codesniffer": "^3.3.1" }, "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", "phpcompatibility/php-compatibility": "^9.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, @@ -27,12 +28,18 @@ }, "minimum-stability": "RC", "scripts": { - "post-install-cmd": "@install-codestandards", - "post-update-cmd": "@install-codestandards", - "check-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs", - "fix-cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf", - "install-codestandards": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths ../../..,../../phpcompatibility/php-compatibility", - "run-tests": "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress --bootstrap=\"./vendor/squizlabs/php_codesniffer/tests/bootstrap.php\" ./vendor/squizlabs/php_codesniffer/tests/AllTests.php" + "check-cs": [ + "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs" + ], + "fix-cs": [ + "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf" + ], + "install-codestandards": [ + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" + ], + "run-tests": [ + "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress --bootstrap=\"./vendor/squizlabs/php_codesniffer/tests/bootstrap.php\" ./vendor/squizlabs/php_codesniffer/tests/AllTests.php" + ] }, "support": { "issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues", From 72818a7be2fc804be47d44cff5ba57a87b360d87 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 23 Dec 2018 03:38:15 +0100 Subject: [PATCH 44/64] Extra: remove superfluous directive The sniff already throws a warning for that error code, so we don't need to change the `type`. --- WordPress-Extra/ruleset.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index aee8d0c2c7..6222ec1e55 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -76,9 +76,6 @@ - - warning - From c8f8c978a04f81eb48b81e27c825afdfb8dda026 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 23 Dec 2018 03:37:29 +0100 Subject: [PATCH 45/64] Extra: Replace `Squiz.Scope.MemberVarScope` with `PSR2.Classes.PropertyDeclaration` PR 1103 added the `Squiz.Scope.MemberVarScope` sniff to the `WordPress-Extra` ruleset which checks that all class properties have their visibility declared. The upstream `PSR2.Classes.PropertyDeclaration` sniff also does this, however it contains more extensive checks. In addition to checking for the visibility of properties being declared, this sniff also checks: * That property names are not prefixed with an underscore `_` to indicate visibility. _For methods, we already check this in the `Extra` ruleset via the `PSR2.Methods.MethodDeclaration` sniff._ * That the `var` keyword is not used for property declarations. This could be considered a duplicate check with the "use visibility" check. * That each property declaration statement only declares one property, i.e. it forbids the use of code like this: ```php public $prop1 = true, $prop2 = '', $prop3 = 123; ``` Even though there is no precedent or reference to this type of property declarations in the handbook or elsewhere in the various rulesets, WP Core itself does not appear to use multi-property assignments, so we may as well check leave the check in for now. People can always still exclude it in their own custom rulesets and if we'd get a lot of push-back, we can reconsider. * As of PHPCS 3.4.0: that the order of the property keywords is `visibility static`, not `static visibility` (includes fixer). _For methods, we already check this in the `Extra` ruleset via the `PSR2.Methods.MethodDeclaration` sniff._ All in all, using the `PSR2` sniff is more in line with the checks we already have in place for methods, so IMO, this seemed like a good change to make. --- WordPress-Extra/ruleset.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index aee8d0c2c7..6370e07db3 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -73,7 +73,7 @@ - + From f5913cc0357be2236360f04a009a24f6189160ce Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Dec 2018 16:49:47 +0100 Subject: [PATCH 46/64] PHPCS native ruleset: don't require exact array double arrow alignment When the item with the _longest_ array key is removed, WPCS requires the double arrows in the whole array to be re-aligned. Setting the [`exact` property](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#array-alignment-allow-non-exact-alignment) to `false` removes this requirement and allows for cleaner diffs when this happens. As PR 1547 removed a large number of items from the `Sniff::$autoEscapedFunctions` array, PHPCS was currently throwing warnings about the WPCS codebase. This small tweaks gets rid of those, while still allowing `phpcbf` to fix them up if so desired. --- .phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index fd5ccc1510..0bc9d6c10e 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -26,6 +26,7 @@ + From 816322ce923d703e4444e4a6e25b4f1529642339 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Jul 2017 19:51:37 +0200 Subject: [PATCH 47/64] Documentation: Touch up the class and method documentation What with classes originally having underscore delimited names, then becoming namespaced and now the namespaces being changed, documentation still referencing old, outdated class names can be confusing for new contributors. With that in mind, I've fixed up most of the documentation to either reference the sniff _code_ or the current sniff class name. --- .../AbstractArrayAssignmentRestrictionsSniff.php | 4 ++-- WordPress/AbstractClassRestrictionsSniff.php | 2 +- WordPress/AbstractFunctionRestrictionsSniff.php | 6 +++--- WordPress/Sniff.php | 8 ++++---- .../Sniffs/Arrays/ArrayDeclarationSpacingSniff.php | 11 +++++------ .../Arrays/ArrayKeySpacingRestrictionsSniff.php | 2 +- WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php | 2 +- WordPress/Sniffs/Files/FileNameSniff.php | 4 ++-- .../NamingConventions/PrefixAllGlobalsSniff.php | 2 +- .../Sniffs/NamingConventions/ValidHookNameSniff.php | 2 +- WordPress/Sniffs/PHP/DontExtractSniff.php | 3 ++- WordPress/Sniffs/PHP/POSIXFunctionsSniff.php | 5 +++-- WordPress/Sniffs/PHP/StrictInArraySniff.php | 9 +++++---- WordPress/Sniffs/PHP/YodaConditionsSniff.php | 2 +- WordPress/Sniffs/Security/EscapeOutputSniff.php | 4 ++-- WordPress/Sniffs/Security/PluginMenuSlugSniff.php | 3 ++- .../Sniffs/Security/ValidatedSanitizedInputSniff.php | 4 ++-- WordPress/Sniffs/WP/AlternativeFunctionsSniff.php | 2 +- WordPress/Sniffs/WP/CronIntervalSniff.php | 2 +- WordPress/Sniffs/WP/DeprecatedClassesSniff.php | 2 +- WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php | 2 +- .../Sniffs/WP/DeprecatedParameterValuesSniff.php | 2 +- WordPress/Sniffs/WP/DeprecatedParametersSniff.php | 2 +- WordPress/Sniffs/WP/EnqueuedResourcesSniff.php | 2 +- WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php | 6 +++--- WordPress/Sniffs/WP/I18nSniff.php | 3 ++- WordPress/Sniffs/WP/TimezoneChangeSniff.php | 4 ++-- .../Sniffs/WhiteSpace/CastStructureSpacingSniff.php | 2 +- .../WhiteSpace/ControlStructureSpacingSniff.php | 2 +- 29 files changed, 54 insertions(+), 50 deletions(-) diff --git a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php index fff3a71fc8..6095db0d72 100644 --- a/WordPress/AbstractArrayAssignmentRestrictionsSniff.php +++ b/WordPress/AbstractArrayAssignmentRestrictionsSniff.php @@ -19,8 +19,8 @@ * @since 0.3.0 * @since 0.10.0 Class became a proper abstract class. This was already the behaviour. * Moved the file and renamed the class from - * `WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff` to - * `WordPress_AbstractArrayAssignmentRestrictionsSniff`. + * `\WordPressCS\WordPress\Sniffs\Arrays\ArrayAssignmentRestrictionsSniff` to + * `\WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff`. */ abstract class AbstractArrayAssignmentRestrictionsSniff extends Sniff { diff --git a/WordPress/AbstractClassRestrictionsSniff.php b/WordPress/AbstractClassRestrictionsSniff.php index 05b0dcc5b7..ad46cb83a4 100644 --- a/WordPress/AbstractClassRestrictionsSniff.php +++ b/WordPress/AbstractClassRestrictionsSniff.php @@ -79,7 +79,7 @@ public function register() { /** * Processes this test, when one of its tokens is encountered. * - * {@internal Unlike in the `WordPress_AbstractFunctionRestrictionsSniff`, + * {@internal Unlike in the `AbstractFunctionRestrictionsSniff`, * we can't do a preliminary check on classes as at this point * we don't know the class name yet.}} * diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index 1fbc24a4bd..ea2e50ae23 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -20,9 +20,9 @@ * @since 0.3.0 * @since 0.10.0 Class became a proper abstract class. This was already the behaviour. * Moved the file and renamed the class from - * `WordPress_Sniffs_Functions_FunctionRestrictionsSniff` to - * `WordPress_AbstractFunctionRestrictionsSniff`. - * @since 0.11.0 Extends the WordPress_Sniff class. + * `\WordPressCS\WordPress\Sniffs\Functions\FunctionRestrictionsSniff` to + * `\WordPressCS\WordPress\AbstractFunctionRestrictionsSniff`. + * @since 0.11.0 Extends the WordPressCS native `Sniff` class. */ abstract class AbstractFunctionRestrictionsSniff extends Sniff { diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 8341e10def..245f7d8443 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -500,7 +500,7 @@ abstract class Sniff implements PHPCS_Sniff { * @since 0.3.0 * @since 0.11.0 Changed visibility from public to protected. * @since 0.12.0 Renamed from `$globals` to `$wp_globals` to be more descriptive. - * @since 0.12.0 Moved from WordPress_Sniffs_Variables_GlobalVariablesSniff to WordPress_Sniff + * @since 0.12.0 Moved here from the WordPress.Variables.GlobalVariables sniff. * * @var array */ @@ -955,7 +955,7 @@ protected function string_to_errorcode( $base_string ) { * before merging/returning to allow for resetting to the base array. * * {@internal Function is static as it doesn't use any of the properties or others - * methods anyway and this way the `WordPress_Sniffs_NamingConventions_ValidVariableNameSniff` + * methods anyway and this way the `WordPress.NamingConventions.ValidVariableName` sniff * which extends an upstream sniff can also use it.}} * * @since 0.11.0 @@ -2196,7 +2196,7 @@ protected function find_array_open_close( $stackPtr ) { * Determine the namespace name an arbitrary token lives in. * * @since 0.10.0 - * @since 0.12.0 Moved from the WordPress_AbstractClassRestrictionsSniff to this sniff. + * @since 0.12.0 Moved from the `AbstractClassRestrictionsSniff` to this class. * * @param int $stackPtr The token position for which to determine the namespace. * @@ -2262,7 +2262,7 @@ public function determine_namespace( $stackPtr ) { * i.e. MyProject\Sub\Level which will be returned together as one string. * * @since 0.12.0 A lesser variant of this method previously existed in the - * WordPress_AbstractClassRestrictionsSniff. + * `AbstractClassRestrictionsSniff` class. * * @param int|bool $stackPtr The position of a T_NAMESPACE token. * diff --git a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php index 949d818d95..f5c6257f3c 100644 --- a/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php @@ -27,14 +27,13 @@ * @package WPCS\WordPressCodingStandards * * @since 0.11.0 - The WordPress specific additional checks have now been split off - * from the WordPress_Sniffs_Arrays_ArrayDeclaration sniff into - * this sniff. + * from the `WordPress.Arrays.ArrayDeclaration` sniff into this sniff. * - Added sniffing & fixing for associative arrays. * @since 0.12.0 Decoupled this sniff from the upstream sniff completely. - * This sniff now extends the `WordPress_Sniff` instead. - * @since 0.13.0 Added the last remaining checks from the `ArrayDeclaration` sniff - * which were not covered elsewhere. The `ArrayDeclaration` sniff has - * now been deprecated. + * This sniff now extends the WordPressCS native `Sniff` class instead. + * @since 0.13.0 Added the last remaining checks from the `WordPress.Arrays.ArrayDeclaration` + * sniff which were not covered elsewhere. + * The `WordPress.Arrays.ArrayDeclaration` sniff has now been deprecated. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 0.14.0 Single item associative arrays are now by default exempt from the * "must be multi-line" rule. This behaviour can be changed using the diff --git a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php index 0ef102e891..b209409368 100644 --- a/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php @@ -20,7 +20,7 @@ * * @since 0.3.0 * @since 0.7.0 This sniff now has the ability to fix a number of the issues it flags. - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class ArrayKeySpacingRestrictionsSniff extends Sniff { diff --git a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php index eecb3e757e..35b4e6447b 100644 --- a/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php @@ -21,7 +21,7 @@ * * @since 0.3.0 * @since 0.6.0 Removed the add_unique_message() function as it is no longer needed. - * @since 0.11.0 This class now extends WordPress_Sniff. + * @since 0.11.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `VIP` category to the `DB` category. */ diff --git a/WordPress/Sniffs/Files/FileNameSniff.php b/WordPress/Sniffs/Files/FileNameSniff.php index 797d277d31..43eb1061b9 100644 --- a/WordPress/Sniffs/Files/FileNameSniff.php +++ b/WordPress/Sniffs/Files/FileNameSniff.php @@ -25,10 +25,10 @@ * template tags end in `-template`. Based on @subpackage file DocBlock tag. * - This sniff will now allow for underscores in file names for certain theme * specific exceptions if the `$is_theme` property is set to `true`. - * @since 0.12.0 Now extends the `WordPress_Sniff` class. + * @since 0.12.0 Now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * - * @uses \WordPress\Sniff::$custom_test_class_whitelist + * @uses \WordPressCS\WordPress\Sniff::$custom_test_class_whitelist */ class FileNameSniff extends Sniff { diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 5656b2c7e8..1dd90a3fb8 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -22,7 +22,7 @@ * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.2.0 Now also checks whether namespaces are prefixed. * - * @uses \WordPress\Sniff::$custom_test_class_whitelist + * @uses \WordPressCS\WordPress\Sniff::$custom_test_class_whitelist */ class PrefixAllGlobalsSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php index ae133c0b69..e7dc9b9e86 100644 --- a/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidHookNameSniff.php @@ -24,7 +24,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.10.0 - * @since 0.11.0 Extends the WordPress_AbstractFunctionParameterSniff class. + * @since 0.11.0 Extends the WordPressCS native `AbstractFunctionParameterSniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class ValidHookNameSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/PHP/DontExtractSniff.php b/WordPress/Sniffs/PHP/DontExtractSniff.php index 6db447ad0d..0b9b984b3a 100644 --- a/WordPress/Sniffs/PHP/DontExtractSniff.php +++ b/WordPress/Sniffs/PHP/DontExtractSniff.php @@ -18,7 +18,8 @@ * * @package WPCS\WordPressCodingStandards * - * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff. + * @since 0.10.0 Previously this check was contained within the + * `WordPress.VIP.RestrictedFunctions` sniff. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `Functions` category to the `PHP` category. */ diff --git a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php index a7e1b0be7b..aade23c63c 100644 --- a/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php +++ b/WordPress/Sniffs/PHP/POSIXFunctionsSniff.php @@ -20,8 +20,9 @@ * * @package WPCS\WordPressCodingStandards * - * @since 0.10.0 Previously this check was contained within WordPress_Sniffs_VIP_RestrictedFunctionsSniff - * and the WordPress_Sniffs_PHP_DiscouragedPHPFunctionsSniff. + * @since 0.10.0 Previously this check was contained within the + * `WordPress.VIP.RestrictedFunctions` and the + * `WordPress.PHP.DiscouragedPHPFunctions` sniffs. * @since 0.13.0 Class name changed: this class is now namespaced. */ class POSIXFunctionsSniff extends AbstractFunctionRestrictionsSniff { diff --git a/WordPress/Sniffs/PHP/StrictInArraySniff.php b/WordPress/Sniffs/PHP/StrictInArraySniff.php index f74f3f491d..f50ce14b9f 100644 --- a/WordPress/Sniffs/PHP/StrictInArraySniff.php +++ b/WordPress/Sniffs/PHP/StrictInArraySniff.php @@ -19,10 +19,11 @@ * @package WPCS\WordPressCodingStandards * * @since 0.9.0 - * @since 0.10.0 This sniff not only checks for `in_array()`, but also `array_search()` and `array_keys()`. - * The sniff no longer needlessly extends the WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff - * which it didn't use. - * @since 0.11.0 Refactored to extend the new WordPress_AbstractFunctionParameterSniff. + * @since 0.10.0 - This sniff not only checks for `in_array()`, but also `array_search()` + * and `array_keys()`. + * - The sniff no longer needlessly extends the `ArrayAssignmentRestrictionsSniff` + * class which it didn't use. + * @since 0.11.0 Refactored to extend the new WordPressCS native `AbstractFunctionParameterSniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class StrictInArraySniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/PHP/YodaConditionsSniff.php b/WordPress/Sniffs/PHP/YodaConditionsSniff.php index bd6738f69c..0587da884d 100644 --- a/WordPress/Sniffs/PHP/YodaConditionsSniff.php +++ b/WordPress/Sniffs/PHP/YodaConditionsSniff.php @@ -20,7 +20,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class YodaConditionsSniff extends Sniff { diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index 2458ddcef0..a4dd060cb2 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -20,9 +20,9 @@ * @package WPCS\WordPressCodingStandards * * @since 2013-06-11 - * @since 0.4.0 This class now extends WordPress_Sniff. + * @since 0.4.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.5.0 The various function list properties which used to be contained in this class - * have been moved to the WordPress_Sniff parent class. + * have been moved to the WordPressCS native `Sniff` parent class. * @since 0.12.0 This sniff will now also check for output escaping when using shorthand * echo tags ` value * in a custom ruleset. * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedClassesSniff extends AbstractClassRestrictionsSniff { diff --git a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php index 15adbc5307..7270899004 100644 --- a/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php @@ -28,7 +28,7 @@ * being provided via the command-line or as as value * in a custom ruleset. * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedFunctionsSniff extends AbstractFunctionRestrictionsSniff { diff --git a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php index 7bbecee22f..01a2f7f860 100644 --- a/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php @@ -19,7 +19,7 @@ * * @since 1.0.0 * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedParameterValuesSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php index 08980292d6..b6918cdb39 100644 --- a/WordPress/Sniffs/WP/DeprecatedParametersSniff.php +++ b/WordPress/Sniffs/WP/DeprecatedParametersSniff.php @@ -28,7 +28,7 @@ * being provided via the command-line or as as value * in a custom ruleset. * - * @uses \WordPress\Sniff::$minimum_supported_version + * @uses \WordPressCS\WordPress\Sniff::$minimum_supported_version */ class DeprecatedParametersSniff extends AbstractFunctionParameterSniff { diff --git a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php index 05c642156f..1473eac208 100644 --- a/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php +++ b/WordPress/Sniffs/WP/EnqueuedResourcesSniff.php @@ -20,7 +20,7 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class EnqueuedResourcesSniff extends Sniff { diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index aef39075de..615cec925c 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -18,14 +18,14 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.4.0 This class now extends WordPress_Sniff. - * @since 0.12.0 The $wp_globals property has been moved to the WordPress_Sniff. + * @since 0.4.0 This class now extends the WordPressCS native `Sniff` class. + * @since 0.12.0 The $wp_globals property has been moved to the `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `Variables` category to the `WP` * category and renamed from `GlobalVariables` to `GlobalVariablesOverride`. * @since 1.1.0 The sniff now also detects variables being overriden in the global namespace. * - * @uses \WordPress\Sniff::$custom_test_class_whitelist + * @uses \WordPressCS\WordPress\Sniff::$custom_test_class_whitelist */ class GlobalVariablesOverrideSniff extends Sniff { diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index 7eff323ef3..01797b5f78 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -27,7 +27,8 @@ * as a comma-delimited list. * `phpcs --runtime-set text_domain my-slug,default` * @since 0.13.0 Class name changed: this class is now namespaced. - * @since 1.0.0 This class now extends the AbstractFunctionRestrictionSniff. + * @since 1.0.0 This class now extends the WordPressCS native + * `AbstractFunctionRestrictionSniff` class. * The parent `exclude` property is, however, disabled as it * would disable the whole sniff. */ diff --git a/WordPress/Sniffs/WP/TimezoneChangeSniff.php b/WordPress/Sniffs/WP/TimezoneChangeSniff.php index 5970e19b1c..c57f8556cb 100644 --- a/WordPress/Sniffs/WP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/WP/TimezoneChangeSniff.php @@ -19,8 +19,8 @@ * @package WPCS\WordPressCodingStandards * * @since 0.3.0 - * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the - * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. + * @since 0.11.0 Extends the WordPressCS native `AbstractFunctionRestrictionsSniff` + * class instead of the upstream `Generic.PHP.ForbiddenFunctions` sniff. * @since 0.13.0 Class name changed: this class is now namespaced. * @since 1.0.0 This sniff has been moved from the `VIP` category to the `WP` category. */ diff --git a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php index af87a7d634..0aa4ff9cc2 100755 --- a/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php @@ -22,7 +22,7 @@ * @since 0.3.0 * @since 0.11.0 This sniff now has the ability to fix the issues it flags. * @since 0.11.0 The error level for all errors thrown by this sniff has been raised from warning to error. - * @since 0.12.0 This class now extends WordPress_Sniff. + * @since 0.12.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. */ class CastStructureSpacingSniff extends Sniff { diff --git a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index e6de10e8d1..b0654ae4f1 100644 --- a/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -20,7 +20,7 @@ * @since 0.1.0 * @since 2013-06-11 This sniff no longer supports JS. * @since 0.3.0 This sniff now has the ability to fix most errors it flags. - * @since 0.7.0 This class now extends WordPress_Sniff. + * @since 0.7.0 This class now extends the WordPressCS native `Sniff` class. * @since 0.13.0 Class name changed: this class is now namespaced. * * Last synced with base class 2017-01-15 at commit b024ad84656c37ef5733c6998ebc1e60957b2277. From 595da31d588bf1596b40f28fd3494c85f516ea98 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 15 Dec 2018 05:23:20 +0100 Subject: [PATCH 48/64] WPCS 2.0.0: Remove the PHPCSAliases file After extensive testing based on issues which were previously reported, I've concluded that the `PHPCSAliases.php` file can now be safely removed. Test setup I've used to confirm this: * Clean Composer install of PHPCS + WPCS _without the `installed_paths` config directive being set. ```json { "require": {}, "require-dev": { "squizlabs/php_codesniffer": "^3.3", "wp-coding-standards/wpcs": "^1.1" } } ``` * Basic PHPCS ruleset: ```xml . vendor/* ``` * A PHP test file which would generate issues. Tests I've run: * Running `vendor/bin/phpcs` on the above (which would be with WPCS 1.2.1) works fine. * Changed the `config` directive value to point to my local WPCS dev install: `` * Tested again against the `develop` branch, still was working fine. * Now we get to the interesting part: changed to this branch and ran it again. Still working fine. * Changed the `` to `` and still working fine. * Changed the `` to ``, i.e. not a registered standard, but a subcategory and still working fine. Based on all this, I'm concluding that the WPCS autoloader in the PHPCSAlias file is no longer needed and can now be safely removed. Refs: * 1087 * squizlabs/PHP_CodeSniffer 1591 --- WordPress-Core/ruleset.xml | 2 -- WordPress-Extra/ruleset.xml | 2 -- WordPress/PHPCSAliases.php | 46 ------------------------------------- WordPress/ruleset.xml | 2 -- 4 files changed, 52 deletions(-) delete mode 100644 WordPress/PHPCSAliases.php diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 4d4f5af8e4..045d5de7f5 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -3,8 +3,6 @@ Non-controversial generally-agreed upon WordPress Coding Standards - ./../WordPress/PHPCSAliases.php - diff --git a/WordPress-Extra/ruleset.xml b/WordPress-Extra/ruleset.xml index 001241e5c1..ad65a65568 100644 --- a/WordPress-Extra/ruleset.xml +++ b/WordPress-Extra/ruleset.xml @@ -3,8 +3,6 @@ Best practices beyond core WordPress Coding Standards - ./../WordPress/PHPCSAliases.php - - + + diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 166c0f5a1f..1d3c7663e9 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -16,8 +16,6 @@ * Verifies the correct usage of type cast keywords. * * Type casts should be: - * - lowercase; - * - short form, i.e. (bool) not (boolean); * - normalized, i.e. (float) not (real). * * Additionally, the use of the (unset) and (binary) casts is discouraged. @@ -27,6 +25,8 @@ * @package WPCS\WordPressCodingStandards * * @since 1.2.0 + * @since 2.0.0 No longer checks that type casts are lowercase or short form. + * Relevant PHPCS native sniffs have been included in the rulesets instead. */ class TypeCastsSniff extends Sniff { @@ -36,10 +36,12 @@ class TypeCastsSniff extends Sniff { * @return array */ public function register() { - $targets = Tokens::$castTokens; - unset( $targets[ \T_ARRAY_CAST ], $targets[ \T_OBJECT_CAST ] ); - - return $targets; + return array( + \T_DOUBLE_CAST, + \T_UNSET_CAST, + \T_STRING_CAST, + \T_BINARY_CAST, + ); } /** @@ -55,39 +57,7 @@ public function process_token( $stackPtr ) { $typecast = str_replace( ' ', '', $this->tokens[ $stackPtr ]['content'] ); $typecast_lc = strtolower( $typecast ); - $this->phpcsFile->recordMetric( $stackPtr, 'Typecast encountered', $typecast ); - switch ( $token_code ) { - case \T_BOOL_CAST: - if ( '(bool)' !== $typecast_lc ) { - $fix = $this->phpcsFile->addFixableError( - 'Short form type keywords must be used; expected "(bool)" but found "%s"', - $stackPtr, - 'LongBoolFound', - array( $typecast ) - ); - - if ( true === $fix ) { - $this->phpcsFile->fixer->replaceToken( $stackPtr, '(bool)' ); - } - } - break; - - case \T_INT_CAST: - if ( '(int)' !== $typecast_lc ) { - $fix = $this->phpcsFile->addFixableError( - 'Short form type keywords must be used; expected "(int)" but found "%s"', - $stackPtr, - 'LongIntFound', - array( $typecast ) - ); - - if ( true === $fix ) { - $this->phpcsFile->fixer->replaceToken( $stackPtr, '(int)' ); - } - } - break; - case \T_DOUBLE_CAST: if ( '(float)' !== $typecast_lc ) { $fix = $this->phpcsFile->addFixableError( diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.inc b/WordPress/Tests/PHP/TypeCastsUnitTest.inc index 8d0fd9e74f..e5b6f78b92 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.inc +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.inc @@ -1,16 +1,12 @@ 1, - 13 => 1, - 14 => 1, - 15 => 1, - 32 => 1, - 33 => 1, - 34 => 1, - 35 => 1, + 10 => 1, + 11 => 1, + 26 => 1, + 27 => 1, ); } @@ -46,12 +42,12 @@ public function getErrorList() { */ public function getWarningList() { return array( - 18 => 1, - 19 => 1, - 20 => ( version_compare( PHPCSHelper::get_version(), '3.4.0', '<' ) === true ? 0 : 1 ), - 21 => 1, - 36 => 1, - 37 => 1, + 14 => 1, + 15 => 1, + 16 => ( version_compare( PHPCSHelper::get_version(), '3.4.0', '<' ) === true ? 0 : 1 ), + 17 => 1, + 28 => 1, + 29 => 1, ); } } From abab1cb8f3156a3c5a4f81a2c24d921f0348853d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 05:50:14 +0100 Subject: [PATCH 50/64] OperatorSpacing: check spacing around `instanceof` operator PHPCS 3.3.0 introduces a `PSR12.Operators.OperatorSpacing` sniff. I've investigated whether that sniff would be a better sniff to extend for the `WordPress.WhiteSpace.OperatorSpacing` sniff than the `Squiz.WhiteSpace.OperatorSpacing` sniff which is currently being extended and have concluded that it is not for the following reason: * The PSR12 sniff demands _at least_ one space instead of _exactly_ one space (both allow for new lines with the correct properties). All the same, the `PSR12` sniff did include an additional token - `T_INSTANCEOF` - which makes sense to add to the WPCS sniff. Includes unit tests. --- WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php | 1 + WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc | 4 ++++ WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed | 4 ++++ WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php | 1 + 4 files changed, 10 insertions(+) diff --git a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php index 4dedca618a..26c12e20b1 100644 --- a/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php +++ b/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php @@ -54,6 +54,7 @@ class OperatorSpacingSniff extends PHPCS_Squiz_OperatorSpacingSniff { public function register() { $tokens = parent::register(); $tokens[ \T_BOOLEAN_NOT ] = \T_BOOLEAN_NOT; + $tokens[ \T_INSTANCEOF ] = \T_INSTANCEOF; $logical_operators = Tokens::$booleanOperators; // Using array union to auto-dedup. diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc index bad89cc0af..0f3f6d5a9e 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc @@ -64,3 +64,7 @@ if ( $a === $b if ( $a === $b or $b === $c ) {} + +// Instanceof +if ( MyClass instanceof SomeOtherClass ) {} +if ( MyClass instanceof SomeOtherClass ) {} diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed index 4a3214f57e..21854ae661 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed @@ -64,3 +64,7 @@ if ( $a === $b if ( $a === $b or $b === $c ) {} + +// Instanceof +if ( MyClass instanceof SomeOtherClass ) {} +if ( MyClass instanceof SomeOtherClass ) {} diff --git a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php index ff7325c071..421c61fd8d 100644 --- a/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php +++ b/WordPress/Tests/WhiteSpace/OperatorSpacingUnitTest.php @@ -42,6 +42,7 @@ public function getErrorList() { 49 => 2, 50 => 2, 51 => 2, + 69 => 2, ); } From b1451f7773f92c3e66c91aa47337cc5229e82cde Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 23 Dec 2018 14:58:00 +0100 Subject: [PATCH 51/64] README: improve instructions about using PHPCompatibility (PHPCS 3.0+) PHPCS 3.0.0 introduced an `` directive as a counter-part to the pre-existing ``. This allows to easily limit the PHPCompatibility sniffs to PHP files only, while still allowing the rest of the ruleset to be applied to both PHP, JS as well as CSS files. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4b644d5d2..b2662a15e1 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,13 @@ The [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility) sni The [PHPCompatibilityWP](https://github.com/PHPCompatibility/PHPCompatibilityWP) ruleset is based on PHPCompatibility, but specifically crafted to prevent false positives for projects which expect to run within the context of WordPress, i.e. core, plugins and themes. -Install either as a separate ruleset and either run it separately against your code or add it to your custom ruleset. +Install either as a separate ruleset and run it separately against your code or add it to your custom ruleset, like so: +```xml + + + *\.php$ + +``` Whichever way you run it, do make sure you set the `testVersion` to run the sniffs against. The `testVersion` determines for which PHP versions you will receive compatibility information. The recommended setting for this at this moment is `5.2-` to support the same PHP versions as WordPress Core supports. From e3a3fec1a731de14f9d70b50ff1a5cfe086bd075 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 16:24:05 +0100 Subject: [PATCH 52/64] PreparedSQL: use unique errorcode for messages The `WordPress.DB.PreparedSQL` sniff contains two different error messages, but didn't use unique error codes for these. --- WordPress/Sniffs/DB/PreparedSQLSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 1f8fa9b3bc..80f2418b9c 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -151,7 +151,7 @@ function ( $symbol ) { $this->phpcsFile->addError( 'Use placeholders and $wpdb->prepare(); found interpolated variable $%s at %s', $this->i, - 'NotPrepared', + 'InterpolatedNotPrepared', array( $bad_variable, $this->tokens[ $this->i ]['content'], From aa0eb35a461d437f8021b55f8fc74a1e46fa9af5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 16:29:23 +0100 Subject: [PATCH 53/64] GlobalVariablesOverride: minor error code adjustment This is more a cosmetic change than anything else. The sniff name for this sniff got changed in WPCS 1.0.0 from `GlobalVariables` to `GlobalVariablesOverride`, however, the error code also contains `override` which is now redundant. This is a BC-break and as the change is cosmetic, is a bit disputable to make this change. However, as the sniff only contains one error code, excluding the whole sniff had the same effect as excluding the single error code, so with a bit of luck, not that many people will have excluded this based on the error code. --- WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php index 615cec925c..4485c027ad 100644 --- a/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php +++ b/WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php @@ -373,7 +373,7 @@ protected function add_error( $stackPtr, $data = array() ) { $this->phpcsFile->addError( 'Overriding WordPress globals is prohibited. Found assignment to %s', $stackPtr, - 'OverrideProhibited', + 'Prohibited', $data ); } From c058b4dd4ac59d158ca2cf348590e0237eed2e37 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 17:36:12 +0100 Subject: [PATCH 54/64] PHPCSHelper: clean up Follow-up on PR 1560. As the PHPCS 2.x code has been removed, we can now use a `use` statement for the PHPCS 3.x `PHP_CodeSniffer\Config` class. --- WordPress/PHPCSHelper.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index bdabb35bf1..1e79685f46 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -9,6 +9,7 @@ namespace WordPressCS\WordPress; +use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\File; /** @@ -33,7 +34,7 @@ class PHPCSHelper { * @return string */ public static function get_version() { - return \PHP_CodeSniffer\Config::VERSION; + return Config::VERSION; } /** @@ -50,7 +51,7 @@ public static function get_version() { * This will not write the config data to the config file. */ public static function set_config_data( $key, $value, $temp = false ) { - \PHP_CodeSniffer\Config::setConfigData( $key, $value, $temp ); + Config::setConfigData( $key, $value, $temp ); } /** @@ -63,7 +64,7 @@ public static function set_config_data( $key, $value, $temp = false ) { * @return string|null */ public static function get_config_data( $key ) { - return \PHP_CodeSniffer\Config::getConfigData( $key ); + return Config::getConfigData( $key ); } /** @@ -98,7 +99,7 @@ public static function ignore_annotations( File $phpcsFile = null ) { if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) { return ! $phpcsFile->config->annotations; } else { - $annotations = \PHP_CodeSniffer\Config::getConfigData( 'annotations' ); + $annotations = Config::getConfigData( 'annotations' ); if ( isset( $annotations ) ) { return ! $annotations; } From c3872c3c5396a50cf35a7c01d27f41f74ac1911f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 17:45:48 +0100 Subject: [PATCH 55/64] CS: minor code clean up Removing: * Unused `use` statement (no longer used after code removal). * Some unnecessary interim variables (no longer needed as code which added to the variables has been removed). * Unnecessary `return` statement. * Simplify an (re-)assignment to the same variable. * Remove an unused function parameter (no longer used after previous refactor of the function code). --- WordPress/AbstractFunctionRestrictionsSniff.php | 2 -- WordPress/Sniffs/DB/PreparedSQLSniff.php | 2 +- .../NamingConventions/ValidVariableNameSniff.php | 11 +++++------ WordPress/Sniffs/PHP/TypeCastsSniff.php | 1 - WordPress/Sniffs/Security/EscapeOutputSniff.php | 4 +--- .../NamingConventions/ValidVariableNameUnitTest.php | 4 +--- .../Tests/WhiteSpace/PrecisionAlignmentUnitTest.php | 4 +--- 7 files changed, 9 insertions(+), 19 deletions(-) diff --git a/WordPress/AbstractFunctionRestrictionsSniff.php b/WordPress/AbstractFunctionRestrictionsSniff.php index ea2e50ae23..5b11af4dad 100644 --- a/WordPress/AbstractFunctionRestrictionsSniff.php +++ b/WordPress/AbstractFunctionRestrictionsSniff.php @@ -302,8 +302,6 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content $this->string_to_errorcode( $group_name . '_' . $matched_content ), array( $matched_content ) ); - - return; } /** diff --git a/WordPress/Sniffs/DB/PreparedSQLSniff.php b/WordPress/Sniffs/DB/PreparedSQLSniff.php index 1f8fa9b3bc..cb48f508ff 100644 --- a/WordPress/Sniffs/DB/PreparedSQLSniff.php +++ b/WordPress/Sniffs/DB/PreparedSQLSniff.php @@ -102,7 +102,7 @@ class PreparedSQLSniff extends Sniff { */ public function register() { - $this->ignored_tokens = $this->ignored_tokens + Tokens::$emptyTokens; + $this->ignored_tokens += Tokens::$emptyTokens; return array( \T_VARIABLE, diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 8c9f6a891d..2b39460432 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -114,7 +114,7 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { } // Merge any custom variables with the defaults. - $this->mergeWhiteList( $phpcs_file ); + $this->mergeWhiteList(); // Likewise if it is a mixed-case var used by WordPress core. if ( isset( $this->wordpress_mixed_case_vars[ $var_name ] ) ) { @@ -203,7 +203,7 @@ protected function processMemberVar( File $phpcs_file, $stack_ptr ) { } // Merge any custom variables with the defaults. - $this->mergeWhiteList( $phpcs_file ); + $this->mergeWhiteList(); $error_data = array( $var_name ); if ( ! isset( $this->whitelisted_mixed_case_member_var_names[ $var_name ] ) && false === self::isSnakeCase( $var_name ) ) { @@ -228,7 +228,7 @@ protected function processVariableInString( File $phpcs_file, $stack_ptr ) { if ( preg_match_all( '|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[ $stack_ptr ]['content'], $matches ) > 0 ) { // Merge any custom variables with the defaults. - $this->mergeWhiteList( $phpcs_file ); + $this->mergeWhiteList(); foreach ( $matches[1] as $var_name ) { // If it's a php reserved var, then its ok. @@ -265,12 +265,11 @@ public static function isSnakeCase( $var_name ) { * if we haven't already. * * @since 0.10.0 - * - * @param \PHP_CodeSniffer\Files\File $phpcs_file The file being scanned. + * @since 2.0.0 Removed unused $phpcs_file parameter. * * @return void */ - protected function mergeWhiteList( File $phpcs_file ) { + protected function mergeWhiteList() { if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] ) { // Fix property potentially passed as comma-delimited string. $customProperties = Sniff::merge_custom_array( $this->customPropertiesWhitelist, array(), false ); diff --git a/WordPress/Sniffs/PHP/TypeCastsSniff.php b/WordPress/Sniffs/PHP/TypeCastsSniff.php index 1d3c7663e9..47376ff39c 100644 --- a/WordPress/Sniffs/PHP/TypeCastsSniff.php +++ b/WordPress/Sniffs/PHP/TypeCastsSniff.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Sniffs\PHP; use WordPressCS\WordPress\Sniff; -use PHP_CodeSniffer\Util\Tokens; /** * Verifies the correct usage of type cast keywords. diff --git a/WordPress/Sniffs/Security/EscapeOutputSniff.php b/WordPress/Sniffs/Security/EscapeOutputSniff.php index a4dd060cb2..9a1feaa857 100644 --- a/WordPress/Sniffs/Security/EscapeOutputSniff.php +++ b/WordPress/Sniffs/Security/EscapeOutputSniff.php @@ -169,15 +169,13 @@ class EscapeOutputSniff extends Sniff { */ public function register() { - $tokens = array( + return array( \T_ECHO, \T_PRINT, \T_EXIT, \T_STRING, \T_OPEN_TAG_WITH_ECHO, ); - - return $tokens; } /** diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index 792d62c3e6..5891f54181 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -27,7 +27,7 @@ class ValidVariableNameUnitTest extends AbstractSniffUnitTest { * @return array => */ public function getErrorList() { - $errors = array( + return array( 2 => 1, 5 => 1, 8 => 1, @@ -74,8 +74,6 @@ public function getErrorList() { 145 => 1, 160 => 1, ); - - return $errors; } /** diff --git a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php index a928640dc3..1da0d8fbeb 100644 --- a/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php +++ b/WordPress/Tests/WhiteSpace/PrecisionAlignmentUnitTest.php @@ -84,7 +84,7 @@ public function getWarningList( $testFile = '' ) { ); case 'PrecisionAlignmentUnitTest.5.inc': - $warnings = array( + return array( 9 => 1, 14 => 1, 19 => 1, @@ -98,8 +98,6 @@ public function getWarningList( $testFile = '' ) { 58 => 1, ); - return $warnings; - case 'PrecisionAlignmentUnitTest.6.inc': return array( 4 => 1, From e0966832668c3f16f1ea0bab4bfc92d46bdc20d3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Dec 2018 16:34:58 +0100 Subject: [PATCH 56/64] DiscouragedConstants: make the error codes more modular This sniff is based on an array of constants the sniff looks for. Previously, the sniff had two distinct error codes for the different use-cases in which the constant could be found (use of vs declaration). This change makes the error codes unique to the constant found, making it easier to silence the error message(s) for just one particular constant. --- WordPress/Sniffs/WP/DiscouragedConstantsSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php index e55254b749..00e1e8efa8 100644 --- a/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php +++ b/WordPress/Sniffs/WP/DiscouragedConstantsSniff.php @@ -173,7 +173,7 @@ public function process_arbitrary_tstring( $stackPtr ) { $this->phpcsFile->addWarning( 'Found usage of constant "%s". Use %s instead.', $stackPtr, - 'UsageFound', + $this->string_to_errorcode( $content . 'UsageFound' ), array( $content, $this->discouraged_constants[ $content ], @@ -208,7 +208,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p $this->phpcsFile->addWarning( 'Found declaration of constant "%s". Use %s instead.', $stackPtr, - 'DeclarationFound', + $this->string_to_errorcode( $raw_content . 'DeclarationFound' ), array( $raw_content, $this->discouraged_constants[ $raw_content ], From a22db480799242deaf941bc16d6b4bf649422b7a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 22 Dec 2018 17:06:56 +0100 Subject: [PATCH 57/64] Contributing: update the documentation about installing and running the unit tests --- .github/CONTRIBUTING.md | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index babd323861..2a6e2d2496 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -49,16 +49,22 @@ When you introduce new `public` sniff properties, or your sniff extends a class * PHP_CodeSniffer 3.3.1 or higher * PHPUnit 4.x, 5.x, 6.x or 7.x -The WordPress Coding Standards use the PHP_CodeSniffer native unit test suite for unit testing the sniffs. +The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test suite for unit testing the sniffs. -Presuming you have installed PHP_CodeSniffer and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`. +Presuming you have installed `PHP_CodeSniffer` and the WordPress-Coding-Standards as [noted in the README](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#how-to-use-this), all you need now is `PHPUnit`. -N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` or run `composer install --prefer-source` now to make sure the unit tests are available. +> N.B.: If you installed WPCS using Composer, make sure you used `--prefer-source` or run `composer install --prefer-source` now to make sure the unit tests are available. +> Other than that, you're all set already as Composer will have installed PHPUnit for you. If you already have PHPUnit installed on your system: Congrats, you're all set. -If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies. -Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file. +## Installing PHPUnit + +N.B.: _If you used Composer to install the WordPress Coding Standards, you can skip this step._ + +You can either navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies or you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.4/installation.html) as a PHAR file. + +You may want to add the directory where PHPUnit is installed to a `PATH` environment variable for your operating system to make the command available everywhere on your system. ## Before running the unit tests @@ -66,7 +72,8 @@ N.B.: _If you used Composer to install the WordPress Coding Standards, you can s For the unit tests to work, you need to make sure PHPUnit can find your `PHP_CodeSniffer` install. -The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. Copy the existing `phpunit.xml.dist` file and add the below `` directive within the `` section. Make sure to adjust the path to reflect your local setup. +The easiest way to do this is to add a `phpunit.xml` file to the root of your WPCS installation and set a `PHPCS_DIR` environment variable from within this file. +Copy the existing `phpunit.xml.dist` file and add the below `` directive within the `` section. Make sure to adjust the path to reflect your local setup. ```xml @@ -75,7 +82,7 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your WP ## Running the unit tests -* Make sure you have registered the directory in which you installed WPCS with PHPCS using; +* If you didn't install WPCS using Composer, make sure you have registered the directory in which you installed WPCS with PHPCS using: ```sh phpcs --config-set installed_paths path/to/WPCS ``` @@ -95,13 +102,13 @@ PHPUnit 7.5.0 by Sebastian Bergmann and contributors. Runtime: PHP 7.2.13 Configuration: /WordPressCS/phpunit.xml -............................................................ 60 / 60 (100%) +........................................................ 56 / 56 (100%) -156 sniff test files generated 490 unique error codes; 59 were fixable (12.04%) +152 sniff test files generated 487 unique error codes; 52 were fixable (10.68%) -Time: 18.02 seconds, Memory: 22.00MB +Time: 21.36 seconds, Memory: 22.00MB -OK (60 tests, 0 assertions) +OK (56 tests, 0 assertions) ``` [![asciicast](https://asciinema.org/a/98078.png)](https://asciinema.org/a/98078) From 46e1a8ae68c0e0d308ece69e29c3dba549a7f159 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 03:57:29 +0100 Subject: [PATCH 58/64] ValidFunctionName: sync in fixes from upstream This adds similar fixes which were made to the upstream `PEAR` sniff to the WPCS native version of the sniff in as far applicable. * The `WordPress.NamingConventions.ValidFunctionName` sniff would throw the same error twice for functions in nested classes. The reasoning and solution used is the same as applied upstream. > Turns out the `processTokensWithinScope()` method gets called for each whitelisted scope a `T_FUNCTION` token exists in. > > In effect, this means that the first time it gets called for the `nestedFunction()` method, it is because it is within the scope of the `Nested` class, the second time the function gets called, it is for the method being in the scope of the anonymous class. > > The fix I've now applied checks that the scope for which the method is called is actually the deepest scope first and bows out if it's not. This fixes the error messages being thrown twice. * For methods in anonymous classes, the error message would read `Method name "nestedFunction" in class is not ....` (take note of the missing class name) which could be considered confusing. I've changed this to now read: `read `Method name "nestedFunction" in class [Anonymous class] is not ` * Class and method names in PHP are case _in_sensitive. While the sniff took that into account for the magic methods, it did not when checking for PHP4 style constructors/destructors. This has now been fixed by lowercasing both the class name as well as the function name before comparing them. Includes unit tests. --- .../ValidFunctionNameSniff.php | 33 +++++++++++++++---- .../ValidFunctionNameUnitTest.inc | 14 ++++++++ .../ValidFunctionNameUnitTest.php | 2 ++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 3ee7c2ab31..96db318d9f 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -22,7 +22,7 @@ * @since 0.1.0 * @since 0.13.0 Class name changed: this class is now namespaced. * - * Last synced with parent class July 2016 up to commit 4fea2e651109e41066a81e22e004d851fb1287f6. + * Last synced with parent class December 2018 up to commit ee167761d7756273b8ad0ad68bf3db1f2c211bb8. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php * * {@internal While this class extends the PEAR parent, it does not actually use the checks @@ -75,10 +75,12 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { return; } + $functionNameLc = strtolower( $functionName ); + // Is this a magic function ? I.e., it is prefixed with "__" ? // Outside class scope this basically just means __autoload(). if ( 0 === strpos( $functionName, '__' ) ) { - $magicPart = strtolower( substr( $functionName, 2 ) ); + $magicPart = substr( $functionNameLc, 2 ); if ( isset( $this->magicFunctions[ $magicPart ] ) ) { return; } @@ -88,7 +90,7 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { $phpcsFile->addError( $error, $stackPtr, 'FunctionDoubleUnderscore', $errorData ); } - if ( strtolower( $functionName ) !== $functionName ) { + if ( $functionNameLc !== $functionName ) { $error = 'Function name "%s" is not in snake case format, try "%s"'; $errorData = array( $functionName, @@ -109,6 +111,17 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { * @return void */ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope ) { + + $tokens = $phpcsFile->getTokens(); + + // Determine if this is a function which needs to be examined. + $conditions = $tokens[ $stackPtr ]['conditions']; + end( $conditions ); + $deepestScope = key( $conditions ); + if ( $deepestScope !== $currScope ) { + return; + } + $methodName = $phpcsFile->getDeclarationName( $stackPtr ); if ( ! isset( $methodName ) ) { @@ -117,6 +130,12 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco } $className = $phpcsFile->getDeclarationName( $currScope ); + if ( isset( $className ) === false ) { + $className = '[Anonymous Class]'; + } + + $methodNameLc = strtolower( $methodName ); + $classNameLc = strtolower( $className ); // Ignore special functions. if ( '' === ltrim( $methodName, '_' ) ) { @@ -124,12 +143,12 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco } // PHP4 constructors are allowed to break our rules. - if ( $methodName === $className ) { + if ( $methodNameLc === $classNameLc ) { return; } // PHP4 destructors are allowed to break our rules. - if ( '_' . $className === $methodName ) { + if ( '_' . $classNameLc === $methodNameLc ) { return; } @@ -143,7 +162,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco // Is this a magic method ? I.e. is it prefixed with "__" ? if ( 0 === strpos( $methodName, '__' ) ) { - $magicPart = strtolower( substr( $methodName, 2 ) ); + $magicPart = substr( $methodNameLc, 2 ); if ( isset( $this->magicMethods[ $magicPart ] ) || isset( $this->methodsDoubleUnderscore[ $magicPart ] ) ) { return; } @@ -154,7 +173,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco } // Check for all lowercase. - if ( strtolower( $methodName ) !== $methodName ) { + if ( $methodNameLc !== $methodName ) { $error = 'Method name "%s" in class %s is not in snake case format, try "%s"'; $errorData = array( $methodName, diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc index 228d4348d0..642fe78a80 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.inc @@ -109,3 +109,17 @@ function __MyTemplateTags() {} // Bad x 2. interface MyInterface extends InterfaceA, InterfaceB { function __MyTemplateTags(); // OK. } + +class Nested { + public function get_anonymous_class() { + return new class() { + public function nestedFunction() {} + protected function __something() {} + }; + } +} + +abstract class My_Class { + public function my_Class() {} + public function _MY_CLASS() {} +} diff --git a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php index dc239337bc..10649e220d 100644 --- a/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidFunctionNameUnitTest.php @@ -44,6 +44,8 @@ public function getErrorList() { 88 => 2, 89 => 2, 106 => 2, + 116 => 1, + 117 => 1, ); } From e7d544700b84c69598b57611e3ed955b57dfd3a5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 04:21:00 +0100 Subject: [PATCH 59/64] ValidFunctionName: remove redundant code As the "method name" check exist out if it finds an extended class or implemented interface anyway, checking the name of underscore magic methods which are only used in extended classes is redundant. --- .../ValidFunctionNameSniff.php | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 96db318d9f..298c14681d 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -30,29 +30,6 @@ */ class ValidFunctionNameSniff extends PHPCS_PEAR_ValidFunctionNameSniff { - /** - * Additional double underscore prefixed methods specific to certain PHP native extensions. - * - * Currently only handles the SoapClient Extension. - * - * @link http://php.net/manual/en/class.soapclient.php - * - * @var array => - */ - private $methodsDoubleUnderscore = array( - 'doRequest' => 'SoapClient', - 'getFunctions' => 'SoapClient', - 'getLastRequest' => 'SoapClient', - 'getLastRequestHeaders' => 'SoapClient', - 'getLastResponse' => 'SoapClient', - 'getLastResponseHeaders' => 'SoapClient', - 'getTypes' => 'SoapClient', - 'setCookie' => 'SoapClient', - 'setLocation' => 'SoapClient', - 'setSoapHeaders' => 'SoapClient', - 'soapCall' => 'SoapClient', - ); - /** * Processes the tokens outside the scope. * @@ -163,7 +140,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco // Is this a magic method ? I.e. is it prefixed with "__" ? if ( 0 === strpos( $methodName, '__' ) ) { $magicPart = substr( $methodNameLc, 2 ); - if ( isset( $this->magicMethods[ $magicPart ] ) || isset( $this->methodsDoubleUnderscore[ $magicPart ] ) ) { + if ( isset( $this->magicMethods[ $magicPart ] ) ) { return; } From 7a013b05604126b3ba67ca810bd269f0b411c54c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:39:54 +0100 Subject: [PATCH 60/64] ValidFunctionName: move `get_name_suggestion()` to the Sniff base class ... rename it to `get_snake_case_name_suggestion()` and make it a static method so it's also available to sniffs extending upstream sniffs. --- WordPress/Sniff.php | 19 +++++++++++++++++ .../ValidFunctionNameSniff.php | 21 +++++-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 245f7d8443..721e85ecba 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -942,6 +942,25 @@ protected function string_to_errorcode( $base_string ) { return preg_replace( '`[^a-z0-9_]`i', '_', $base_string ); } + /** + * Transform the name of a PHP construct (function, variable etc) to one in snake_case. + * + * @since 2.0.0 Moved from the `WordPress.NamingConventions.ValidFunctionName` sniff + * to this class, renamed from `get_name_suggestion` and made static + * so it can also be used by classes which don't extend this class. + * + * @param string $name The construct name. + * + * @return string + */ + public static function get_snake_case_name_suggestion( $name ) { + $suggested = preg_replace( '`([A-Z])`', '_$1', $name ); + $suggested = strtolower( $suggested ); + $suggested = str_replace( '__', '_', $suggested ); + $suggested = trim( $suggested, '_' ); + return $suggested; + } + /** * Merge a pre-set array with a ruleset provided array. * diff --git a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php index 298c14681d..645bed3d9d 100644 --- a/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -11,6 +11,7 @@ use PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions\ValidFunctionNameSniff as PHPCS_PEAR_ValidFunctionNameSniff; use PHP_CodeSniffer\Files\File; +use WordPressCS\WordPress\Sniff; /** * Enforces WordPress function name and method name format, based upon Squiz code. @@ -21,6 +22,8 @@ * * @since 0.1.0 * @since 0.13.0 Class name changed: this class is now namespaced. + * @since 2.0.0 The `get_name_suggestion()` method has been moved to the + * WordPress native `Sniff` base class as `get_snake_case_name_suggestion()`. * * Last synced with parent class December 2018 up to commit ee167761d7756273b8ad0ad68bf3db1f2c211bb8. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php @@ -71,7 +74,7 @@ protected function processTokenOutsideScope( File $phpcsFile, $stackPtr ) { $error = 'Function name "%s" is not in snake case format, try "%s"'; $errorData = array( $functionName, - $this->get_name_suggestion( $functionName ), + Sniff::get_snake_case_name_suggestion( $functionName ), ); $phpcsFile->addError( $error, $stackPtr, 'FunctionNameInvalid', $errorData ); } @@ -155,24 +158,10 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco $errorData = array( $methodName, $className, - $this->get_name_suggestion( $methodName ), + Sniff::get_snake_case_name_suggestion( $methodName ), ); $phpcsFile->addError( $error, $stackPtr, 'MethodNameInvalid', $errorData ); } } - /** - * Transform the existing function/method name to one which complies with the naming conventions. - * - * @param string $name The function/method name. - * @return string - */ - protected function get_name_suggestion( $name ) { - $suggested = preg_replace( '/([A-Z])/', '_$1', $name ); - $suggested = strtolower( $suggested ); - $suggested = str_replace( '__', '_', $suggested ); - $suggested = trim( $suggested, '_' ); - return $suggested; - } - } From ccae00cfc043fcc58025ae4388b644ed89d8b9e2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:54:30 +0100 Subject: [PATCH 61/64] ValidVariableName: adjust error messages and codes * Adjusts the error messages to include an alternative name suggestion in snake_case. * Adds back the previously stripped `$` to the variable name for the error message. * Adjusts the error messages the sniff throws to be more consistent. Fixes 1280 --- .../ValidVariableNameSniff.php | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 2b39460432..0b5cb047f3 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -23,7 +23,8 @@ * * @since 0.9.0 * @since 0.13.0 Class name changed: this class is now namespaced. - * @since 2.0.0 Defers to the upstream `$phpReservedVars` property. + * @since 2.0.0 - Defers to the upstream `$phpReservedVars` property. + * - Now offers name suggestions for variables in violation. * * Last synced with base class June 2018 at commit 78ddbae97cac078f09928bf89e3ab9e53ad2ace0. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -139,9 +140,12 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { } if ( ! isset( $this->whitelisted_mixed_case_member_var_names[ $obj_var_name ] ) && self::isSnakeCase( $obj_var_name ) === false ) { - $error = 'Object property "%s" is not in valid snake_case format'; - $data = array( $original_var_name ); - $phpcs_file->addError( $error, $var, 'NotSnakeCaseMemberVar', $data ); + $error = 'Object property "$%s" is not in valid snake_case format, try "$%s"'; + $data = array( + $original_var_name, + Sniff::get_snake_case_name_suggestion( $original_var_name ), + ); + $phpcs_file->addError( $error, $var, 'UsedPropertyNotSnakeCase', $data ); } } } @@ -165,15 +169,18 @@ protected function processVariable( File $phpcs_file, $stack_ptr ) { if ( self::isSnakeCase( $var_name ) === false ) { if ( $in_class && ! isset( $this->whitelisted_mixed_case_member_var_names[ $var_name ] ) ) { - $error = 'Object property "%s" is not in valid snake_case format'; - $error_name = 'NotSnakeCaseMemberVar'; + $error = 'Object property "$%s" is not in valid snake_case format, try "$%s"'; + $error_name = 'UsedPropertyNotSnakeCase'; } elseif ( ! $in_class ) { - $error = 'Variable "%s" is not in valid snake_case format'; - $error_name = 'NotSnakeCase'; + $error = 'Variable "$%s" is not in valid snake_case format, try "$%s"'; + $error_name = 'VariableNotSnakeCase'; } if ( isset( $error, $error_name ) ) { - $data = array( $original_var_name ); + $data = array( + $original_var_name, + Sniff::get_snake_case_name_suggestion( $original_var_name ), + ); $phpcs_file->addError( $error, $stack_ptr, $error_name, $data ); } } @@ -205,10 +212,13 @@ protected function processMemberVar( File $phpcs_file, $stack_ptr ) { // Merge any custom variables with the defaults. $this->mergeWhiteList(); - $error_data = array( $var_name ); if ( ! isset( $this->whitelisted_mixed_case_member_var_names[ $var_name ] ) && false === self::isSnakeCase( $var_name ) ) { - $error = 'Member variable "%s" is not in valid snake_case format.'; - $phpcs_file->addError( $error, $stack_ptr, 'MemberNotSnakeCase', $error_data ); + $error = 'Member variable "$%s" is not in valid snake_case format, try "$%s"'; + $data = array( + $var_name, + Sniff::get_snake_case_name_suggestion( $var_name ), + ); + $phpcs_file->addError( $error, $stack_ptr, 'PropertyNotSnakeCase', $data ); } } @@ -242,9 +252,12 @@ protected function processVariableInString( File $phpcs_file, $stack_ptr ) { } if ( false === self::isSnakeCase( $var_name ) ) { - $error = 'Variable "%s" is not in valid snake_case format'; - $data = array( $var_name ); - $phpcs_file->addError( $error, $stack_ptr, 'StringNotSnakeCase', $data ); + $error = 'Variable "$%s" is not in valid snake_case format, try "$%s"'; + $data = array( + $var_name, + Sniff::get_snake_case_name_suggestion( $var_name ), + ); + $phpcs_file->addError( $error, $stack_ptr, 'InterpolatedVariableNotSnakeCase', $data ); } } } From e5cc4b00730ab1c631b5b3aed575c0e316e0f0cf Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:56:33 +0100 Subject: [PATCH 62/64] ValidVariableName: minor tweaks Minor changes missed in PR 1586. * Update the class documentation. * Remove a, now unused, property array key. --- .../Sniffs/NamingConventions/ValidVariableNameSniff.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php index 0b5cb047f3..0b9422796a 100644 --- a/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/WordPress/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -28,8 +28,8 @@ * * Last synced with base class June 2018 at commit 78ddbae97cac078f09928bf89e3ab9e53ad2ace0. * @link https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php - * One change from upstream deferred till later (PHPCS 3.3.0+): - * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1048#issuecomment-364282100 + * + * @uses PHP_CodeSniffer\Sniffs\AbstractVariableSniff::$phpReservedVars */ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { @@ -92,7 +92,6 @@ class ValidVariableNameSniff extends PHPCS_AbstractVariableSniff { */ protected $addedCustomProperties = array( 'properties' => null, - 'variables' => null, ); /** From 56bcfd9683afa9de18696ff92f142743ef185bc4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Dec 2018 18:59:11 +0100 Subject: [PATCH 63/64] ValidVariableName: add some additional unit tests ... to confirm that the sniff handles multi-variable/property declarations correctly. (some of these would have failed prior to PHPCS 3.3.0) --- .../ValidVariableNameUnitTest.inc | 19 +++++++++++++++++++ .../ValidVariableNameUnitTest.php | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc index f510d74d57..0186491d75 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc @@ -167,3 +167,22 @@ echo ClassName $var_name2 // More sillyness. ['test']; + +class MultiVarDeclarations { + public $multiVar1, $multiVar2, // Bad x 2. + $multiVar3, // Bad. + // Some comment. + $multiVar4, // Bad. + $multiVar5 = false, // Bad. + $multiVar6 = 123, // Bad. + $multi_var7 = 'string'; // Ok. + + public function testMultiGlobalAndStatic() { + global $multiGlobal1, $multi_global2, // Bad x 1. + $multiGlobal3; // Bad. + + static $multiStatic1, $multi_static2 = false, // Bad x 1. + // Comment. + $multiStatic3 = ''; // Bad. + } +} diff --git a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php index 5891f54181..934826f5d4 100644 --- a/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -73,6 +73,15 @@ public function getErrorList() { 138 => 1, 145 => 1, 160 => 1, + 172 => 2, + 173 => 1, + 175 => 1, + 176 => 1, + 177 => 1, + 181 => 1, + 182 => 1, + 184 => 1, + 186 => 1, ); } From 9b17fe2e52facdf77d1766605855ca1ad4085cfa Mon Sep 17 00:00:00 2001 From: Juliette <663378+jrfnl@users.noreply.github.com> Date: Sun, 30 Dec 2018 19:16:01 +0100 Subject: [PATCH 64/64] Changelog for WPCS version 2.0.0-RC1 (#1610) Changelog for WPCS version 2.0.0-RC1 * Release date set at this Monday December 31.. * Includes all currently merged changes. --- CHANGELOG.md | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97a14f7ab8..5413967824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,150 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ +## [2.0.0-RC1] - 2018-12-31 + +### Important information about this release: + +This is the first release candidate for WordPressCS 2.0.0. +WordPressCS 2.0.0 contains breaking changes, both for people using custom rulesets as well as for sniff developers who maintain a custom PHPCS standard based on WordPressCS. + +Support for `PHP_CodeSniffer` 2.x has been dropped, the new minimum `PHP_CodeSniffer` version is 3.3.1. +Also, all previously deprecated sniffs, properties and methods have been removed. + +Please read the complete changelog carefully before you upgrade. + +If you are a maintainer of an external standard based on WordPressCS and any of your custom sniffs are based on or extend WPCS sniffs, please read the [Developers Upgrade Guide to WordPressCS 2.0.0](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Upgrade-Guide-to-WordPressCS-2.0.0-for-Developers-of-external-standards). + +### Added +- `Generic.PHP.DiscourageGoto`, `Generic.PHP.LowerCaseType`, `Generic.WhiteSpace.ArbitraryParenthesesSpacing` and `PSR12.Keywords.ShortFormTypeKeywords` to the `WordPress-Core` ruleset. +- Checking the spacing around the `instanceof` operator to the `WordPress.WhiteSpace.OperatorSpacing` sniff. + +### Changed +- The minimum required `PHP_CodeSniffer` version to 3.3.1 (was 2.9.0). +- The namespace used by WordPressCS has been changed from `WordPress` to `WordPressCS\WordPress`. + This was not possible while `PHP_CodeSniffer` 2.x was still supported, but WordPressCS, as a good Open Source citizen, does not want to occupy the `WordPress` namespace and is releasing its use of it now this is viable. +- The `WordPress.DB.PreparedSQL` sniff used the same error code for two different errors. + The `NotPrepared` error code remains, however an additional `InterpolatedNotPrepared` error code has been added for the second error. + If you are referencing the old error code in a ruleset XML file or in inline annotations, you may need to update it. +- The `WordPress.NamingConventions.PrefixAllGlobals` sniff used the same error code for some errors as well as warnings. + The `NonPrefixedConstantFound` error code remains for the related error, but the warning will now use the new `VariableConstantNameFound` error code. + The `NonPrefixedHooknameFound` error code remains for the related error, but the warning will now use the new `DynamicHooknameFound` error code. + If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. +- `WordPress.NamingConventions.ValidVariableName`: the error messages and error codes used by this sniff have been changed for improved usability and consistency. + - The error messages will now show a suggestion for a valid alternative name for the variable. + - The `NotSnakeCaseMemberVar` error code has been renamed to `UsedPropertyNotSnakeCase`. + - The `NotSnakeCase` error code has been renamed to `VariableNotSnakeCase`. + - The `MemberNotSnakeCase` error code has been renamed to `PropertyNotSnakeCase`. + - The `StringNotSnakeCase` error code has been renamed to `InterpolatedVariableNotSnakeCase`. + If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. +- The `WordPress.Security.NonceVerification` sniff used the same error code for both an error as well as a warning. + The old error code `NoNonceVerification` is no longer used. + The `error` now uses the `Missing` error code, while the `warning` now uses the `Recommended` error code. + If you are referencing the old error code in a ruleset XML file or in inline annotations, please update these to use the new codes instead. +- The `WordPress.WP.DiscouragedConstants` sniff used to have two error codes `UsageFound` and `DeclarationFound`. + These error codes will now be prefixed by the name of the constant found to allow for more fine-grained excluding/ignoring of warnings generated by this sniff. + If you are referencing the old error codes in a ruleset XML file or in inline annotations, you may need to update these to use the new codes instead. +- The `WordPress.WP.GlobalVariablesOverride.OverrideProhibited` error code has been replaced by the `WordPress.WP.GlobalVariablesOverride.Prohibited` error code. + If you are referencing the old error code in a ruleset XML file or in inline annotations, you may need to update it. +- `WordPress-Extra`: Replaced the inclusion of the `Generic.Files.OneClassPerFile`, `Generic.Files.OneInterfacePerFile` and the `Generic.Files.OneTraitPerFile` sniffs with the new `Generic.Files.OneObjectStructurePerFile` sniff. +- `WordPress-Extra`: Replaced the inclusion of the `Squiz.WhiteSpace.LanguageConstructSpacing` sniff with the new `Generic.WhiteSpace.LanguageConstructSpacing` sniff. +- `WordPress-Extra`: Replaced the inclusion of the `Squiz.Scope.MemberVarScope` sniff with the more comprehensive `PSR2.Classes.PropertyDeclaration` sniff. +- `WordPress.NamingConventions.ValidFunctionName`: Added a unit test confirming support for interfaces extending multiple interfaces. +- `WordPress.NamingConventions.ValidVariableName`: Added unit tests confirming support for multi-variable/property declarations. +- The `get_name_suggestion()` method has been moved from the `WordPress.NamingConventions.ValidFunctionName` sniff to the base `Sniff` class, renamed to `get_snake_case_name_suggestion()` and made static. +- The rulesets are now validated against the `PHP_CodeSniffer` XSD schema. +- Updated the [custom ruleset example](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) to use the recommended ruleset syntax for `PHP_CodeSniffer` 3.3.1+, including using the new [array property format](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0) which is now supported. +- Dev: The command to run the unit tests has changed. Please see the updated instructions in the [CONTRIBUTING.md](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/.github/CONTRIBUTING.md) file. + The `bin/pre-commit` example git hook has been updated to match. Additionally a `run-tests` script has been added to the `composer.json` file for your convenience. + To facilitate this, PHPUnit has been added to `require-dev`, even though it is strictly speaking a dependency of PHPCS, not of WPCS. +- Dev: The DealerDirect PHPCS Composer plugin has been added to `require-dev`. +- Various code tweaks and clean up. +- User facing documentation, including the wiki, as well as inline documentation has been updated for all the changes contained in WordPressCS 2.0 and other recommended best practices for `PHP_CodeSniffer` 3.3.1+. + +### Deprecated +- The use of the [WordPressCS native whitelist comments](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Whitelisting-code-which-flags-errors), which were introduced in WPCS 0.4.0, have been deprecated and support will be removed in WPCS 3.0.0. + The WordPressCS native whitelist comments will continue to work for now, but a deprecation warning will be thrown when they are encountered. + You are encouraged to upgrade our whitelist comment to use the [PHPCS native selective ignore annotations}(https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.2.0) as introduced in `PHP_CodeSniffer` 3.2.0, as soon as possible. + +### Removed +- Support for PHP 5.3. PHP 5.4 is the minimum requirement for `PHP_CodeSniffer` 3.x. + Includes removing any and all workarounds which were in place to still support PHP 5.3. +- Support for `PHP_CodeSniffer` < 3.3.1. + Includes removing any and all workarounds which were in place for supporting older `PHP_CodeSniffer` versions. +- The `WordPress-VIP` standard which was deprecated since WordPressCS 1.0.0. + For checking a theme/plugin for hosting on the WordPress.com VIP platform, please use the [Automattic VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) instead. +- Support for array properties set in a custom ruleset without the `type="array"` attribute. + Support for this was deprecated in WPCS 1.0.0. + If in doubt about how properties should be set in your custom ruleset, please refer to the [Customizable sniff properties](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties) wiki page which contains XML code examples for setting each and every WPCS native sniff property. + As the minimum `PHP_CodeSniffer` version is now 3.3.1, you can now also use the [new format for setting array properties](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.3.0), so this would be a great moment to review and update your custom ruleset. + Note: the ability to set select properties from the command-line as comma-delimited strings is _not_ affected by this change. +- The following sniffs have been removed outright without deprecation. + If you are referencing these sniffs in a ruleset XML file or in inline annotations, please update these to reference the replacement sniffs instead. + - `WordPress.Functions.FunctionCallSignatureNoParams` - superseded by a bug fix in the upstream `PEAR.Functions.FunctionCallSignature` sniff. + - `WordPress.PHP.DiscourageGoto` - replaced by the same sniff which is now available upstream: `Generic.PHP.DiscourageGoto`. + - `WordPress.WhiteSpace.SemicolonSpacing` - superseded by a bug fix in the upstream `Squiz.WhiteSpace.SemicolonSpacing` sniff. + - `WordPress.WhiteSpace.ArbitraryParenthesesSpacing` - replaced by the same sniff which is now available upstream: `Generic.WhiteSpace.ArbitraryParenthesesSpacing`. +- The following "base" sniffs which were previously already deprecated and turned into abstract base classes, have been removed: + - `WordPress.Arrays.ArrayAssignmentRestrictions` - use the `AbstractArrayAssignmentRestrictionsSniff` class instead. + - `WordPress.Functions.FunctionRestrictions` - use the `AbstractFunctionRestrictionsSniff` class instead. + - `WordPress.Variables.VariableRestrictions` without replacement. +- The following sniffs which were previously deprecated, have been removed: + - `WordPress.Arrays.ArrayDeclaration` - use the other sniffs in the `WordPress.Arrays` category instead. + - `WordPress.CSRF.NonceVerification` - use `WordPress.Security.NonceVerification` instead. + - `WordPress.Functions.DontExtract` - use `WordPress.PHP.DontExtract` instead. + - `WordPress.Variables.GlobalVariables` - use `WordPress.WP.GlobalVariablesOverride` instead. + - `WordPress.VIP.CronInterval` - use `WordPress.WP.CronInterval` instead. + - `WordPress.VIP.DirectDatabaseQuery` - use `WordPress.DB.DirectDatabaseQuery` instead. + - `WordPress.VIP.PluginMenuSlug` - use `WordPress.Security.PluginMenuSlug` instead. + - `WordPress.VIP.SlowDBQuery` - use `WordPress.DB.SlowDBQuery` instead. + - `WordPress.VIP.TimezoneChange` - use `WordPress.WP.TimezoneChange` instead. + - `WordPress.VIP.ValidatedSanitizedInput` - use `WordPress.Security.ValidatedSanitizedInput` instead. + - `WordPress.WP.PreparedSQL` - use `WordPress.DB.PreparedSQL` instead. + - `WordPress.XSS.EscapeOutput` - use `WordPress.Security.EscapeOutput` instead. + - `WordPress.PHP.DiscouragedFunctions` without direct replacement. + The checks previously contained in this sniff were moved to separate sniffs in WPCS 0.11.0. + - `WordPress.Variables.VariableRestrictions` without replacement. + - `WordPress.VIP.AdminBarRemoval` without replacement. + - `WordPress.VIP.FileSystemWritesDisallow` without replacement. + - `WordPress.VIP.OrderByRand` without replacement. + - `WordPress.VIP.PostsPerPage` without replacement. + Part of the previous functionality was split off in WPCS 1.0.0 to the `WordPress.WP.PostsPerPage` sniff. + - `WordPress.VIP.RestrictedFunctions` without replacement. + - `WordPress.VIP.RestrictedVariables` without replacement. + - `WordPress.VIP.SessionFunctionsUsage` without replacement. + - `WordPress.VIP.SessionVariableUsage` without replacement. + - `WordPress.VIP.SuperGlobalInputUsage` without replacement. +- The `WordPress.DB.SlowDBQuery.DeprecatedWhitelistFlagFound` error code which is superseded by the blanket deprecation warning for using the now deprecated WPCS native whitelist comments. +- The `WordPress.PHP.TypeCasts.NonLowercaseFound` error code which has been replaced by the upstream `Generic.PHP.LowerCaseType` sniff. +- The `WordPress.PHP.TypeCasts.LongBoolFound` and `WordPress.PHP.TypeCasts.LongIntFound` error codes which has been replaced by the new upstream `PSR12.Keywords.ShortFormTypeKeywords` sniff. +- The `WordPress.Security.EscapeOutput.OutputNotEscapedShortEcho` error code which was only ever used if WPCS was run on PHP 5.3 with the `short_open_tag` ini directive set to `off`. +- The following sniff categories which were previously deprecated, have been removed, though select categories may be reinstated in the future: + - `CSRF` + - `Functions` + - `Variables` + - `VIP` + - `XSS` +- `WordPress.NamingConventions.ValidVariableName`: The `customVariableWhitelist` property, which had been deprecated since WordPressCS 0.11.0. Use the `customPropertiesWhitelist` property instead. +- `WordPress.Security.EscapeOutput`: The `customSanitizingFunctions` property, which had been deprecated since WordPressCS 0.5.0. Use the `customEscapingFunctions` property instead. +- `WordPress.Security.NonceVerification`: The `errorForSuperGlobals` and `warnForSuperGlobals` properties, which had been deprecated since WordPressCS 0.12.0. +- The `vip_powered_wpcom` function from the `Sniff::$autoEscapedFunctions` list which is used by the `WordPress.Security.EscapeOutput` sniff. +- The `AbstractVariableRestrictionsSniff` class, which was deprecated since WordPressCS 1.0.0. +- The `Sniff::has_html_open_tag()` utility method, which was deprecated since WordPressCS 1.0.0. +- The internal `$php_reserved_vars` property from the `WordPress.NamingConventions.ValidVariableName` sniff in favour of using a PHPCS native property which is now available. +- The class aliases and WPCS native autoloader used for PHPCS cross-version support. +- The unit test framework workarounds for PHPCS cross-version unit testing. +- Support for the `@codingStandardsChangeSetting` annotation, which is generally only used in unit tests. +- The old generic GitHub issue template which was replaced by more specific issue templates in WPCS 1.2.0. + +### Fixed +- Support for PHP 7.3. + `PHP_CodeSniffer` < 3.3.1 was not fully compatible with PHP 7.3. Now the minimum required PHPCS has been upped to `PHP_CodeSniffer` 3.3.1, WordPressCS will run on PHP 7.3 without issue. +- `WordPress.Arrays.ArrayDeclarationSpacing`: improved fixing of the placement of array items following an array item with a trailing multi-line comment. +- `WordPress.NamingConventions.ValidFunctionName`: the sniff will no longer throw false positives nor duplicate errors for methods declared in nested anonymous classes. + The error message has also been improved for methods in anonymous classes. +- `WordPress.NamingConventions.ValidFunctionName`: the sniff will no longer throw false positives for PHP 4-style class constructors/destructors where the name of the constructor/destructor method did not use the same case as the class name. + + ## [1.2.1] - 2018-12-18 Note: This will be the last release supporting PHP_CodeSniffer 2.x. @@ -826,6 +970,7 @@ See the comparison for full list. Initial tagged release. [Unreleased]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/master...HEAD +[2.0.0-RC1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.1...2.0.0-RC1 [1.2.1]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.2.0...1.2.1 [1.2.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.1.0...1.2.0 [1.1.0]: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/compare/1.0.0...1.1.0