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 @@ - - - - - - - - - - - +