mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-29 18:22: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,8 +188,10 @@ abstract class ArcanistLintEngine {
|
|||
}
|
||||
$this->cacheVersion = crc32(implode("\n", $versions));
|
||||
|
||||
$linters_paths = array();
|
||||
$stopped = array();
|
||||
$exceptions = array();
|
||||
foreach ($linters as $linter_name => $linter) {
|
||||
try {
|
||||
$linter->setEngine($this);
|
||||
if (!$linter->canRun()) {
|
||||
continue;
|
||||
|
@ -202,6 +204,9 @@ abstract class ArcanistLintEngine {
|
|||
// 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 (isset($this->cachedResults[$path][$this->cacheVersion])) {
|
||||
if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
|
||||
unset($paths[$key]);
|
||||
|
@ -209,28 +214,29 @@ abstract class ArcanistLintEngine {
|
|||
}
|
||||
}
|
||||
$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;
|
||||
}
|
||||
foreach ($paths as $path) {
|
||||
$linter->willLintPath($path);
|
||||
$linter->lintPath($path);
|
||||
if ($linter->didStopAllLinters()) {
|
||||
$stopped[$path] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $ex) {
|
||||
if (!is_string($linter_name)) {
|
||||
$linter_name = get_class($linter);
|
||||
}
|
||||
$exceptions[$linter_name] = $ex;
|
||||
}
|
||||
}
|
||||
|
||||
$this->didRunLinters($linters);
|
||||
|
||||
foreach ($linters as $linter) {
|
||||
$minimum = $this->minimumSeverity;
|
||||
foreach ($linter->getLintMessages() as $message) {
|
||||
if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
|
||||
|
@ -245,12 +251,6 @@ abstract class ArcanistLintEngine {
|
|||
$result = $this->getResultForPath($message->getPath());
|
||||
$result->addMessage($message);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
if (!is_string($linter_name)) {
|
||||
$linter_name = get_class($linter);
|
||||
}
|
||||
$exceptions[$linter_name] = $ex;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->cachedResults) {
|
||||
|
@ -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