mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Add emacs-compatible report format
This commit is contained in:
parent
de9d282205
commit
0deccccdbb
@ -145,6 +145,7 @@ class ProjectChecker
|
||||
|
||||
const TYPE_CONSOLE = 'console';
|
||||
const TYPE_JSON = 'json';
|
||||
const TYPE_EMACS = 'emacs';
|
||||
|
||||
/**
|
||||
* @param boolean $use_color
|
||||
@ -165,7 +166,7 @@ class ProjectChecker
|
||||
$this->debug_output = $debug_output;
|
||||
$this->update_docblocks = $update_docblocks;
|
||||
|
||||
if (!in_array($output_format, [self::TYPE_CONSOLE, self::TYPE_JSON])) {
|
||||
if (!in_array($output_format, [self::TYPE_CONSOLE, self::TYPE_JSON, self::TYPE_EMACS])) {
|
||||
throw new \UnexpectedValueException('Unrecognised output format ' . $output_format);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,9 @@ class CodeLocation
|
||||
/** @var int */
|
||||
protected $selection_end = -1;
|
||||
|
||||
/** @var int */
|
||||
protected $column = -1;
|
||||
|
||||
/** @var string */
|
||||
protected $snippet = '';
|
||||
|
||||
@ -162,6 +165,10 @@ class CodeLocation
|
||||
$this->selection_start = max($this->preview_start, $this->selection_start);
|
||||
$this->selection_end = min($this->preview_end, $this->selection_end);
|
||||
|
||||
// reset preview start to beginning of line
|
||||
$this->column = $this->selection_start -
|
||||
(int)strrpos($file_contents, "\n", $this->selection_start - strlen($file_contents));
|
||||
|
||||
$this->snippet = substr($file_contents, $this->preview_start, $this->preview_end - $this->preview_start);
|
||||
}
|
||||
|
||||
@ -183,6 +190,16 @@ class CodeLocation
|
||||
return $this->snippet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getColumn()
|
||||
{
|
||||
$this->calculateRealLocation();
|
||||
|
||||
return $this->column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
|
@ -79,6 +79,10 @@ class IssueBuffer
|
||||
case ProjectChecker::TYPE_JSON:
|
||||
self::$issue_data[] = self::getIssueArray($e, Config::REPORT_INFO);
|
||||
break;
|
||||
|
||||
case ProjectChecker::TYPE_EMACS:
|
||||
echo self::getEmacsOutput($e, Config::REPORT_INFO) . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -102,6 +106,10 @@ class IssueBuffer
|
||||
case ProjectChecker::TYPE_JSON:
|
||||
self::$issue_data[] = self::getIssueArray($e);
|
||||
break;
|
||||
|
||||
case ProjectChecker::TYPE_EMACS:
|
||||
echo self::getEmacsOutput($e) . PHP_EOL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,6 +142,20 @@ class IssueBuffer
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Issue\CodeIssue $e
|
||||
* @param string $severity
|
||||
* @return string
|
||||
*/
|
||||
protected static function getEmacsOutput(Issue\CodeIssue $e, $severity = Config::REPORT_ERROR)
|
||||
{
|
||||
$location = $e->getLocation();
|
||||
$selection_bounds = $location->getSelectionBounds();
|
||||
|
||||
return $location->file_path . ':' . $location->getLineNumber() . ':' . $location->getColumn() . ': ' .
|
||||
($severity === Config::REPORT_ERROR ? 'error' : 'warning') . ' - ' . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array>
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user