2018-12-09 21:47:20 +01:00
|
|
|
<?php
|
2019-06-09 18:37:28 +02:00
|
|
|
namespace Psalm\Report;
|
2018-12-09 21:47:20 +01:00
|
|
|
|
|
|
|
use Psalm\Config;
|
2019-06-09 18:37:28 +02:00
|
|
|
use Psalm\Report;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function sprintf;
|
2018-12-09 21:47:20 +01:00
|
|
|
|
2019-06-09 18:37:28 +02:00
|
|
|
class PylintReport extends Report
|
2018-12-09 21:47:20 +01:00
|
|
|
{
|
|
|
|
/**
|
2019-07-05 22:24:00 +02:00
|
|
|
* {@inheritdoc}
|
2018-12-09 21:47:20 +01:00
|
|
|
*/
|
|
|
|
public function create(): string
|
|
|
|
{
|
|
|
|
$output = '';
|
|
|
|
foreach ($this->issues_data as $issue_data) {
|
|
|
|
$output .= $this->format($issue_data) . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array{severity: string, line_from: int, line_to: int, type: string, message: string,
|
|
|
|
* file_name: string, file_path: string, snippet: string, from: int, to: int,
|
|
|
|
* snippet_from: int, snippet_to: int, column_from: int, column_to: int} $issue_data
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function format(array $issue_data): string
|
|
|
|
{
|
|
|
|
$message = sprintf(
|
|
|
|
'%s: %s',
|
|
|
|
$issue_data['type'],
|
|
|
|
$issue_data['message']
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($issue_data['severity'] === Config::REPORT_ERROR) {
|
|
|
|
$code = 'E0001';
|
|
|
|
} else {
|
|
|
|
$code = 'W0001';
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://docs.pylint.org/en/1.6.0/output.html doesn't mention what to do about 'column',
|
|
|
|
// but it's still useful for users.
|
|
|
|
// E.g. jenkins can't parse %s:%d:%d.
|
|
|
|
$message = sprintf('%s (column %d)', $message, $issue_data['column_from']);
|
|
|
|
$issue_string = sprintf(
|
|
|
|
'%s:%d: [%s] %s',
|
|
|
|
$issue_data['file_name'],
|
|
|
|
$issue_data['line_from'],
|
|
|
|
$code,
|
|
|
|
$message
|
|
|
|
);
|
|
|
|
|
|
|
|
return $issue_string;
|
|
|
|
}
|
|
|
|
}
|