Changeset View
Changeset View
Standalone View
Standalone View
src/lint/renderer/ArcanistJSONLintRenderer.php
| <?php | <?php | ||||
| /** | |||||
| * Shows lint messages to the user. | |||||
| */ | |||||
| final class ArcanistJSONLintRenderer extends ArcanistLintRenderer { | final class ArcanistJSONLintRenderer extends ArcanistLintRenderer { | ||||
| const RENDERERKEY = 'json'; | |||||
| const LINES_OF_CONTEXT = 3; | const LINES_OF_CONTEXT = 3; | ||||
| public function renderLintResult(ArcanistLintResult $result) { | public function renderLintResult(ArcanistLintResult $result) { | ||||
| $messages = $result->getMessages(); | $messages = $result->getMessages(); | ||||
| $path = $result->getPath(); | $path = $result->getPath(); | ||||
| $data = explode("\n", $result->getData()); | $data = explode("\n", $result->getData()); | ||||
| array_unshift($data, ''); // make the line numbers work as array indices | array_unshift($data, ''); // make the line numbers work as array indices | ||||
| $output = array($path => array()); | $output = array($path => array()); | ||||
| foreach ($messages as $message) { | foreach ($messages as $message) { | ||||
| $dictionary = $message->toDictionary(); | $dictionary = $message->toDictionary(); | ||||
| $dictionary['context'] = implode("\n", array_slice( | $dictionary['context'] = implode("\n", array_slice( | ||||
| $data, | $data, | ||||
| max(1, $message->getLine() - self::LINES_OF_CONTEXT), | max(1, $message->getLine() - self::LINES_OF_CONTEXT), | ||||
| self::LINES_OF_CONTEXT * 2 + 1)); | self::LINES_OF_CONTEXT * 2 + 1)); | ||||
| unset($dictionary['path']); | unset($dictionary['path']); | ||||
| $output[$path][] = $dictionary; | $output[$path][] = $dictionary; | ||||
| } | } | ||||
| return json_encode($output)."\n"; | $this->writeOut(json_encode($output)."\n"); | ||||
| } | |||||
| public function renderOkayResult() { | |||||
| return ''; | |||||
| } | } | ||||
| } | } | ||||