diff --git a/.travis.yml b/.travis.yml index 45e958eb..9707c948 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,16 +24,23 @@ script: # Run ruleset tests. - ./bin/ruleset-tests +env: + # `master` is now 3.x. + - PHPCS_BRANCH="dev-master" + # Lowest supported release in the 3.x series with which VIPCS is compatible. + - PHPCS_BRANCH="3.3.1" + +php: + - 5.6 + - 7.0 + - 7.1 + - 7.2 + - 7.3 + - "7.4snapshot" + # Rather than a `matrix` property, we use build stages. This allows early # build failure for basic linting and sniffing issues. # @link https://docs.travis-ci.com/user/build-stages/ -# -# PHP >= 7.3 & PHPCS < 3.3.1 is known to fail. -# @link https://github.com/squizlabs/PHP_CodeSniffer/issues/2086. -# -# We can't use Matrix Expansion here, since we need to exclude jobs for the known failures, -# which Matrix Expansion does not yet support. We list each combination instead. -# @link https://docs.travis-ci.com/user/conditional-builds-stages-jobs/#conditional-jobs stages: - lint @@ -43,11 +50,10 @@ stages: jobs: allow_failures: - php: "7.4snapshot" - fast_finish: true include: - stage: lint - php: 7.2 + php: 7.3 env: PHPCS_BRANCH="dev-master" before_install: phpenv config-rm xdebug.ini || echo 'No xdebug config.' install: false @@ -70,7 +76,7 @@ jobs: - libxml2-utils - stage: sniff - php: 7.2 + php: 7.3 env: PHPCS_BRANCH="dev-master" before_install: phpenv config-rm xdebug.ini || echo 'No xdebug config.' install: composer install --dev --no-suggest @@ -78,44 +84,4 @@ jobs: # Run PHPCS against VIPCS. - ./bin/phpcs - # PHPCS 3.2.3 is the lowest supported release - - stage: test - php: 5.6 - env: PHPCS_BRANCH="dev-master" - - - stage: test - php: 5.6 - env: PHPCS_BRANCH="3.2.3" - - - stage: test - php: 7.0 - env: PHPCS_BRANCH="dev-master" - - - stage: test - php: 7.0 - env: PHPCS_BRANCH="3.2.3" - - - stage: test - php: 7.1 - env: PHPCS_BRANCH="dev-master" - - - stage: test - php: 7.1 - env: PHPCS_BRANCH="3.2.3" - - - stage: test - php: 7.2 - env: PHPCS_BRANCH="dev-master" - - - stage: test - php: 7.2 - env: PHPCS_BRANCH="3.2.3" - # Only use PHPCS_BRANCH="dev-master" from this point, because PHPCS 3.3.1+ is needed to support PHP 7.3+ - - stage: test - php: 7.3 - env: PHPCS_BRANCH="dev-master" - - - stage: test - php: "7.4snapshot" - env: PHPCS_BRANCH="dev-master" diff --git a/README.md b/README.md index 14ce48fb..a80d9eb1 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,42 @@ -# VIP-Coding-Standards +# VIP Coding Standards -This project maintains the minimum ruleset of [PHP_CodeSniffer rules](https://github.com/squizlabs/PHP_CodeSniffer) (sniffs) to validate code developed for [WordPress.com VIP](https://wpvip.com/). +This project contains [PHP_CodeSniffer (PHPCS) sniffs and rulesets](https://github.com/squizlabs/PHP_CodeSniffer) to validate code developed for [WordPress.com VIP](https://wpvip.com/). -This project contains 2 PHP Codesniffer rulesets: +This project contains two rulesets: - - `WordPressVIPMinimum` - for use on WordPress.com projects - - `WordPress-VIP-Go` - for use on VIP Go projects + - `WordPressVIPMinimum` - for use with projects on the (older) WordPress.com VIP platform. + - `WordPress-VIP-Go` - for use with projects on the (newer) VIP Go platform. -These rulesets contain only the rules which are considered being "blockers" and "warnings" according to the [WordPress VIP Go documentation](https://wpvip.com/documentation/vip-go/code-review-blockers-warnings-notices/) +These rulesets contain only the rules which are considered to be "errors" and "warnings" according to the [WordPress VIP Go documentation](https://wpvip.com/documentation/vip-go/code-review-blockers-warnings-notices/) -The ruleset takes advantage of existing rules in the [WordPress-Coding-Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) project. +The rulesets use rules from the [WordPress-Coding-Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) (WPCS) project. -Go to https://wpvip.com/documentation/phpcs-review-feedback/ to learn about why various things are flagged as errors vs warnings and what the levels mean for us. +Go to https://wpvip.com/documentation/phpcs-review-feedback/ to learn about why violations are flagged as errors vs warnings and what the levels mean. -## Installation +## Minimal requirements -### Note +* [PHPCS 3.3.1+](https://github.com/squizlabs/PHP_CodeSniffer/releases) +* [WPCS 2.*](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases) -Currently, the VIP Go Coding Standards are built on top of the WordPress Coding Standards 1.* release. If you are using `master` here, you will need to checkout [1.2.1 tag](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases/tag/1.2.1). +## Installation -First, make sure you have WPCS 1.* and PHPCS v3+ installed. If you do not, please refer to the [installation instructions for installing PHP CodeSniffer for WordPress.com VIP](https://vip.wordpress.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/). Note that VIPCS does not currently work with the `develop` or `master` branch of WPCS. +`composer require automattic/vipwpcs`, or `composer g require automattic/vipwpcs` if installing globally. -You will also find additional information at the [WordPress Coding Standards for PHP_CodeSniffer project](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#installation). +This will install the latest compatible versions of PHPCS and WPCS. -Then, clone this repo to your local machine, and add the standard to PHPCodeSniffer by appending the folder you cloned into to the end of the installed paths. e.g. -`phpcs --config-set installed_paths [/path/to/wpcsstandard],[path/to/vipcsstandard],etc` +Please refer to the [installation instructions for installing PHP_CodeSniffer for WordPress.com VIP](https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/) for more details. -Alternatively, we recommend the [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer), which handles the registration of all of the installed standards, so there is no need to set the `installed_paths` config value manually, for single or multiple standards. +We recommend the [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer), which handles the registration of all of the installed standards, so there is no need to set the `installed_paths` config value manually, for single or multiple standards. -### Minimal requirements +Alternatively, you should register the standard to PHPCS by appending the VIPCS directory to the end of the installed paths. e.g. -* [PHPCS 3+](https://github.com/squizlabs/PHP_CodeSniffer/releases) -* [WPCS 1.*](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases) +`phpcs --config-set installed_paths [/path/to/wpcsstandard],[path/to/vipcsstandard],etc` -### Setup note +## Contribution -Should you wish to run both standards (WordPress.com VIP minimum standard & WordPress.com VIP coding standard), you can add both to PHPCS by running the following configuration command: +Please see [CONTRIBUTION.md](CONTRIBUTING.md). -`phpcs --config-set installed_paths [/path/to/standard],[path/to/standard]` +## License -Note the comma separating each standard. +Licensed under [GPL-2.0-or-later](LICENSE.md). diff --git a/WordPress-VIP-Go/ruleset-test.inc b/WordPress-VIP-Go/ruleset-test.inc index 6bfcff69..a3fcd0d4 100644 --- a/WordPress-VIP-Go/ruleset-test.inc +++ b/WordPress-VIP-Go/ruleset-test.inc @@ -69,7 +69,7 @@ wpcom_vip_file_get_contents( $bar ); // Ok. // WordPress.Security.NonceVerification.NoNonceVerification function bar_foo() { - if ( ! isset( $_POST['test'] ) ) { // Warning. + if ( ! isset( $_POST['test'] ) ) { // Error. return; } } @@ -80,7 +80,7 @@ function foo_bar() { } // WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -do_something( $_POST ); // Ok. +do_something( $_POST ); // Error. if ( isset( $_POST['foo2'] ) ) { bar( wp_unslash( $_POST['foo2'] ) ); // Warning. } @@ -473,7 +473,7 @@ $args = array( ); $query_args['orderby'] = 'rand'; // Error. -// WordPressVIPMinimum.Performance.RegexpCompare +// WordPressVIPMinimum.Performance.RegexpCompare $query_args = array( 'posts_per_page' => 1, 'post_status' => 'draft', diff --git a/WordPress-VIP-Go/ruleset-test.php b/WordPress-VIP-Go/ruleset-test.php index 6b3e476d..07a58740 100644 --- a/WordPress-VIP-Go/ruleset-test.php +++ b/WordPress-VIP-Go/ruleset-test.php @@ -36,6 +36,8 @@ 60 => 1, 63 => 1, 66 => 1, + 72 => 1, + 83 => 1, 165 => 1, 180 => 1, 181 => 1, @@ -162,7 +164,6 @@ 575 => 1, ], 'warnings' => [ - 72 => 1, 85 => 1, 90 => 1, 94 => 1, diff --git a/WordPressVIPMinimum/PHPCSCompatibility.php b/WordPressVIPMinimum/PHPCSCompatibility.php deleted file mode 100644 index 0d7ba46c..00000000 --- a/WordPressVIPMinimum/PHPCSCompatibility.php +++ /dev/null @@ -1,27 +0,0 @@ - $details ) { - if ( 'WordPress' === $standard ) { - require_once $details['path'] . '/PHPCSAliases.php'; - return; - } - } -} - -load_phpcs_helper_file(); - diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index 40e6f17c..ca8fd808 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -22,14 +22,14 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff { * * @var string */ - private $_currentClass = ''; + private $currentClass = ''; /** * A list of functions in the current class. * * @var string[] */ - private $_functionList = []; + private $functionList = []; /** * A list of classes and methods to check. @@ -204,9 +204,9 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco $className = $phpcsFile->getDeclarationName( $currScope ); - if ( $className !== $this->_currentClass ) { + if ( $className !== $this->currentClass ) { $this->loadFunctionNamesInScope( $phpcsFile, $currScope ); - $this->_currentClass = $className; + $this->currentClass = $className; } $methodName = $phpcsFile->getDeclarationName( $stackPtr ); @@ -300,7 +300,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco */ private function addError( $parentClassName, $methodName, $currentMethodSignature, $parentMethodSignature, $phpcsFile, $stackPtr ) { - $currentSignature = sprintf( '%s::%s(%s)', $this->_currentClass, $methodName, implode( ', ', $this->generateParamList( $currentMethodSignature ) ) ); + $currentSignature = sprintf( '%s::%s(%s)', $this->currentClass, $methodName, implode( ', ', $this->generateParamList( $currentMethodSignature ) ) ); $parentSignature = sprintf( '%s::%s(%s)', $parentClassName, $methodName, implode( ', ', $this->generateParamList( $parentMethodSignature ) ) ); @@ -354,16 +354,16 @@ private function generateParamList( $methodSignature ) { * @return void */ protected function loadFunctionNamesInScope( File $phpcsFile, $currScope ) { - $this->_functionList = []; - $tokens = $phpcsFile->getTokens(); + $this->functionList = []; + $tokens = $phpcsFile->getTokens(); for ( $i = ( $tokens[ $currScope ]['scope_opener'] + 1 ); $i < $tokens[ $currScope ]['scope_closer']; $i++ ) { if ( T_FUNCTION !== $tokens[ $i ]['code'] ) { continue; } - $next = $phpcsFile->findNext( T_STRING, $i ); - $this->_functionList[] = trim( $tokens[ $next ]['content'] ); + $next = $phpcsFile->findNext( T_STRING, $i ); + $this->functionList[] = trim( $tokens[ $next ]['content'] ); } } diff --git a/WordPressVIPMinimum/Sniffs/Classes/RestrictedExtendClassesSniff.php b/WordPressVIPMinimum/Sniffs/Classes/RestrictedExtendClassesSniff.php index 28adbb89..92bd9f9e 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/RestrictedExtendClassesSniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/RestrictedExtendClassesSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Classes; -use WordPress\AbstractClassRestrictionsSniff; +use WordPressCS\WordPress\AbstractClassRestrictionsSniff; /** * WordPressVIPMinimum_Sniffs_Classes_RestrictedExtendClassesSniff. diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index 95247d9e..2b6efd09 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Files; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; use PHP_CodeSniffer\Util\Tokens; /** diff --git a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php index 4c59f0dc..af8fd7cb 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php @@ -7,7 +7,6 @@ namespace WordPressVIPMinimum\Sniffs\Functions; -use PHP_CodeSniffer\Files\File; use WordPressVIPMinimum\Sniffs\Sniff; use PHP_CodeSniffer\Util\Tokens; @@ -22,13 +21,6 @@ */ class CheckReturnValueSniff extends Sniff { - /** - * Tokens of the whole file. - * - * @var array - */ - private $_tokens = []; - /** * Pairs we are about to check. * diff --git a/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php index 13a008cd..05318571 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php @@ -31,7 +31,7 @@ class DynamicCallsSniff extends Sniff { * * @var array */ - private $_blacklisted_functions = [ + private $blacklisted_functions = [ 'assert', 'compact', 'extract', @@ -49,14 +49,14 @@ class DynamicCallsSniff extends Sniff { * * @var array */ - private $_variables_arr = []; + private $variables_arr = []; /** * The position in the stack where the token was found. * * @var int */ - private $_stackPtr; + private $stackPtr; /** * Returns the token types that this sniff is interested in. @@ -77,7 +77,7 @@ public function register() { * @return void */ public function process_token( $stackPtr ) { - $this->_stackPtr = $stackPtr; + $this->stackPtr = $stackPtr; // First collect all variables encountered and their values. $this->collect_variables(); @@ -101,13 +101,13 @@ private function collect_variables() { if ( 'T_VARIABLE' !== - $this->tokens[ $this->_stackPtr ]['type'] + $this->tokens[ $this->stackPtr ]['type'] ) { return; } $current_var_name = $this->tokens[ - $this->_stackPtr + $this->stackPtr ]['content']; /* @@ -118,7 +118,7 @@ private function collect_variables() { $t_item_key = $this->phpcsFile->findNext( [ T_WHITESPACE ], - $this->_stackPtr + 1, + $this->stackPtr + 1, null, true, null, @@ -162,7 +162,7 @@ private function collect_variables() { $current_var_value = $this->tokens[ $t_item_key ]['content']; - $this->_variables_arr[ $current_var_name ] = + $this->variables_arr[ $current_var_name ] = str_replace( "'", '', $current_var_value ); } @@ -179,7 +179,7 @@ private function find_dynamic_calls() { * anything */ - if ( empty( $this->_variables_arr ) ) { + if ( empty( $this->variables_arr ) ) { return; } @@ -189,7 +189,7 @@ private function find_dynamic_calls() { if ( 'T_VARIABLE' !== - $this->tokens[ $this->_stackPtr ]['type'] + $this->tokens[ $this->stackPtr ]['type'] ) { return; } @@ -202,8 +202,8 @@ private function find_dynamic_calls() { */ if ( ! isset( - $this->_variables_arr[ - $this->tokens[ $this->_stackPtr ]['content'] + $this->variables_arr[ + $this->tokens[ $this->stackPtr ]['content'] ] ) ) { return; @@ -221,20 +221,20 @@ private function find_dynamic_calls() { } while ( 'T_WHITESPACE' === $this->tokens[ - $this->_stackPtr + $i + $this->stackPtr + $i ]['type'] ); if ( 'T_OPEN_PARENTHESIS' !== $this->tokens[ - $this->_stackPtr + $i + $this->stackPtr + $i ]['type'] ) { return; } - $t_item_key = $this->_stackPtr + $i; + $t_item_key = $this->stackPtr + $i; /* * We have a variable match, but make sure it contains name @@ -242,10 +242,10 @@ private function find_dynamic_calls() { */ if ( ! in_array( - $this->_variables_arr[ - $this->tokens[ $this->_stackPtr ]['content'] + $this->variables_arr[ + $this->tokens[ $this->stackPtr ]['content'] ], - $this->_blacklisted_functions, + $this->blacklisted_functions, true ) ) { return; @@ -253,7 +253,7 @@ private function find_dynamic_calls() { // We do, so report. $message = 'Dynamic calling is not recommended in the case of %s.'; - $data = [ $this->_variables_arr[ $this->tokens[ $this->_stackPtr ]['content'] ] ]; + $data = [ $this->variables_arr[ $this->tokens[ $this->stackPtr ]['content'] ] ]; $this->phpcsFile->addError( $message, $t_item_key, 'DynamicCalls', $data ); } } diff --git a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php index 71d5ff1d..658af707 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Functions; -use WordPress\AbstractFunctionRestrictionsSniff; +use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; use PHP_CodeSniffer\Util\Tokens; /** diff --git a/WordPressVIPMinimum/Sniffs/Functions/StripTagsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/StripTagsSniff.php index 656d0f2a..40b4094e 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/StripTagsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/StripTagsSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Functions; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * This sniff ensures proper tag stripping. diff --git a/WordPressVIPMinimum/Sniffs/Hooks/RestrictedHooksSniff.php b/WordPressVIPMinimum/Sniffs/Hooks/RestrictedHooksSniff.php index 5b447ef1..ff340ebb 100644 --- a/WordPressVIPMinimum/Sniffs/Hooks/RestrictedHooksSniff.php +++ b/WordPressVIPMinimum/Sniffs/Hooks/RestrictedHooksSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Hooks; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * This sniff restricts usage of some action and filter hooks. diff --git a/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php b/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php index 83dcef36..20ae980f 100644 --- a/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php +++ b/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Performance; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * This sniff throws a warning when low cache times are set. diff --git a/WordPressVIPMinimum/Sniffs/Performance/NoPagingSniff.php b/WordPressVIPMinimum/Sniffs/Performance/NoPagingSniff.php index 8a04ce10..fbeffa51 100644 --- a/WordPressVIPMinimum/Sniffs/Performance/NoPagingSniff.php +++ b/WordPressVIPMinimum/Sniffs/Performance/NoPagingSniff.php @@ -9,7 +9,7 @@ namespace WordPressVIPMinimum\Sniffs\Performance; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag returning high or infinite posts_per_page. diff --git a/WordPressVIPMinimum/Sniffs/Performance/OrderByRandSniff.php b/WordPressVIPMinimum/Sniffs/Performance/OrderByRandSniff.php index 3c151398..b743e74d 100644 --- a/WordPressVIPMinimum/Sniffs/Performance/OrderByRandSniff.php +++ b/WordPressVIPMinimum/Sniffs/Performance/OrderByRandSniff.php @@ -9,7 +9,7 @@ namespace WordPressVIPMinimum\Sniffs\Performance; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag using orderby => rand. diff --git a/WordPressVIPMinimum/Sniffs/Performance/RegexpCompareSniff.php b/WordPressVIPMinimum/Sniffs/Performance/RegexpCompareSniff.php index 4ca763ae..7a34ab5c 100644 --- a/WordPressVIPMinimum/Sniffs/Performance/RegexpCompareSniff.php +++ b/WordPressVIPMinimum/Sniffs/Performance/RegexpCompareSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Performance; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag REGEXP and NOT REGEXP in meta compare diff --git a/WordPressVIPMinimum/Sniffs/Performance/RemoteRequestTimeoutSniff.php b/WordPressVIPMinimum/Sniffs/Performance/RemoteRequestTimeoutSniff.php index 4209c1db..e0c17f95 100644 --- a/WordPressVIPMinimum/Sniffs/Performance/RemoteRequestTimeoutSniff.php +++ b/WordPressVIPMinimum/Sniffs/Performance/RemoteRequestTimeoutSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Performance; -use WordPress\AbstractArrayAssignmentRestrictionsSniff; +use WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff; /** * Flag REGEXP and NOT REGEXP in meta compare diff --git a/WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php index 1da213a1..abe621fe 100644 --- a/WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php @@ -7,7 +7,7 @@ namespace WordPressVIPMinimum\Sniffs\Security; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; /** * This sniff ensures that proper sanitization is occurring when PHP's filter_* functions are used. diff --git a/WordPressVIPMinimum/Sniffs/Sniff.php b/WordPressVIPMinimum/Sniffs/Sniff.php index 3abe33eb..dfad0381 100644 --- a/WordPressVIPMinimum/Sniffs/Sniff.php +++ b/WordPressVIPMinimum/Sniffs/Sniff.php @@ -16,5 +16,5 @@ * * @package VIPCS\WordPressVIPMinimum */ -abstract class Sniff extends \WordPress\Sniff { +abstract class Sniff extends \WordPressCS\WordPress\Sniff { } diff --git a/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php b/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php index 85ac8b7e..833745d4 100644 --- a/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php +++ b/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php @@ -9,7 +9,7 @@ namespace WordPressVIPMinimum\Sniffs\UserExperience; -use WordPress\AbstractFunctionParameterSniff; +use WordPressCS\WordPress\AbstractFunctionParameterSniff; use PHP_CodeSniffer\Util\Tokens; /** diff --git a/WordPressVIPMinimum/ruleset-test.inc b/WordPressVIPMinimum/ruleset-test.inc index 5a66acb7..d3a894cb 100644 --- a/WordPressVIPMinimum/ruleset-test.inc +++ b/WordPressVIPMinimum/ruleset-test.inc @@ -50,10 +50,10 @@ $b = function () { $listofthings = wp_cache_get( $listofthings ); if ( ! $listofthings ) { $foo = "column = 'test'"; - + $listofthings = $wpdb->query( 'SELECT something FROM somewhere WHERE ' . $foo ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Error. wp_cache_set( 'foo', $listofthings ); - } + } }; // WordPress.DB.DirectDatabaseQuery @@ -124,7 +124,7 @@ class TestClass extends MyClass { ?> -// if (empty($this)) {echo 'This is will not work';} +// if (empty($this)) {echo 'This is will not work';} // Squiz.PHP.Eval eval('$var = 4;'); // Error + Message. @@ -146,12 +146,6 @@ $handle = popen( '/bin/ls', 'r' ); // Warning. // WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting error_reporting(); // Error. -// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_ini_set -ini_set(); // Error. - -// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_ini_alter -ini_alter(); // Error. - // WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_ini_restore ini_restore(); // Error. @@ -198,12 +192,58 @@ phpinfo(); // Error. // WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log(); // Error. +// WordPress.PHP.IniSet +ini_set( 'auto_detect_line_endings', true ); // Ok. +ini_set( 'highlight.bg', '#000000' ); // Ok. +ini_set( 'highlight.comment', '#000000' ); // Ok. +ini_set( 'highlight.default', '#000000' ); // Ok. +ini_set( 'highlight.html', '#000000' ); // Ok. +ini_set( 'highlight.keyword', '#000000' ); // Ok. +ini_set( 'highlight.string', '#000000' ); // Ok. +ini_set( 'short_open_tag', 1 ); // Ok. +ini_set( 'bcmath.scale', 1 ); // Error. +ini_set( 'display_errors', 1 ); // Error. +ini_set( 'error_reporting', 1 ); // Error. +ini_set( 'filter.default', 1 ); // Error. +ini_set( 'filter.default_flags', 1 ); // Error. +ini_set( 'iconv.input_encoding', 1 ); // Error. +ini_set( 'iconv.internal_encoding', 1 ); // Error. +ini_set( 'iconv.output_encoding', 1 ); // Error. +ini_set( 'ignore_user_abort', 1 ); // Error. +ini_set( 'log_errors', 1 ); // Error. +ini_set( 'max_execution_time', 1 ); // Error. +ini_set( 'memory_limit', 1 ); // Error. +ini_set( 'short_open_tag', 'off' ); // Error. +ini_set( 'foo', true ); // Warning. +ini_alter( 'auto_detect_line_endings', true ); // Ok. +ini_alter( 'highlight.bg', '#000000' ); // Ok. +ini_alter( 'highlight.comment', '#000000' ); // Ok. +ini_alter( 'highlight.default', '#000000' ); // Ok. +ini_alter( 'highlight.html', '#000000' ); // Ok. +ini_alter( 'highlight.keyword', '#000000' ); // Ok. +ini_alter( 'highlight.string', '#000000' ); // Ok. +ini_alter( 'short_open_tag', 1 ); // Ok. +ini_alter( 'bcmath.scale', 1 ); // Error. +ini_alter( 'display_errors', 1 ); // Error. +ini_alter( 'error_reporting', 1 ); // Error. +ini_alter( 'filter.default', 1 ); // Error. +ini_alter( 'filter.default_flags', 1 ); // Error. +ini_alter( 'iconv.input_encoding', 1 ); // Error. +ini_alter( 'iconv.internal_encoding', 1 ); // Error. +ini_alter( 'iconv.output_encoding', 1 ); // Error. +ini_alter( 'ignore_user_abort', 1 ); // Error. +ini_alter( 'log_errors', 1 ); // Error. +ini_alter( 'max_execution_time', 1 ); // Error. +ini_alter( 'memory_limit', 1 ); // Error. +ini_alter( 'short_open_tag', 'off' ); // Error. +ini_alter( 'foo', true ); // Warning. + // WordPress.WP.AlternativeFunctions curl_init(); // Warning + Message. curl_close( $ch ); // Warning + Message. CURL_getinfo(); // Warning + Message. -parse_url( 'http://example.com/' ); // Warning + Message. -$json = json_encode( $thing ); // Warning + Message. +parse_url( 'http://example.com/' ); // Warning. +$json = json_encode( $thing ); // Warning. readfile(); // Warning. fclose(); // Warning. fopen(); // Warning. @@ -430,7 +470,7 @@ $args = array( ); $query_args['orderby'] = 'rand'; // Error. -// WordPressVIPMinimum.Performance.RegexpCompare +// WordPressVIPMinimum.Performance.RegexpCompare $query_args = array( 'posts_per_page' => 1, 'post_status' => 'draft', diff --git a/WordPressVIPMinimum/ruleset-test.php b/WordPressVIPMinimum/ruleset-test.php index 424a46db..a4dd1efd 100644 --- a/WordPressVIPMinimum/ruleset-test.php +++ b/WordPressVIPMinimum/ruleset-test.php @@ -44,60 +44,44 @@ 171 => 1, 174 => 1, 177 => 1, - 180 => 1, - 183 => 1, - 196 => 1, - 199 => 1, - 219 => 1, + 190 => 1, + 193 => 1, + 204 => 1, + 205 => 1, + 206 => 1, + 207 => 1, + 208 => 1, + 209 => 1, + 210 => 1, + 211 => 1, + 212 => 1, + 213 => 1, + 214 => 1, + 215 => 1, + 216 => 1, + 226 => 1, + 227 => 1, + 228 => 1, + 229 => 1, + 230 => 1, + 231 => 1, + 232 => 1, + 233 => 1, 234 => 1, - 245 => 1, - 250 => 1, - 255 => 1, - 256 => 1, + 235 => 1, + 236 => 1, + 237 => 1, + 238 => 1, 259 => 1, - 263 => 1, - 264 => 1, - 268 => 1, - 271 => 1, - 272 => 1, - 273 => 1, 274 => 1, - 275 => 1, - 276 => 1, - 277 => 1, - 278 => 1, - 279 => 1, - 280 => 1, - 281 => 1, - 282 => 1, - 283 => 1, - 284 => 1, 285 => 1, - 286 => 1, - 287 => 1, - 288 => 1, - 289 => 1, 290 => 1, - 291 => 1, - 292 => 1, - 293 => 1, - 294 => 1, 295 => 1, 296 => 1, - 297 => 1, - 298 => 1, 299 => 1, - 300 => 1, - 301 => 1, - 302 => 1, 303 => 1, 304 => 1, - 305 => 1, - 306 => 1, - 307 => 1, 308 => 1, - 309 => 1, - 310 => 1, 311 => 1, 312 => 1, 313 => 1, @@ -117,8 +101,11 @@ 327 => 1, 328 => 1, 329 => 1, + 330 => 1, 331 => 1, 332 => 1, + 333 => 1, + 334 => 1, 335 => 1, 336 => 1, 337 => 1, @@ -140,50 +127,87 @@ 353 => 1, 354 => 1, 355 => 1, + 356 => 1, + 357 => 1, + 358 => 1, + 359 => 1, + 360 => 1, + 361 => 1, + 362 => 1, + 363 => 1, + 364 => 1, + 365 => 1, + 366 => 1, + 367 => 1, + 368 => 1, + 369 => 1, + 371 => 1, + 372 => 1, 375 => 1, + 376 => 1, + 377 => 1, + 378 => 1, + 379 => 1, + 380 => 1, + 381 => 1, + 382 => 1, + 383 => 1, + 384 => 1, 385 => 1, - 411 => 1, - 423 => 1, + 386 => 1, + 387 => 1, + 388 => 1, + 389 => 1, + 390 => 1, + 391 => 1, + 392 => 1, + 393 => 1, + 394 => 1, + 395 => 1, + 415 => 1, 425 => 1, - 429 => 1, - 431 => 1, - 437 => 1, - 443 => 1, 451 => 1, + 463 => 1, 465 => 1, 469 => 1, - 470 => 1, 471 => 1, - 472 => 1, - 473 => 1, - 474 => 1, - 475 => 1, - 476 => 1, 477 => 1, - 478 => 1, - 479 => 1, 483 => 1, - 485 => 1, + 491 => 1, + 505 => 1, + 509 => 1, 510 => 1, 511 => 1, + 512 => 1, + 513 => 1, 514 => 1, - 529 => 1, - 530 => 1, - 533 => 1, - 534 => 1, - 535 => 1, - 538 => 1, - 541 => 1, - 542 => 1, - 543 => 1, - 548 => 1, + 515 => 1, + 516 => 1, + 517 => 1, + 518 => 1, + 519 => 1, + 523 => 1, + 525 => 1, 550 => 1, + 551 => 1, 554 => 1, - 555 => 1, - 556 => 1, - 557 => 1, - 572 => 1, + 569 => 1, + 570 => 1, + 573 => 1, + 574 => 1, + 575 => 1, 578 => 1, + 581 => 1, + 582 => 1, + 583 => 1, + 588 => 1, + 590 => 1, + 594 => 1, + 595 => 1, + 596 => 1, + 597 => 1, + 612 => 1, + 618 => 1, ], 'warnings' => [ 32 => 1, @@ -207,91 +231,93 @@ 142 => 1, 143 => 1, 144 => 1, + 180 => 1, + 181 => 1, + 182 => 1, + 183 => 1, + 184 => 1, + 185 => 1, 186 => 1, 187 => 1, - 188 => 1, - 189 => 1, - 190 => 1, - 191 => 1, - 192 => 1, - 193 => 1, - 202 => 1, - 203 => 1, - 204 => 1, - 205 => 1, - 206 => 1, - 207 => 1, - 208 => 1, - 209 => 1, - 210 => 1, - 211 => 1, - 212 => 1, - 213 => 1, - 214 => 1, - 215 => 1, - 216 => 1, - 224 => 2, + 217 => 1, 239 => 1, 242 => 1, + 243 => 1, + 244 => 1, + 245 => 1, + 246 => 1, + 247 => 1, 248 => 1, + 249 => 1, + 250 => 1, + 251 => 1, + 252 => 1, 253 => 1, 254 => 1, - 356 => 1, - 357 => 1, - 358 => 1, - 359 => 1, - 360 => 1, - 361 => 1, - 362 => 1, - 363 => 1, - 364 => 1, - 365 => 1, - 366 => 1, - 367 => 1, - 368 => 1, - 371 => 1, - 372 => 1, - 392 => 1, + 255 => 1, + 256 => 1, + 264 => 2, + 279 => 1, + 282 => 1, + 288 => 1, + 293 => 1, + 294 => 1, + 396 => 1, 397 => 1, 398 => 1, 399 => 1, 400 => 1, 401 => 1, + 402 => 1, + 403 => 1, + 404 => 1, + 405 => 1, + 406 => 1, 407 => 1, - 414 => 1, - 417 => 1, - 418 => 1, - 419 => 1, + 408 => 1, + 411 => 1, + 412 => 1, + 432 => 1, + 437 => 1, + 438 => 1, + 439 => 1, + 440 => 1, + 441 => 1, + 447 => 1, + 454 => 1, + 457 => 1, + 458 => 1, 459 => 1, - 460 => 1, - 464 => 1, - 488 => 1, - 489 => 1, - 490 => 1, - 491 => 1, - 492 => 1, - 495 => 1, - 498 => 1, - 505 => 1, - 519 => 1, - 525 => 1, - 549 => 1, - 564 => 2, + 499 => 1, + 500 => 1, + 504 => 1, + 528 => 1, + 529 => 1, + 530 => 1, + 531 => 1, + 532 => 1, + 535 => 1, + 538 => 1, + 545 => 1, + 559 => 1, + 565 => 1, + 589 => 1, + 604 => 2, ], 'messages' => [ 130 => [ '`eval()` is a security risk, please refrain from using it.', ], - 202 => [ + 242 => [ 'Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/.', ], - 203 => [ + 243 => [ 'Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/.', ], - 204 => [ + 244 => [ 'Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/.', ], - 219 => [ + 259 => [ '`get_children()` performs a no-LIMIT query by default, make sure to set a reasonable `posts_per_page`. `get_children()` will do a -1 query by default, a maximum of 100 should be used.', ], ], diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml index 042f9289..976aac76 100644 --- a/WordPressVIPMinimum/ruleset.xml +++ b/WordPressVIPMinimum/ruleset.xml @@ -6,8 +6,6 @@ https://wpvip.com/documentation/vip-go/understanding-codebase-differences/ for the differences between the platforms --> - ./PHPCSCompatibility.php - @@ -25,6 +23,7 @@ + @@ -69,18 +68,14 @@ - + + + error - - error - - - error - error diff --git a/composer.json b/composer.json index e6f7ce41..c37ec9f9 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ ], "require": { "php": ">=5.6", - "squizlabs/php_codesniffer": "^3.2.3", - "wp-coding-standards/wpcs": "1.*" + "squizlabs/php_codesniffer": "^3.3.1", + "wp-coding-standards/wpcs": "^2.1" }, "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.5", diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 52ffc92e..9257de94 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -52,6 +52,4 @@ die( 1 ); } -// Load our class aliases. -require_once dirname( __DIR__ ) . $ds . 'WordPressVIPMinimum' . $ds . 'PHPCSCompatibility.php'; unset( $ds, $phpcsDir );