Skip to content

Commit

Permalink
WP/EnqueuedResourceParameters: change MissingVersion to a warning
Browse files Browse the repository at this point in the history
Fixes 1472

Includes updated unit tests.
  • Loading branch information
jrfnl committed Dec 9, 2022
1 parent 7688d70 commit 4861af0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions WordPress/Sniffs/WP/EnqueuedResourceParametersSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
$type = 'style';
}

$this->phpcsFile->addError(
'Resource version not set in call to %s(). This means new versions of the %s will not always be loaded due to browser caching.',
$this->phpcsFile->addWarning(
'Resource version not set in call to %s(). This means new versions of the %s may not always be loaded due to browser caching.',
$stackPtr,
'MissingVersion',
array( $matched_content, $type )
Expand Down
8 changes: 4 additions & 4 deletions WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ) ); // Error - missing $ver, Warning - In Footer is set to a falsy (default) value.
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ) ); // Warning - missing $ver, Warning - In Footer is set to a falsy (default) value.

wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), /* comment */ '1.1.1', true ); // OK.
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), /* comment */ '0' /* another comment */, true ); // Error - 0, false or NULL are not allowed.
Expand Down Expand Up @@ -36,13 +36,13 @@ wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array
wp_register_script( 'someScript-js', 'https://example.com/someScript.js' , array( 'jquery' ), '1.1.0', $in_footer ); // OK.

wp_enqueue_script( 'script-name', 'https://example.com/someScript.js', false, '1.0.0', true ); // OK.
wp_enqueue_script( 'script-name', 'https://example.com/someScript.js' ); // Error - missing $ver, Warning - missing $in_footer.
wp_enqueue_script( 'script-name', 'https://example.com/someScript.js' ); // Warning - missing $ver, Warning - missing $in_footer.

wp_register_style( 'script-name', 'https://example.com/someScript.js', false, '1.0.0' ); // OK.
wp_register_style( 'script-name', 'https://example.com/someScript.js' ); // Error - missing $ver.
wp_register_style( 'script-name', 'https://example.com/someScript.js' ); // Warning - missing $ver.

wp_enqueue_style( 'script-name', 'https://example.com/someScript.js', false, '1.0.0'); // OK.
wp_enqueue_style( 'script-name', 'https://example.com/someScript.js' ); // Error - missing $ver.
wp_enqueue_style( 'script-name', 'https://example.com/someScript.js' ); // Warning - missing $ver.

wp_register_script( 'someScript-js' ); // OK.
wp_enqueue_script( 'someScript-js' ); // OK.
Expand Down
12 changes: 5 additions & 7 deletions WordPress/Tests/WP/EnqueuedResourceParametersUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ class EnqueuedResourceParametersUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
6 => 1,
9 => 1,
10 => 1,
11 => 1,
12 => 1,
13 => 1,
14 => 1,
22 => 1,
39 => 1,
42 => 1,
45 => 1,
54 => 1,
57 => 1,
);
Expand All @@ -51,9 +46,12 @@ public function getErrorList() {
*/
public function getWarningList() {
return array(
3 => 1,
3 => 2,
11 => 1,
32 => 1,
39 => 1,
39 => 2,
42 => 1,
45 => 1,
);
}

Expand Down

0 comments on commit 4861af0

Please sign in to comment.