Skip to content

Commit 0fd1c85

Browse files
authored
Merge pull request #779 from Automattic/3.0/updates-for-wpcs-3.0
2 parents 9b5c899 + 36f1684 commit 0fd1c85

18 files changed

+109
-64
lines changed

.github/workflows/basics.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install PHP
3030
uses: shivammathur/setup-php@v2
3131
with:
32-
php-version: '7.4'
32+
php-version: 'latest'
3333
coverage: none
3434
tools: cs2pr
3535

.github/workflows/quicktest.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ jobs:
2828
include:
2929
- php: '5.4'
3030
phpcs_version: 'dev-master'
31-
wpcs_version: '2.3.*'
31+
wpcs_version: '3.0.*'
3232
- php: '5.4'
33-
phpcs_version: '3.7.1'
34-
wpcs_version: '2.3.*'
33+
phpcs_version: '3.7.2'
34+
wpcs_version: '3.0.*'
3535

3636
- php: 'latest'
3737
phpcs_version: 'dev-master'
38-
wpcs_version: '2.3.*'
38+
wpcs_version: '3.0.*'
3939
- php: 'latest'
40-
phpcs_version: '3.7.1'
41-
wpcs_version: '2.3.*'
40+
phpcs_version: '3.7.2'
41+
wpcs_version: '3.0.*'
4242

4343
name: "QTest${{ matrix.phpcs_version == 'dev-master' && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"
4444

@@ -48,7 +48,6 @@ jobs:
4848

4949
# On stable PHPCS versions, allow for PHP deprecation notices.
5050
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
51-
# Note: the "elif" condition is temporary and should be removed once VIPCS updates to WPCS 3.0+.
5251
- name: Setup ini config
5352
id: set_ini
5453
run: |

.github/workflows/test.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ jobs:
7272
# no additional versions are included in the array.
7373
matrix:
7474
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
75-
phpcs_version: ['3.7.1', 'dev-master']
76-
wpcs_version: ['2.3.*']
75+
phpcs_version: ['3.7.2', 'dev-master']
76+
wpcs_version: ['3.0.*']
7777

7878
include:
7979
- php: '8.3'
8080
phpcs_version: 'dev-master'
81-
wpcs_version: '2.3.*'
81+
wpcs_version: '3.0.*'
8282

8383
name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }} - WPCS ${{ matrix.wpcs_version }}"
8484

@@ -90,14 +90,11 @@ jobs:
9090

9191
# On stable PHPCS versions, allow for PHP deprecation notices.
9292
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
93-
# Note: the "elif" condition is temporary and should be removed once VIPCS updates to WPCS 3.0+.
9493
- name: Setup ini config
9594
id: set_ini
9695
run: |
9796
if [[ "${{ matrix.phpcs_version }}" != "dev-master" ]]; then
9897
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED' >> $GITHUB_OUTPUT
99-
elif [[ "${{ matrix.php }}" == "8.1" ]]; then
100-
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED' >> $GITHUB_OUTPUT
10198
else
10299
echo 'PHP_INI=error_reporting=-1' >> $GITHUB_OUTPUT
103100
fi

.phpcs.xml.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
<rule ref="WordPress-Extra">
2020
<exclude name="WordPress.Files.FileName"/>
2121
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
22-
<exclude name="WordPress.NamingConventions.PrefixAllGlobals"/>
23-
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
22+
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
2423
<exclude name="WordPress.PHP.YodaConditions"/>
2524
</rule>
2625

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Go to https://docs.wpvip.com/technical-references/code-review/phpcs-report/ to l
1616
## Minimal requirements
1717

