From a83cb43d08a79c536678899d753de623a0dcda4d Mon Sep 17 00:00:00 2001 From: vrana Date: Mon, 5 Nov 2012 20:23:38 -0800 Subject: [PATCH] Move conversion to dictionary inside lint message Summary: Maybe I will need it on other places. Test Plan: $ arc lint --output json # on file with lint error Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3898 --- src/lint/ArcanistLintMessage.php | 12 +++++++++++ .../renderer/ArcanistLintJSONRenderer.php | 20 +++++++------------ src/workflow/ArcanistDiffWorkflow.php | 10 +--------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/lint/ArcanistLintMessage.php b/src/lint/ArcanistLintMessage.php index 6da5a0d8..89a8fd1e 100644 --- a/src/lint/ArcanistLintMessage.php +++ b/src/lint/ArcanistLintMessage.php @@ -39,6 +39,18 @@ final class ArcanistLintMessage { return $message; } + public function toDictionary() { + return array( + 'path' => $this->getPath(), + 'line' => $this->getLine(), + 'char' => $this->getChar(), + 'code' => $this->getCode(), + 'severity' => $this->getSeverity(), + 'name' => $this->getName(), + 'description' => $this->getDescription(), + ); + } + public function setPath($path) { $this->path = $path; return $this; diff --git a/src/lint/renderer/ArcanistLintJSONRenderer.php b/src/lint/renderer/ArcanistLintJSONRenderer.php index 1c038841..ce824224 100644 --- a/src/lint/renderer/ArcanistLintJSONRenderer.php +++ b/src/lint/renderer/ArcanistLintJSONRenderer.php @@ -17,19 +17,13 @@ final class ArcanistLintJSONRenderer implements ArcanistLintRenderer { $output = array($path => array()); foreach ($messages as $message) { - $output[$path][] = array( - 'code' => $message->getCode(), - 'name' => $message->getName(), - 'severity' => $message->getSeverity(), - 'line' => $message->getLine(), - 'char' => $message->getChar(), - 'context' => implode("\n", array_slice( - $data, - max(1, $message->getLine() - self::LINES_OF_CONTEXT), - self::LINES_OF_CONTEXT * 2 + 1 - )), - 'description' => $message->getDescription(), - ); + $dictionary = $message->toDictionary(); + $dictionary['context'] = implode("\n", array_slice( + $data, + max(1, $message->getLine() - self::LINES_OF_CONTEXT), + self::LINES_OF_CONTEXT * 2 + 1)); + unset($dictionary['path']); + $output[$path][] = $dictionary; } return json_encode($output)."\n"; diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 08163d3f..43c049e5 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -1264,15 +1264,7 @@ EOTEXT $this->unresolvedLint = array(); foreach ($lint_workflow->getUnresolvedMessages() as $message) { - $this->unresolvedLint[] = array( - 'path' => $message->getPath(), - 'line' => $message->getLine(), - 'char' => $message->getChar(), - 'code' => $message->getCode(), - 'severity' => $message->getSeverity(), - 'name' => $message->getName(), - 'description' => $message->getDescription(), - ); + $this->unresolvedLint[] = $message->toDictionary(); } $this->postponedLinters = $lint_workflow->getPostponedLinters(); -- 2.43.0