mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
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
This commit is contained in:
parent
5c5d347544
commit
ff73a90482
2 changed files with 59 additions and 48 deletions
|
@ -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) {
|
||||
$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($stopped[$path])) {
|
||||
continue;
|
||||
unset($paths[$key]);
|
||||
}
|
||||
$linter->willLintPath($path);
|
||||
$linter->lintPath($path);
|
||||
if ($linter->didStopAllLinters()) {
|
||||
$stopped[$path] = true;
|
||||
if (isset($this->cachedResults[$path][$this->cacheVersion])) {
|
||||
if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
|
||||
unset($paths[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
} 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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue