mirror of
https://github.com/WordPress/WordPress-Coding-Standards.git
synced 2025-08-30 03:11:24 +08:00
Compare commits
5 commits
298da73b33
...
f8685a2866
Author | SHA1 | Date | |
---|---|---|---|
|
f8685a2866 | ||
|
97ce8229c0 | ||
|
009086db6e | ||
|
7d376f8c69 | ||
|
afb6fb0e82 |
6 changed files with 94 additions and 32 deletions
2
.github/workflows/quicktest.yml
vendored
2
.github/workflows/quicktest.yml
vendored
|
@ -38,7 +38,7 @@ jobs:
|
|||
php-version: ${{ matrix.php }}
|
||||
# With stable PHPCS dependencies, allow for PHP deprecation notices.
|
||||
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
|
||||
ini-values: error_reporting=-1, display_errors=On
|
||||
ini-values: error_reporting=-1, display_errors=On, display_startup_errors=On
|
||||
coverage: ${{ github.ref_name == 'develop' && 'xdebug' || 'none' }}
|
||||
|
||||
- name: Enable creation of `composer.lock` file
|
||||
|
|
4
.github/workflows/unit-tests.yml
vendored
4
.github/workflows/unit-tests.yml
vendored
|
@ -91,9 +91,9 @@ jobs:
|
|||
id: set_ini
|
||||
run: |
|
||||
if [ "${{ matrix.dependencies }}" != "dev" ]; then
|
||||
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> "$GITHUB_OUTPUT"
|
||||
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On, display_startup_errors=On' >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> "$GITHUB_OUTPUT"
|
||||
echo 'PHP_INI=error_reporting=-1, display_errors=On, display_startup_errors=On' >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Set up PHP
|
||||
|
|
|
@ -227,6 +227,30 @@ final class EnqueuedResourceParametersSniff extends AbstractFunctionParameterSni
|
|||
continue;
|
||||
}
|
||||
|
||||
// Make sure that when deprecated casts are used in the code under scan and the sniff is run on PHP 8.5,
|
||||
// the eval() won't cause a deprecation notice, borking the scan of the file.
|
||||
if ( \PHP_VERSION_ID >= 80500 ) {
|
||||
if ( \T_INT_CAST === $this->tokens[ $i ]['code'] ) {
|
||||
$code_string .= '(int)';
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( \T_DOUBLE_CAST === $this->tokens[ $i ]['code'] ) {
|
||||
$code_string .= '(float)';
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( \T_BOOL_CAST === $this->tokens[ $i ]['code'] ) {
|
||||
$code_string .= '(bool)';
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( \T_BINARY_CAST === $this->tokens[ $i ]['code'] ) {
|
||||
$code_string .= '(string)';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$code_string .= $this->tokens[ $i ]['content'];
|
||||
}
|
||||
|
||||
|
|
|
@ -84,5 +84,14 @@ wp_register_script( 'someScript-js', $url, [], 0_0.0_0, true ); // Error - 0, fa
|
|||
// Safeguard handling of PHP 8.1 explicit octals.
|
||||
wp_register_script( 'someScript-js', $url, [], 0o0, true ); // Error - 0, false or NULL are not allowed.
|
||||
|
||||
// Live coding/parse error.
|
||||
wp_register_style( src: 'https://example.com/someScript.js', ver: /*to do*/, handle: 'someScript-js', );
|
||||
// Safeguard against PHP 8.5 deprecation of non-standard cast names.
|
||||
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (boolean) 1, true ); // OK.
|
||||
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (boolean) 0, true ); // Error - 0, false or NULL are not allowed.
|
||||
|
||||
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (integer) 1, true ); // OK.
|
||||
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (integer) 0, true ); // Error - 0, false or NULL are not allowed.
|
||||
|
||||
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (double) 1, true ); // OK.
|
||||
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (double) 0, true ); // Error - 0, false or NULL are not allowed.
|
||||
|
||||
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), (binary) 0, true ); // Error - 0, false or NULL are not allowed.
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
// Live coding/parse error.
|
||||
// This should be the only test in the file.
|
||||
wp_register_style( src: 'https://example.com/someScript.js', ver: /*to do*/, handle: 'someScript-js', );
|
|
@ -23,41 +23,65 @@ final class EnqueuedResourceParametersUnitTest extends AbstractSniffUnitTest {
|
|||
/**
|
||||
* Returns the lines where errors should occur.
|
||||
*
|
||||
* @param string $testFile The name of the file being tested.
|
||||
*
|
||||
* @return array<int, int> Key is the line number, value is the number of expected errors.
|
||||
*/
|
||||
public function getErrorList() {
|
||||
return array(
|
||||
6 => 1,
|
||||
9 => 1,
|
||||
10 => 1,
|
||||
12 => 1,
|
||||
13 => 1,
|
||||
14 => 1,
|
||||
22 => 1,
|
||||
54 => 1,
|
||||
57 => 1,
|
||||
61 => 1,
|
||||
82 => 1,
|
||||
85 => 1,
|
||||
88 => 1,
|
||||
);
|
||||
public function getErrorList( $testFile = '' ) {
|
||||
switch ( $testFile ) {
|
||||
case 'EnqueuedResourceParametersUnitTest.1.inc':
|
||||
return array(
|
||||
6 => 1,
|
||||
9 => 1,
|
||||
10 => 1,
|
||||
12 => 1,
|
||||
13 => 1,
|
||||
14 => 1,
|
||||
22 => 1,
|
||||
54 => 1,
|
||||
57 => 1,
|
||||
61 => 1,
|
||||
82 => 1,
|
||||
85 => 1,
|
||||
89 => 1,
|
||||
92 => 1,
|
||||
95 => 1,
|
||||
97 => 1,
|
||||
);
|
||||
|
||||
case 'EnqueuedResourceParametersUnitTest.2.inc':
|
||||
return array(
|
||||
5 => 1,
|
||||
);
|
||||
|
||||
default:
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lines where warnings should occur.
|
||||
*
|
||||
* @param string $testFile The name of the file being tested.
|
||||
*
|
||||
* @return array<int, int> Key is the line number, value is the number of expected warnings.
|
||||
*/
|
||||
public function getWarningList() {
|
||||
return array(
|
||||
3 => 2,
|
||||
11 => 1,
|
||||
32 => 1,
|
||||
39 => 2,
|
||||
42 => 1,
|
||||
45 => 1,
|
||||
66 => 2,
|
||||
77 => 1,
|
||||
);
|
||||
public function getWarningList( $testFile = '' ) {
|
||||
switch ( $testFile ) {
|
||||
case 'EnqueuedResourceParametersUnitTest.1.inc':
|
||||
return array(
|
||||
3 => 2,
|
||||
11 => 1,
|
||||
32 => 1,
|
||||
39 => 2,
|
||||
42 => 1,
|
||||
45 => 1,
|
||||
66 => 2,
|
||||
77 => 1,
|
||||
);
|
||||
|
||||
default:
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue