]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Make lint output look like a compiler
authorEdward Speyer <edward@fb.com>
Wed, 29 Jun 2011 01:14:07 +0000 (18:14 -0700)
committerEdward Speyer <edward@fb.com>
Fri, 9 Mar 2012 19:20:08 +0000 (11:20 -0800)
Summary:
Make lint output look like gcc errors / grep output; a format used by
editors to jump from a compiler error to a file+line of code which
triggered the error.

Test Plan:
In vim, I ran:

  :set makeprg=~/checkouts/devtools/arcanist/bin/arc\ lint\ --output\ compiler

Then:

  :make

And was able to jump directly to problematic lines of code.

Reviewers: jungejason

Reviewed By: jungejason

CC: aran, edwardspeyer, jungejason, codeblock, tuomaspelkonen, epriestley
Differential Revision: https://secure.phabricator.com/D550

src/lint/renderer/ArcanistLintLikeCompilerRenderer.php [new file with mode: 0644]
src/lint/renderer/__init__.php
src/workflow/lint/ArcanistLintWorkflow.php

diff --git a/src/lint/renderer/ArcanistLintLikeCompilerRenderer.php b/src/lint/renderer/ArcanistLintLikeCompilerRenderer.php
new file mode 100644 (file)
index 0000000..53316aa
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * Copyright 2012 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
+ */
+final class ArcanistLintLikeCompilerRenderer {
+  public function renderLintResult(ArcanistLintResult $result) {
+    $lines = array();
+    $messages = $result->getMessages();
+    $path = $result->getPath();
+
+    foreach ($messages as $message) {
+      $severity = ArcanistLintSeverity::getStringForSeverity(
+        $message->getSeverity());
+      $line = $message->getLine();
+      $code = $message->getCode();
+      $description = $message->getDescription();
+      $lines[] = sprintf(
+        "%s:%d:%s (%s) %s\n",
+        $path,
+        $line,
+        $severity,
+        $code,
+        $description
+      );
+    }
+
+    return implode('', $lines);
+  }
+
+  public function renderOkayResult() {
+    return "";
+  }
+}
index 23f3b9606d5c186d7a4be395b23bd94327d48131..8837258ec0729d9768cf9b41edfa90b29bcd9895 100644 (file)
@@ -12,6 +12,7 @@ phutil_require_module('phutil', 'console');
 phutil_require_module('phutil', 'utils');
 
 
+phutil_require_source('ArcanistLintJSONRenderer.php');
+phutil_require_source('ArcanistLintLikeCompilerRenderer.php');
 phutil_require_source('ArcanistLintRenderer.php');
 phutil_require_source('ArcanistLintSummaryRenderer.php');
-phutil_require_source('ArcanistLintJSONRenderer.php');
index 93c824330c3c9b672e73e8246d703a050f5563a9..b53c87ba82d28cc01945c2babd5f74b6c65171ae 100644 (file)
@@ -74,7 +74,8 @@ EOTEXT
         'param' => 'format',
         'help' =>
           "With 'summary', show lint warnings in a more compact format. ".
-          "With 'json', show lint warnings in machine-readable JSON format."
+          "With 'json', show lint warnings in machine-readable JSON format. ".
+          "With 'compiler', show lint warnings in suitable for your editor."
       ),
       'advice' => array(
         'help' =>
@@ -196,6 +197,11 @@ EOTEXT
       case 'summary':
         $renderer = new ArcanistLintSummaryRenderer();
         break;
+      case 'compiler':
+        $renderer = new ArcanistLintLikeCompilerRenderer();
+        $prompt_patches = false;
+        $apply_patches = $this->getArgument('apply-patches');
+        break;
       default:
         $renderer = new ArcanistLintRenderer();
         break;