Skip to content
Open
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
6 changes: 3 additions & 3 deletions includes/Checker/Check_Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* }
Expand All @@ -97,7 +97,7 @@ public function add_message( $error, $message, $args = array() ) {
$defaults = array(
'code' => '',
'file' => '',
'line' => 0,
'line' => 1,
'column' => 0,
'link' => '',
'docs' => '',
Expand All @@ -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'] );

Expand Down
12 changes: 6 additions & 6 deletions includes/Traits/Amend_Check_Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 );
}

Expand All @@ -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 );
}
}
4 changes: 2 additions & 2 deletions tests/behat/features/plugin-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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
"""
Expand Down
Loading