From: vrana Date: Fri, 11 Jan 2013 22:11:38 +0000 (-0800) Subject: Add hook after running linters X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ff73a9048253d8749e5042e2c825ab769fb189ef;p=arcanist.git Add hook after running linters 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 --- diff --git a/src/lint/engine/ArcanistLintEngine.php b/src/lint/engine/ArcanistLintEngine.php index 9025b839..fd5816eb 100644 --- a/src/lint/engine/ArcanistLintEngine.php +++ b/src/lint/engine/ArcanistLintEngine.php @@ -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 diff --git a/src/lint/linter/ArcanistLinter.php b/src/lint/linter/ArcanistLinter.php index eb2b9d9d..776dded8 100644 --- a/src/lint/linter/ArcanistLinter.php +++ b/src/lint/linter/ArcanistLinter.php @@ -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(); }