Changeset View
Changeset View
Standalone View
Standalone View
src/lint/renderer/ArcanistConsoleLintRenderer.php
| <?php | <?php | ||||
| /** | |||||
| * Shows lint messages to the user. | |||||
| */ | |||||
| final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer { | final class ArcanistConsoleLintRenderer extends ArcanistLintRenderer { | ||||
| private $showAutofixPatches = false; | const RENDERERKEY = 'console'; | ||||
| private $testableMode; | |||||
| public function setShowAutofixPatches($show_autofix_patches) { | private $testableMode; | ||||
| $this->showAutofixPatches = $show_autofix_patches; | |||||
| return $this; | |||||
| } | |||||
| public function setTestableMode($testable_mode) { | public function setTestableMode($testable_mode) { | ||||
| $this->testableMode = $testable_mode; | $this->testableMode = $testable_mode; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getTestableMode() { | public function getTestableMode() { | ||||
| return $this->testableMode; | return $this->testableMode; | ||||
| } | } | ||||
| public function supportsPatching() { | |||||
| return true; | |||||
| } | |||||
| public function renderResultCode($result_code) { | |||||
| if ($result_code == ArcanistLintWorkflow::RESULT_OKAY) { | |||||
| $view = new PhutilConsoleInfo( | |||||
| pht('OKAY'), | |||||
| pht('No lint messages.')); | |||||
| $this->writeOut($view->drawConsoleString()); | |||||
| } | |||||
| } | |||||
| public function promptForPatch( | |||||
| ArcanistLintResult $result, | |||||
| $old_path, | |||||
| $new_path) { | |||||
| if ($old_path === null) { | |||||
| $old_path = '/dev/null'; | |||||
| } | |||||
| list($err, $stdout) = exec_manual('diff -u %s %s', $old_path, $new_path); | |||||
| $this->writeOut($stdout); | |||||
| $prompt = pht( | |||||
| 'Apply this patch to %s?', | |||||
| tsprintf('__%s__', $result->getPath())); | |||||
| return phutil_console_confirm($prompt, $default_no = false); | |||||
| } | |||||
| public function renderLintResult(ArcanistLintResult $result) { | public function renderLintResult(ArcanistLintResult $result) { | ||||
| $messages = $result->getMessages(); | $messages = $result->getMessages(); | ||||
| $path = $result->getPath(); | $path = $result->getPath(); | ||||
| $data = $result->getData(); | $data = $result->getData(); | ||||
| $line_map = $this->newOffsetMap($data); | $line_map = $this->newOffsetMap($data); | ||||
| $text = array(); | $text = array(); | ||||
| foreach ($messages as $message) { | foreach ($messages as $message) { | ||||
| if (!$this->showAutofixPatches && $message->isAutofix()) { | |||||
| continue; | |||||
| } | |||||
| if ($message->isError()) { | if ($message->isError()) { | ||||
| $color = 'red'; | $color = 'red'; | ||||
| } else { | } else { | ||||
| $color = 'yellow'; | $color = 'yellow'; | ||||
| } | } | ||||
| $severity = ArcanistLintSeverity::getStringForSeverity( | $severity = ArcanistLintSeverity::getStringForSeverity( | ||||
| $message->getSeverity()); | $message->getSeverity()); | ||||
| Show All 26 Lines | public function renderLintResult(ArcanistLintResult $result) { | ||||
| } | } | ||||
| if ($text) { | if ($text) { | ||||
| $prefix = phutil_console_format( | $prefix = phutil_console_format( | ||||
| "**>>>** %s\n\n\n", | "**>>>** %s\n\n\n", | ||||
| pht( | pht( | ||||
| 'Lint for %s:', | 'Lint for %s:', | ||||
| phutil_console_format('__%s__', $path))); | phutil_console_format('__%s__', $path))); | ||||
| return $prefix.implode("\n", $text); | $this->writeOut($prefix.implode("\n", $text)); | ||||
| } else { | |||||
| return null; | |||||
| } | } | ||||
| } | } | ||||
| protected function renderContext( | protected function renderContext( | ||||
| ArcanistLintMessage $message, | ArcanistLintMessage $message, | ||||
| $data, | $data, | ||||
| array $line_map) { | array $line_map) { | ||||
| ▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | protected function renderLine($line, $data, $chevron = false, $diff = null) { | ||||
| return sprintf( | return sprintf( | ||||
| ' %3s %1s %6s %s', | ' %3s %1s %6s %s', | ||||
| $chevron, | $chevron, | ||||
| $diff, | $diff, | ||||
| $line, | $line, | ||||
| $data); | $data); | ||||
| } | } | ||||
| public function renderOkayResult() { | |||||
| return phutil_console_format( | |||||
| "<bg:green>** %s **</bg> %s\n", | |||||
| pht('OKAY'), | |||||
| pht('No lint warnings.')); | |||||
| } | |||||
| private function newOffsetMap($data) { | private function newOffsetMap($data) { | ||||
| $lines = phutil_split_lines($data); | $lines = phutil_split_lines($data); | ||||
| $line_map = array(); | $line_map = array(); | ||||
| $number = 1; | $number = 1; | ||||
| $offset = 0; | $offset = 0; | ||||
| foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
| Show All 17 Lines | |||||