]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Render chevrons and carets in lint output for messages without "original" text
authorepriestley <git@epriestley.com>
Fri, 1 Jun 2012 22:53:16 +0000 (15:53 -0700)
committerepriestley <git@epriestley.com>
Fri, 1 Jun 2012 22:53:16 +0000 (15:53 -0700)
Summary:
If a message has only "line", or "line" and "char", we don't point out the location in the context block.

When a message includes "line", show chevrons on the line.
When a message includes "line" and "char", show chevrons on the line and a caret on the next line.

Test Plan: Ran regex linters to capture line, line+char, and normal linters to capture everything. Output appeared sane.

Reviewers: csilvers, vrana, btrahan

Reviewed By: csilvers

CC: aran
Differential Revision: https://secure.phabricator.com/D2642

src/lint/ArcanistLintRenderer.php
src/lint/linter/ArcanistScriptAndRegexLinter.php

index c4a7d702b9775c302e6e1fd73813ee6cb3fee077..3f9cb480a18e14f6170403077b4f8a9398f63271 100644 (file)
@@ -204,13 +204,33 @@ final class ArcanistLintRenderer {
 
     $end = min($num_lines, $cursor + $lines_of_context);
     for (; $cursor < $end; $cursor++) {
-      $out[] = $this->renderLine($cursor, $line_data[$cursor]);
+      // If there is no original text, we didn't print out a chevron or any
+      // highlighted text above, so print it out here. This allows messages
+      // which don't have any original/replacement information to still
+      // render with indicator chevrons.
+      if ($text || $message->isPatchable()) {
+        $chevron = false;
+      } else {
+        $chevron = ($cursor == $line_num);
+      }
+      $out[] = $this->renderLine($cursor, $line_data[$cursor], $chevron);
+
+      // With original text, we'll render the text highlighted above. If the
+      // lint message only has a line/char offset there's nothing to
+      // highlight, so print out a caret on the next line instead.
+      if ($chevron && $message->getChar()) {
+        $out[] = $this->renderCaret($message->getChar());
+      }
     }
     $out[] = null;
 
     return implode("\n", $out);
   }
 
+  private function renderCaret($pos) {
+    return str_repeat(' ', 16 + $pos).'^';
+  }
+
   protected function renderLine($line, $data, $chevron = false, $diff = null) {
     $chevron = $chevron ? '>>>' : '';
     return sprintf(
index 5bbcabf9e8f880a5af31884dae51599d979077b1..da4891fd4a0aa0a017eae8ce403eb4bfee5df2fb 100644 (file)
@@ -312,7 +312,7 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
     }
 
     $line = idx($match, 'line', 1);
-    $char = idx($match, 'char', 1);
+    $char = idx($match, 'char');
 
     return array($line, $char);
   }