1818
* PHP 5.4+
19-
* [PHPCS 3.7.1+](https://github.com/squizlabs/PHP_CodeSniffer/releases)
19+
* [PHPCS 3.7.2+](https://github.com/squizlabs/PHP_CodeSniffer/releases)
2020
* [PHPCSUtils 1.0.8+](https://github.com/PHPCSStandards/PHPCSUtils)
21-
* [WPCS 2.3.0+](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases)
21+
* [WPCS 3.0.0+](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases)
2222
* [VariableAnalysis 2.11.17+](https://github.com/sirbrillig/phpcs-variable-analysis/releases)
2323

2424
## Installation
@@ -35,7 +35,7 @@ composer g config allow-plugins.dealerdirect/phpcodesniffer-composer-installer t
3535
composer g require automattic/vipwpcs
3636
```
3737

38-
This will install the latest compatible versions of PHPCS, PHPCSUtils, WPCS and VariableAnalysis and register the external standards with PHP_CodeSniffer.
38+
This will install the latest compatible versions of PHPCS, PHPCSUtils, PHPCSExtra, WPCS and VariableAnalysis and register the external standards with PHP_CodeSniffer.
3939

4040
Please refer to the [installation instructions for installing PHP_CodeSniffer for WordPress.com VIP](https://docs.wpvip.com/how-tos/code-review/php_codesniffer/) for more details.
4141

WordPress-VIP-Go/ruleset-test.inc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && $_SERVER['HTTP_USER_AGENT'] === 'so
5959
// Make sure nonce verification is done in global scope to silence notices about use of superglobals without later on in the file.
6060
isset( $_GET['my_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_GET['my_nonce'] ) );
6161

62-
// WordPress.WP.AlternativeFunctions.file_system_read_fopen
62+
// WordPress.WP.AlternativeFunctions.file_system_operations_fopen
6363
fopen( 'file.txt', 'r' ); // Warning + Message.
6464

6565
// WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
@@ -153,7 +153,7 @@ url_to_postid( $url ); // Warning + Message.
153153
wpcom_vip_old_slug_redirect(); // Ok.
154154
wp_old_slug_redirect(); // Warning.
155155

156-
// WordPress.CodeAnalysis.AssignmentInCondition.Found
156+
// Generic.CodeAnalysis.AssignmentInCondition.Found
157157
if ($a = 123) { // Warning.
158158
}
159159

@@ -165,7 +165,7 @@ rawurlencode(); // Ok.
165165
extract( array( 'a' => 1 ) ); // Error.
166166
$obj->extract(); // Ok.
167167

168-
// WordPress.PHP.StrictComparisons.LooseComparison
168+
// Universal.Operators.StrictComparisons
169169
true == $true; // Warning.
170170
false === $true; // Ok.
171171

@@ -557,7 +557,7 @@ echo "<script>
557557
</article> <?php
558558

559559
// WordPressVIPMinimum.Variables.RestrictedVariables
560-
foo( $_SESSION['bar'] ); // Error.
560+
foo( $_SESSION['bar'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Error.
561561

562562
// WordPressVIPMinimum.Variables.ServerVariables
563563
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
@@ -572,3 +572,8 @@ $_SERVER["REMOTE_ADDR"]; // Error.
572572
<<<<<<< HEAD // Error.
573573

574574
>>>>>>> // Error.
575+
576+
<?php
577+
578+
// WordPress.CodeAnalysis.AssignmentInTernaryCondition
579+
$var = ($a = 123) ? $a : 0; // Warning.

WordPress-VIP-Go/ruleset-test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
540 => 1,
234234
550 => 1,
235235
556 => 1,
236+
579 => 1,
236237
],
237238
'messages' => [
238239
7 => [

WordPress-VIP-Go/ruleset.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
This includes potential security holes as well as functions that may bring down sites for performance reasons.
105105
-->
106106
<!-- Should fix all of them but it doesn't need a manual review -->
107-
<rule ref="WordPress.WP.AlternativeFunctions.file_system_read_fopen">
107+
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fopen">
108108
<message>File system operations only work on the `/tmp/` and `wp-content/uploads/` directories. To avoid unexpected results, please use helper functions like `get_temp_dir()` or `wp_get_upload_dir()` to get the proper directory path when using functions such as %s(). For more details, please see: https://docs.wpvip.com/technical-references/vip-go-files-system/local-file-operations/</message>
109109
</rule>
110110
<rule ref="WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown">
@@ -179,7 +179,10 @@
179179
<rule ref="Internal.LineEndings.Mixed">
180180
<severity>1</severity>
181181
</rule>
182-
<rule ref="WordPress.CodeAnalysis.AssignmentInCondition.Found">
182+
<rule ref="Generic.CodeAnalysis.AssignmentInCondition">
183+
<severity>1</severity>
184+
</rule>
185+
<rule ref="WordPress.CodeAnalysis.AssignmentInTernaryCondition.FoundInTernaryCondition">
183186
<severity>1</severity>
184187
</rule>
185188
<rule ref="WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode">
@@ -188,7 +191,7 @@
188191
<rule ref="WordPress.PHP.DontExtract">
189192
<severity>3</severity>
190193
</rule>
191-
<rule ref="WordPress.PHP.StrictComparisons.LooseComparison">
194+
<rule ref="Universal.Operators.StrictComparisons">
192195
<severity>3</severity>
193196
</rule>
194197
<rule ref="WordPress.PHP.StrictInArray.MissingTrueStrict">
@@ -246,10 +249,10 @@
246249
<rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound">
247250
<severity>0</severity>
248251
</rule>
249-
<rule ref="WordPress.WP.AlternativeFunctions.file_system_read_readfile">
252+
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_readfile">
250253
<severity>0</severity>
251254
</rule>
252-
<rule ref="WordPress.WP.AlternativeFunctions.file_system_read_fclose">
255+
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_fclose">
253256
<severity>0</severity>
254257
</rule>
255258

WordPressVIPMinimum/Sniffs/AbstractVariableRestrictionsSniff.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use PHPCSUtils\Utils\GetTokensAsString;
1313
use PHPCSUtils\Utils\MessageHelper;
14+
use WordPressCS\WordPress\Helpers\ContextHelper;
15+
use WordPressCS\WordPress\Helpers\RulesetPropertyHelper;
1416

1517
/**
1618
* Restricts usage of some variables.
@@ -128,7 +130,7 @@ public function process_token( $stackPtr ) {
128130

129131
$token = $this->tokens[ $stackPtr ];
130132

131-
$this->excluded_groups = static::merge_custom_array( $this->exclude );
133+
$this->excluded_groups = RulesetPropertyHelper::merge_custom_array( $this->exclude );
132134
if ( array_diff_key( $this->groups_cache, $this->excluded_groups ) === [] ) {
133135
// All groups have been excluded.
134136
// Don't remove the listener as the exclude property can be changed inline.
@@ -144,7 +146,7 @@ public function process_token( $stackPtr ) {
144146
}
145147
}
146148

147-
if ( $this->is_in_isset_or_empty( $stackPtr ) === true ) {
149+
if ( ContextHelper::is_in_isset_or_empty( $this->phpcsFile, $stackPtr ) === true ) {
148150
// Checking whether a variable exists is not the same as using it.
149151
return;
150152
}

WordPressVIPMinimum/Sniffs/Performance/NoPagingSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public function getGroups() {
5252
public function callback( $key, $val, $line, $group ) {
5353
$key = strtolower( $key );
5454

55-
return ( $key === 'nopaging' && ( $val === 'true' || $val === 1 ) );
55+
return ( $key === 'nopaging' && ( $val === 'true' || $val === '1' ) );
5656
}
5757
}

0 commit comments

Comments
 (0)