From c2788c8797118c4acf9d242bc819c24103032244 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 1 Jun 2012 15:53:16 -0700 Subject: [PATCH] Render chevrons and carets in lint output for messages without "original" text 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 | 22 ++++++++++++++++++- .../linter/ArcanistScriptAndRegexLinter.php | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/lint/ArcanistLintRenderer.php b/src/lint/ArcanistLintRenderer.php index c4a7d702..3f9cb480 100644 --- a/src/lint/ArcanistLintRenderer.php +++ b/src/lint/ArcanistLintRenderer.php @@ -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( diff --git a/src/lint/linter/ArcanistScriptAndRegexLinter.php b/src/lint/linter/ArcanistScriptAndRegexLinter.php index 5bbcabf9..da4891fd 100644 --- a/src/lint/linter/ArcanistScriptAndRegexLinter.php +++ b/src/lint/linter/ArcanistScriptAndRegexLinter.php @@ -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); } -- 2.43.0