diff --git a/includes/Checker/Check_Result.php b/includes/Checker/Check_Result.php index 389cb8217..c8b8fc30f 100644 --- a/includes/Checker/Check_Result.php +++ b/includes/Checker/Check_Result.php @@ -88,7 +88,7 @@ public function plugin() { * * @type string $code Violation code according to the message. Default empty string. * @type string $file The file in which the message occurred. Default empty string (unknown file). - * @type int $line The line on which the message occurred. Default 0 (unknown line). + * @type int $line The line on which the message occurred. Default 1 (unknown line). * @type int $column The column on which the message occurred. Default 0 (unknown column). * @type string $link View in code editor link. Default empty string. * } @@ -97,7 +97,7 @@ public function add_message( $error, $message, $args = array() ) { $defaults = array( 'code' => '', 'file' => '', - 'line' => 0, + 'line' => 1, 'column' => 0, 'link' => '', 'docs' => '', @@ -113,7 +113,7 @@ public function add_message( $error, $message, $args = array() ) { ); $file = str_replace( $this->plugin()->path( '/' ), '', $data['file'] ); - $line = $data['line']; + $line = $data['line'] > 0 ? $data['line'] : 1; $column = $data['column']; unset( $data['line'], $data['column'], $data['file'] ); diff --git a/includes/Traits/Amend_Check_Result.php b/includes/Traits/Amend_Check_Result.php index 4dc5a1951..c8cab9a3f 100644 --- a/includes/Traits/Amend_Check_Result.php +++ b/includes/Traits/Amend_Check_Result.php @@ -28,12 +28,12 @@ trait Amend_Check_Result { * @param string $message Error message. * @param string $code Error code. * @param string $file Absolute path to the file where the issue was found. - * @param int $line The line on which the message occurred. Default is 0 (unknown line). + * @param int $line The line on which the message occurred. Default is 1 (unknown line). * @param int $column The column on which the message occurred. Default is 0 (unknown column). * @param string $docs URL for further information about the message. * @param int $severity Severity level. Default is 5. */ - protected function add_result_message_for_file( Check_Result $result, $error, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) { + protected function add_result_message_for_file( Check_Result $result, $error, $message, $code, $file, $line = 1, $column = 0, string $docs = '', $severity = 5 ) { $result->add_message( (bool) $error, @@ -59,12 +59,12 @@ protected function add_result_message_for_file( Check_Result $result, $error, $m * @param string $message Error message. * @param string $code Error code. * @param string $file Absolute path to the file where the error was found. - * @param int $line The line on which the error occurred. Default is 0 (unknown line). + * @param int $line The line on which the error occurred. Default is 1 (unknown line). * @param int $column The column on which the error occurred. Default is 0 (unknown column). * @param string $docs URL for further information about the message. * @param int $severity Severity level. Default is 5. */ - protected function add_result_error_for_file( Check_Result $result, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) { + protected function add_result_error_for_file( Check_Result $result, $message, $code, $file, $line = 1, $column = 0, string $docs = '', $severity = 5 ) { $this->add_result_message_for_file( $result, true, $message, $code, $file, $line, $column, $docs, $severity ); } @@ -77,12 +77,12 @@ protected function add_result_error_for_file( Check_Result $result, $message, $c * @param string $message Error message. * @param string $code Error code. * @param string $file Absolute path to the file where the warning was found. - * @param int $line The line on which the warning occurred. Default is 0 (unknown line). + * @param int $line The line on which the warning occurred. Default is 1 (unknown line). * @param int $column The column on which the warning occurred. Default is 0 (unknown column). * @param string $docs URL for further information about the message. * @param int $severity Severity level. Default is 5. */ - protected function add_result_warning_for_file( Check_Result $result, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) { + protected function add_result_warning_for_file( Check_Result $result, $message, $code, $file, $line = 1, $column = 0, string $docs = '', $severity = 5 ) { $this->add_result_message_for_file( $result, false, $message, $code, $file, $line, $column, $docs, $severity ); } } diff --git a/tests/behat/features/plugin-check.feature b/tests/behat/features/plugin-check.feature index 8b13b4806..60ff50556 100644 --- a/tests/behat/features/plugin-check.feature +++ b/tests/behat/features/plugin-check.feature @@ -56,7 +56,7 @@ Feature: Test that the WP-CLI command works. Then STDOUT should contain: """ line,column,type,code,message,docs - 0,0,ERROR,missing_direct_file_access_protection,"PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;",https://developer.wordpress.org/plugins/wordpress-org/common-issues/#direct-file-access + 1,0,ERROR,missing_direct_file_access_protection,"PHP file should prevent direct access. Add a check like: if ( ! defined( 'ABSPATH' ) ) exit;",https://developer.wordpress.org/plugins/wordpress-org/common-issues/#direct-file-access 16,15,ERROR,WordPress.WP.AlternativeFunctions.rand_mt_rand,"mt_rand() is discouraged. Use the far less predictable wp_rand() instead.", 17,10,ERROR,WordPress.Security.EscapeOutput.OutputNotEscaped,"All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$number'.",https://developer.wordpress.org/apis/security/escaping/#escaping-functions """ @@ -65,7 +65,7 @@ Feature: Test that the WP-CLI command works. Then STDOUT should contain: """ line,column,code - 0,0,missing_direct_file_access_protection + 1,0,missing_direct_file_access_protection 16,15,WordPress.WP.AlternativeFunctions.rand_mt_rand 17,10,WordPress.Security.EscapeOutput.OutputNotEscaped """