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 @@ -6,12 +6,22 @@ final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer { private $showAutofixPatches = false; + private $testableMode; public function setShowAutofixPatches($show_autofix_patches) { $this->showAutofixPatches = $show_autofix_patches; return $this; } + public function setTestableMode($testable_mode) { + $this->testableMode = $testable_mode; + return $this; + } + + public function getTestableMode() { + return $this->testableMode; + } + public function renderLintResult(ArcanistLintResult $result) { $messages = $result->getMessages(); $path = $result->getPath(); @@ -90,6 +100,7 @@ $old = $data; $old_lines = phutil_split_lines($old); + $old_impact = substr_count($original, "\n") + 1; $start = $line; if ($message->isPatchable()) { @@ -105,9 +116,26 @@ // Figure out how many "-" and "+" lines we have by counting the newlines // for the relevant patches. This may overestimate things if we are adding // or removing entire lines, but we'll adjust things below. - $old_impact = substr_count($original, "\n") + 1; $new_impact = substr_count($replacement, "\n") + 1; + + // If this is a change on a single line, we'll try to highlight the + // changed character range to make it easier to pick out. + if ($old_impact === 1 && $new_impact === 1) { + $old_lines[$start - 1] = substr_replace( + $old_lines[$start - 1], + $this->highlightText($original), + $char - 1, + strlen($original)); + + $new_lines[$start - 1] = substr_replace( + $new_lines[$start - 1], + $this->highlightText($replacement), + $char - 1, + strlen($replacement)); + } + + // If lines at the beginning of the changed line range are actually the // same, shrink the range. This happens when a patch just adds a line. do { @@ -154,6 +182,18 @@ } while (true); } else { + + // If we have "original" text and it is contained on a single line, + // highlight the affected area. If we don't have any text, we'll mark + // the character with a caret (below, in rendering) instead. + if ($old_impact == 1 && strlen($original)) { + $old_lines[$start - 1] = substr_replace( + $old_lines[$start - 1], + $this->highlightText($original), + $char - 1, + strlen($original)); + } + $old_impact = 0; $new_impact = 0; } @@ -263,4 +303,12 @@ return $line_map; } + private function highlightText($text) { + if ($this->getTestableMode()) { + return '>'.$text.'<'; + } else { + return (string)tsprintf('##%s##', $text); + } + } + } diff --git a/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php b/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php --- a/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php +++ b/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php @@ -61,6 +61,12 @@ 'name' => 'Fruit Misinformation', 'description' => 'Arguably untrue.', ), + + 'original' => array( + 'line' => 1, + 'char' => 4, + 'original' => 'should of', + ), ); $defaults = array( @@ -105,7 +111,8 @@ ->setData($data) ->addMessage($message); - $renderer = new ArcanistConsoleLintRenderer(); + $renderer = id(new ArcanistConsoleLintRenderer()) + ->setTestableMode(true); try { PhutilConsoleFormatter::disableANSI(true); diff --git a/src/lint/renderer/__tests__/data/inline.expect b/src/lint/renderer/__tests__/data/inline.expect --- a/src/lint/renderer/__tests__/data/inline.expect +++ b/src/lint/renderer/__tests__/data/inline.expect @@ -4,5 +4,5 @@ Warning (WARN123) Lint Warning Consider this. - >>> - 1 adjudicated - + adjudidoged + >>> - 1 adjudi>catdog>> - 1 tantawount - + tantamount + >>> 1 He >should of< known. diff --git a/src/lint/renderer/__tests__/data/original.txt b/src/lint/renderer/__tests__/data/original.txt new file mode 100644 --- /dev/null +++ b/src/lint/renderer/__tests__/data/original.txt @@ -0,0 +1 @@ +He should of known. diff --git a/src/lint/renderer/__tests__/data/overlap.expect b/src/lint/renderer/__tests__/data/overlap.expect --- a/src/lint/renderer/__tests__/data/overlap.expect +++ b/src/lint/renderer/__tests__/data/overlap.expect @@ -4,5 +4,5 @@ Warning (WARN123) Lint Warning Consider this. - >>> - 1 tantawount - + tantamount + >>> - 1 tanta>wm>> - 1 a - + z + >>> - 1 >a< + + >z< 2 b 3 c