--- /dev/null
+<?php
+
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Shows lint messages to the user.
+ *
+ * @group lint
+ */
+class ArcanistLintJSONRenderer {
+ const LINES_OF_CONTEXT = 3;
+
+ public function renderLintResult(ArcanistLintResult $result) {
+ $messages = $result->getMessages();
+ $path = $result->getPath();
+ $data = explode("\n", $result->getData());
+ array_unshift($data, ''); // make the line numbers work as array indices
+
+ $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,
+ $message->getLine() - self::LINES_OF_CONTEXT,
+ self::LINES_OF_CONTEXT * 2 + 1
+ )),
+ );
+ }
+
+ return json_encode($output)."\n";
+ }
+}
* @group lint
*/
class ArcanistLintRenderer {
-
- private $summaryMode;
-
- public function setSummaryMode($mode) {
- $this->summaryMode = $mode;
- }
-
public function renderLintResult(ArcanistLintResult $result) {
- if ($this->summaryMode) {
- return $this->renderResultSummary($result);
- } else {
- return $this->renderResultFull($result);
- }
- }
-
- protected function renderResultFull(ArcanistLintResult $result) {
$messages = $result->getMessages();
$path = $result->getPath();
$lines = explode("\n", $result->getData());
return implode("\n", $text);
}
- protected function renderResultSummary(ArcanistLintResult $result) {
- $messages = $result->getMessages();
- $path = $result->getPath();
-
- $text = array();
- $text[] = $path.":";
- foreach ($messages as $message) {
- $name = $message->getName();
- $severity = ArcanistLintSeverity::getStringForSeverity(
- $message->getSeverity());
- $line = $message->getLine();
-
- $text[] = " {$severity} on line {$line}: {$name}";
- }
- $text[] = null;
-
- return implode("\n", $text);
- }
-
-
protected function renderContext(
ArcanistLintMessage $message,
array $line_data) {
$line,
$data);
}
-
}
--- /dev/null
+<?php
+
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Shows lint messages to the user.
+ *
+ * @group lint
+ */
+class ArcanistLintSummaryRenderer {
+ public function renderLintResult(ArcanistLintResult $result) {
+ $messages = $result->getMessages();
+ $path = $result->getPath();
+
+ $text = array();
+ $text[] = $path.":";
+ foreach ($messages as $message) {
+ $name = $message->getName();
+ $severity = ArcanistLintSeverity::getStringForSeverity(
+ $message->getSeverity());
+ $line = $message->getLine();
+
+ $text[] = " {$severity} on line {$line}: {$name}";
+ }
+ $text[] = null;
+
+ return implode("\n", $text);
+ }
+}
phutil_require_source('ArcanistLintRenderer.php');
+phutil_require_source('ArcanistLintSummaryRenderer.php');
+phutil_require_source('ArcanistLintJSONRenderer.php');
'help' =>
"Show all lint warnings, not just those on changed lines."
),
- 'summary' => array(
+ 'output' => array(
+ 'param' => 'format',
'help' =>
- "Show lint warnings in a more compact format."
+ "With 'summary', show lint warnings in a more compact format. ".
+ "With 'json', show lint warnings in machine-readable JSON format."
),
'advice' => array(
'help' =>
$wrote_to_disk = false;
- $renderer = new ArcanistLintRenderer();
- if ($this->getArgument('summary')) {
- $renderer->setSummaryMode(true);
+ switch ($this->getArgument('output')) {
+ case 'json':
+ $renderer = new ArcanistLintJSONRenderer();
+ break;
+ case 'summary':
+ $renderer = new ArcanistLintSummaryRenderer();
+ break;
+ default:
+ $renderer = new ArcanistLintRenderer();
+ break;
}
+
foreach ($results as $result) {
if (!$result->getMessages()) {
continue;