Page MenuHomePhabricator

D21357.diff
No OneTemporary

D21357.diff

diff --git a/src/lint/renderer/ArcanistConsoleLintRenderer.php b/src/lint/renderer/ArcanistConsoleLintRenderer.php
--- a/src/lint/renderer/ArcanistConsoleLintRenderer.php
+++ b/src/lint/renderer/ArcanistConsoleLintRenderer.php
@@ -122,6 +122,41 @@
$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);

File Metadata

Mime Type
text/plain
Expires
Sun, May 12, 3:05 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6287656
Default Alt Text
D21357.diff (1 KB)

Event Timeline