]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Introduce `arc lint --severity warning`
authorvrana <jakubv@fb.com>
Fri, 9 Nov 2012 03:29:40 +0000 (19:29 -0800)
committervrana <jakubv@fb.com>
Tue, 13 Nov 2012 02:17:30 +0000 (18:17 -0800)
Summary: I plan to exclude advices from our saved results.

Test Plan:
  $ arc lint src/lint/engine/PhutilLintEngine.php
  $ arc lint --severity advice src/lint/engine/PhutilLintEngine.php
  $ arc lint --severity error src/lint/engine/PhutilLintEngine.php

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Maniphest Tasks: T2038

Differential Revision: https://secure.phabricator.com/D3936

src/lint/ArcanistLintSeverity.php
src/repository/api/ArcanistGitAPI.php
src/repository/api/ArcanistMercurialAPI.php
src/repository/api/ArcanistSubversionAPI.php
src/workflow/ArcanistLintWorkflow.php

index f239e1a21f65a59f2c329425c12b6c2f70a892c9..3466cde1c8b5290a555e7be0b57a0d8a006f5e08 100644 (file)
@@ -13,14 +13,18 @@ final class ArcanistLintSeverity {
   const SEVERITY_ERROR        = 'error';
   const SEVERITY_DISABLED     = 'disabled';
 
-  public static function getStringForSeverity($severity_code) {
-    static $map = array(
+  public static function getLintSeverities() {
+    return array(
       self::SEVERITY_ADVICE   => 'Advice',
       self::SEVERITY_AUTOFIX  => 'Auto-Fix',
       self::SEVERITY_WARNING  => 'Warning',
       self::SEVERITY_ERROR    => 'Error',
       self::SEVERITY_DISABLED => 'Disabled',
     );
+  }
+
+  public static function getStringForSeverity($severity_code) {
+    $map = self::getLintSeverities();
 
     if (!array_key_exists($severity_code, $map)) {
       throw new Exception("Unknown lint severity '{$severity_code}'!");
index f1849fcd8758f742484a4fe34be84e965cf47130..1158f896a1d60fb8a6fd5a319da741b0dfdd5b6d 100644 (file)
@@ -500,7 +500,7 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     $lines = array();
     foreach (explode("\n", $status) as $line) {
       if ($line) {
-        $lines[] = preg_split("/[ \t]/", $line);
+        $lines[] = preg_split("/[ \t]/", $line, 6);
       }
     }
 
@@ -535,17 +535,9 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
 
   public function getChangedFiles($since_commit) {
     list($stdout) = $this->execxLocal(
-      'diff --name-status -z %s',
+      'diff --name-status --raw %s',
       $since_commit);
-    $return = array();
-    foreach (array_chunk(explode("\0", $stdout), 2) as $val) {
-      if (count($val) != 2) {
-        break;
-      }
-      list($status, $path) = $val;
-      $return[$path] = ($status == 'D' ? false : true);
-    }
-    return $return;
+    return $this->parseGitStatus($stdout);
   }
 
   public function getBlame($path) {
index 62573fe944aab3f9e642718a8c26541ec03b6e16..8ddd0cd7f7fe6a42f8a71e74e22c5ff350f4b9b6 100644 (file)
@@ -253,17 +253,9 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
 
   public function getChangedFiles($since_commit) {
     list($stdout) = $this->execxLocal(
-      'status --rev %s -0',
+      'status --rev %s',
       $since_commit);
-    $return = array();
-    foreach (explode("\0", $stdout) as $val) {
-      $match = null;
-      if (preg_match('/^(.) (.+)/', $val, $match)) {
-        list(, $status, $path) = $match;
-        $return[$path] = ($status == 'R' ? false : true);
-      }
-    }
-    return $return;
+    return ArcanistMercurialParser::parseMercurialStatus($stdout);
   }
 
   public function getBlame($path) {
index 30d857531601fe1855f280ae0c960dba5a998c63..b813fe41e7b362fda12011441d8a3515094888a6 100644 (file)
@@ -102,45 +102,9 @@ final class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
             throw new Exception("Unrecognized property status '{$props}'.");
         }
 
-        switch ($item) {
-          case 'normal':
-            break;
-          case 'external':
-            $mask |= self::FLAG_EXTERNALS;
-            $externals[] = $path;
-            break;
-          case 'unversioned':
-            $mask |= self::FLAG_UNTRACKED;
-            break;
-          case 'obstructed':
-            $mask |= self::FLAG_OBSTRUCTED;
-            break;
-          case 'missing':
-            $mask |= self::FLAG_MISSING;
-            break;
-          case 'added':
-            $mask |= self::FLAG_ADDED;
-            break;
-          case 'replaced':
-            // This is the result of "svn rm"-ing a file, putting another one
-            // in place of it, and then "svn add"-ing the new file. Just treat
-            // this as equivalent to "modified".
-            $mask |= self::FLAG_MODIFIED;
-            break;
-          case 'modified':
-            $mask |= self::FLAG_MODIFIED;
-            break;
-          case 'deleted':
-            $mask |= self::FLAG_DELETED;
-            break;
-          case 'conflicted':
-            $mask |= self::FLAG_CONFLICT;
-            break;
-          case 'incomplete':
-            $mask |= self::FLAG_INCOMPLETE;
-            break;
-          default:
-            throw new Exception("Unrecognized item status '{$item}'.");
+        $mask |= $this->parseSVNStatus($item);
+        if ($item == 'external') {
+          $externals[] = $path;
         }
 
         // This is new in or around Subversion 1.6.
@@ -175,6 +139,38 @@ final class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
     return $status;
   }
 
+  private function parseSVNStatus($item) {
+    switch ($item) {
+      case 'normal':
+        return 0;
+      case 'external':
+        return self::FLAG_EXTERNALS;
+      case 'unversioned':
+        return self::FLAG_UNTRACKED;
+      case 'obstructed':
+        return self::FLAG_OBSTRUCTED;
+      case 'missing':
+        return self::FLAG_MISSING;
+      case 'added':
+        return self::FLAG_ADDED;
+      case 'replaced':
+        // This is the result of "svn rm"-ing a file, putting another one
+        // in place of it, and then "svn add"-ing the new file. Just treat
+        // this as equivalent to "modified".
+        return self::FLAG_MODIFIED;
+      case 'modified':
+        return self::FLAG_MODIFIED;
+      case 'deleted':
+        return self::FLAG_DELETED;
+      case 'conflicted':
+        return self::FLAG_CONFLICT;
+      case 'incomplete':
+        return self::FLAG_INCOMPLETE;
+      default:
+        throw new Exception("Unrecognized item status '{$item}'.");
+    }
+  }
+
   public function getSVNProperty($path, $property) {
     list($stdout) = execx(
       'svn propget %s %s@',
@@ -476,15 +472,13 @@ EODIFF;
   public function getChangedFiles($since_commit) {
     // TODO: Handle paths with newlines.
     list($stdout) = $this->execxLocal(
-      'diff --revision %s:HEAD',
+      '--xml diff --revision %s:HEAD --summarize',
       $since_commit);
+    $xml = new SimpleXMLElement($stdout);
+
     $return = array();
-    foreach (explode("\n", $stdout) as $val) {
-      $match = null;
-      if (preg_match('/^(.)\S*\s+(.+)/', $val, $match)) {
-        list(, $status, $path) = $match;
-        $return[$path] = ($status == 'D' ? false : true);
-      }
+    foreach ($xml->paths[0]->path as $path) {
+      $return[(string)$path] = $this->parseSVNStatus($path['item']);
     }
     return $return;
   }
index 592c6c4e99b089ca4588a5934b77e1e1dfb0e20d..f065a45c5519a3163b3a7646d125aaef335eec4d 100644 (file)
@@ -13,6 +13,8 @@ class ArcanistLintWorkflow extends ArcanistBaseWorkflow {
   const RESULT_SKIP       = 3;
   const RESULT_POSTPONED  = 4;
 
+  const DEFAULT_SEVERITY = ArcanistLintSeverity::SEVERITY_ADVICE;
+
   private $unresolvedMessages;
   private $shouldAmendChanges = false;
   private $shouldAmendWithoutPrompt = false;
@@ -109,6 +111,15 @@ EOTEXT
           'When linting git repositories, amend HEAD with autofix '.
           'patches suggested by lint without prompting.',
       ),
+      'severity' => array(
+        'param' => 'string',
+        'help' =>
+          "Set minimum message severity. One of: '".
+          implode(
+            "', '",
+            array_keys(ArcanistLintSeverity::getLintSeverities())).
+          "'. Defaults to '".self::DEFAULT_SEVERITY."'.",
+      ),
       '*' => 'paths',
     );
   }
@@ -162,7 +173,8 @@ EOTEXT
     $this->engine = $engine;
     $engine->setWorkingCopy($working_copy);
 
-    $engine->setMinimumSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
+    $engine->setMinimumSeverity(
+      $this->getArgument('severity', self::DEFAULT_SEVERITY));
 
     // Propagate information about which lines changed to the lint engine.
     // This is used so that the lint engine can drop warning messages
@@ -300,10 +312,6 @@ EOTEXT
       }
     }
 
-    if ($failed) {
-      throw $failed;
-    }
-
     $repository_api = $this->getRepositoryAPI();
     if ($wrote_to_disk &&
         ($repository_api instanceof ArcanistGitAPI) &&
@@ -330,6 +338,15 @@ EOTEXT
       }
     }
 
+    if ($this->getArgument('output') == 'json') {
+      // NOTE: Required by save_lint.php in Phabricator.
+      return 0;
+    }
+
+    if ($failed) {
+      throw $failed;
+    }
+
     $unresolved = array();
     $has_warnings = false;
     $has_errors = false;