]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add hook after running linters
authorvrana <jakubv@fb.com>
Fri, 11 Jan 2013 22:11:38 +0000 (14:11 -0800)
committervrana <jakubv@fb.com>
Fri, 11 Jan 2013 22:15:04 +0000 (14:15 -0800)
Summary: This resolves D4380#7 by reverting https://secure.phabricator.com/D4380?vs=9112&id=9123.

Test Plan: Used it in our linters.

Reviewers: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D4409

src/lint/engine/ArcanistLintEngine.php
src/lint/linter/ArcanistLinter.php

index 9025b839eb45dd2eb901d16704ac59f0353d4093..fd5816eba6227ddffbea7015d5ec6d4f289da12a 100644 (file)
@@ -188,63 +188,44 @@ abstract class ArcanistLintEngine {
     }
     $this->cacheVersion = crc32(implode("\n", $versions));
 
-    $linters_paths = array();
-    foreach ($linters as $linter_name => $linter) {
-      $linter->setEngine($this);
-      if (!$linter->canRun()) {
-        continue;
-      }
-      $paths = $linter->getPaths();
-
-      $cache_granularity = $linter->getCacheGranularity();
-
-      foreach ($paths as $key => $path) {
-        // Make sure each path has a result generated, even if it is empty
-        // (i.e., the file has no lint messages).
-        $result = $this->getResultForPath($path);
-        if (isset($this->cachedResults[$path][$this->cacheVersion])) {
-          if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
-            unset($paths[$key]);
-          }
-        }
-      }
-      $paths = array_values($paths);
-      $linters_paths[$linter_name] = $paths;
-
-      if ($paths) {
-        $linter->willLintPaths($paths);
-      }
-    }
-
     $stopped = array();
     $exceptions = array();
     foreach ($linters as $linter_name => $linter) {
       try {
-        foreach ($linters_paths[$linter_name] as $path) {
-          if (isset($stopped[$path])) {
-            continue;
-          }
-          $linter->willLintPath($path);
-          $linter->lintPath($path);
-          if ($linter->didStopAllLinters()) {
-            $stopped[$path] = true;
-          }
+        $linter->setEngine($this);
+        if (!$linter->canRun()) {
+          continue;
         }
+        $paths = $linter->getPaths();
+
+        $cache_granularity = $linter->getCacheGranularity();
 
-        $minimum = $this->minimumSeverity;
-        foreach ($linter->getLintMessages() as $message) {
-          if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
-            continue;
+        foreach ($paths as $key => $path) {
+          // Make sure each path has a result generated, even if it is empty
+          // (i.e., the file has no lint messages).
+          $result = $this->getResultForPath($path);
+          if (isset($stopped[$path])) {
+            unset($paths[$key]);
           }
-          if (!$this->isRelevantMessage($message)) {
-            continue;
+          if (isset($this->cachedResults[$path][$this->cacheVersion])) {
+            if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
+              unset($paths[$key]);
+            }
           }
-          if ($cache_granularity != ArcanistLinter::GRANULARITY_FILE) {
-            $message->setUncacheable(true);
+        }
+        $paths = array_values($paths);
+
+        if ($paths) {
+          $linter->willLintPaths($paths);
+          foreach ($paths as $path) {
+            $linter->willLintPath($path);
+            $linter->lintPath($path);
+            if ($linter->didStopAllLinters()) {
+              $stopped[$path] = true;
+            }
           }
-          $result = $this->getResultForPath($message->getPath());
-          $result->addMessage($message);
         }
+
       } catch (Exception $ex) {
         if (!is_string($linter_name)) {
           $linter_name = get_class($linter);
@@ -253,6 +234,25 @@ abstract class ArcanistLintEngine {
       }
     }
 
+    $this->didRunLinters($linters);
+
+    foreach ($linters as $linter) {
+      $minimum = $this->minimumSeverity;
+      foreach ($linter->getLintMessages() as $message) {
+        if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
+          continue;
+        }
+        if (!$this->isRelevantMessage($message)) {
+          continue;
+        }
+        if ($cache_granularity != ArcanistLinter::GRANULARITY_FILE) {
+          $message->setUncacheable(true);
+        }
+        $result = $this->getResultForPath($message->getPath());
+        $result->addMessage($message);
+      }
+    }
+
     if ($this->cachedResults) {
       foreach ($this->cachedResults as $path => $messages) {
         foreach (idx($messages, $this->cacheVersion, array()) as $message) {
@@ -305,6 +305,13 @@ abstract class ArcanistLintEngine {
 
   abstract protected function buildLinters();
 
+  protected function didRunLinters(array $linters) {
+    assert_instances_of($linters, 'ArcanistLinter');
+    foreach ($linters as $linter) {
+      $linter->didRunLinters();
+    }
+  }
+
   private function isRelevantMessage(ArcanistLintMessage $message) {
     // When a user runs "arc lint", we default to raising only warnings on
     // lines they have changed (errors are still raised anywhere in the
index eb2b9d9dae3970c7a09a79d3c05e8951af55db5f..776dded842b5069a24cc185ae71192f0385e01dd 100644 (file)
@@ -206,6 +206,10 @@ abstract class ArcanistLinter {
   abstract public function lintPath($path);
   abstract public function getLinterName();
 
+  public function didRunLinters() {
+    // This is a hook.
+  }
+
   public function getLintSeverityMap() {
     return array();
   }