Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change error type of NonEnqueuedImage in ImageFunctions sniff #822

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function process_token( $stackPtr ) {

if ( preg_match_all( '#<img[^>]*(?<=src=)#', $content, $matches, \PREG_OFFSET_CAPTURE ) > 0 ) {
foreach ( $matches[0] as $match ) {
$this->phpcsFile->addError(
$this->phpcsFile->addWarning(
'Images should be added using wp_get_attachment_image() or similar functions',
$this->find_token_in_multiline_string( $stackPtr, $content, $match[1] ),
'NonEnqueuedImage'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ final class ImageFunctionsUnitTest extends AbstractSniffUnitTest {
* @return array <int line number> => <int number of errors>
*/
public function getErrorList() {
return array();
}

/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array(
1 => 1,
7 => 1,
Expand All @@ -32,13 +41,4 @@ public function getErrorList() {
25 => 1,
);
}

/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public function test_run_with_errors() {

$check->run( $check_result );

$errors = $check_result->get_errors();
$warnings = $check_result->get_warnings();

$this->assertNotEmpty( $errors );
$this->assertArrayHasKey( 'load.php', $errors );
$this->assertEquals( 2, $check_result->get_error_count() );
$this->assertNotEmpty( $warnings );
$this->assertArrayHasKey( 'load.php', $warnings );
$this->assertEquals( 2, $check_result->get_warning_count() );
}

public function test_run_without_errors() {
Expand All @@ -32,9 +32,9 @@ public function test_run_without_errors() {

$check->run( $check_result );

$errors = $check_result->get_errors();
$warnings = $check_result->get_warnings();

$this->assertEmpty( $errors );
$this->assertEquals( 0, $check_result->get_error_count() );
$this->assertEmpty( $warnings );
$this->assertEquals( 0, $check_result->get_warning_count() );
}
}
Loading