mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-14 19:02:40 +01:00
(stable) When a linter raises a message at a nonexistent line, don't fatal during rendering
Summary: See PHI1782. If a linter raises a message at a line which does not exist in the file, render a confused warning rather than fataling. This is a long-existing issue which was exacerbated by D21044. Test Plan: Modified a linter to raise issues at line 99999. Before change: fatal in console rendering. After change: reasonable rendering. Differential Revision: https://secure.phabricator.com/D21357
This commit is contained in:
parent
b689a8c78b
commit
a798e74071
1 changed files with 35 additions and 0 deletions
|
@ -122,6 +122,41 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer {
|
|||
$old_impact = substr_count($original, "\n") + 1;
|
||||
$start = $line;
|
||||
|
||||
// See PHI1782. If a linter raises a message at a line that does not
|
||||
// exist, just render a warning message.
|
||||
|
||||
// Linters are permitted to raise a warning at the very end of a file.
|
||||
// For example, if a file is 13 lines long, it is valid to raise a message
|
||||
// on line 14 as long as the character position is 1 or unspecified and
|
||||
// there is no "original" text.
|
||||
|
||||
$max_old = count($old_lines);
|
||||
|
||||
$invalid_position = false;
|
||||
if ($start > ($max_old + 1)) {
|
||||
$invalid_position = true;
|
||||
} else if ($start > $max_old) {
|
||||
if (strlen($original)) {
|
||||
$invalid_position = true;
|
||||
} else if ($char !== null && $char !== 1) {
|
||||
$invalid_position = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($invalid_position) {
|
||||
$warning = $this->renderLine(
|
||||
$start,
|
||||
pht(
|
||||
'(This message was raised at line %s, but the file only has '.
|
||||
'%s line(s).)',
|
||||
new PhutilNumber($start),
|
||||
new PhutilNumber($max_old)),
|
||||
false,
|
||||
'?');
|
||||
|
||||
return $warning."\n\n";
|
||||
}
|
||||
|
||||
if ($message->isPatchable()) {
|
||||
$patch_offset = $line_map[$line] + ($char - 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue