mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 08:52:39 +01:00
Print lint results before throwing
Summary: When some linter throws then we don't print any result. This is bad in case when the linter threw e.g. because of syntax error in some file which some other linter will tell us about. Test Plan: Threw from a linter, made lint error in a file, saw error then exception. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3756
This commit is contained in:
parent
134e9e5b4d
commit
d09eb881a3
2 changed files with 55 additions and 31 deletions
|
@ -196,44 +196,49 @@ abstract class ArcanistLintEngine {
|
|||
throw new ArcanistNoEffectException("No paths are lintable.");
|
||||
}
|
||||
|
||||
$exceptions = array();
|
||||
foreach ($linters as $linter) {
|
||||
$linter->setEngine($this);
|
||||
if (!$linter->canRun()) {
|
||||
continue;
|
||||
}
|
||||
$paths = $linter->getPaths();
|
||||
|
||||
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]);
|
||||
try {
|
||||
$linter->setEngine($this);
|
||||
if (!$linter->canRun()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$paths = array_values($paths);
|
||||
$paths = $linter->getPaths();
|
||||
|
||||
if ($paths) {
|
||||
$linter->willLintPaths($paths);
|
||||
foreach ($paths as $path) {
|
||||
$linter->willLintPath($path);
|
||||
$linter->lintPath($path);
|
||||
if ($linter->didStopAllLinters()) {
|
||||
$stopped[$path] = true;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$paths = array_values($paths);
|
||||
|
||||
$minimum = $this->minimumSeverity;
|
||||
foreach ($linter->getLintMessages() as $message) {
|
||||
if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
|
||||
continue;
|
||||
if ($paths) {
|
||||
$linter->willLintPaths($paths);
|
||||
foreach ($paths as $path) {
|
||||
$linter->willLintPath($path);
|
||||
$linter->lintPath($path);
|
||||
if ($linter->didStopAllLinters()) {
|
||||
$stopped[$path] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$this->isRelevantMessage($message)) {
|
||||
continue;
|
||||
|
||||
$minimum = $this->minimumSeverity;
|
||||
foreach ($linter->getLintMessages() as $message) {
|
||||
if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isRelevantMessage($message)) {
|
||||
continue;
|
||||
}
|
||||
$result = $this->getResultForPath($message->getPath());
|
||||
$result->addMessage($message);
|
||||
}
|
||||
$result = $this->getResultForPath($message->getPath());
|
||||
$result->addMessage($message);
|
||||
} catch (Exception $ex) {
|
||||
$exceptions[] = $ex;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,6 +263,14 @@ abstract class ArcanistLintEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if ($exceptions) {
|
||||
throw new PhutilAggregateException('Some linters failed:', $exceptions);
|
||||
}
|
||||
|
||||
return $this->results;
|
||||
}
|
||||
|
||||
public function getResults() {
|
||||
return $this->results;
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,14 @@ EOTEXT
|
|||
$engine->setEnableAsyncLint(false);
|
||||
}
|
||||
|
||||
$results = $engine->run();
|
||||
$failed = null;
|
||||
try {
|
||||
$engine->run();
|
||||
} catch (Exception $ex) {
|
||||
$failed = $ex;
|
||||
}
|
||||
|
||||
$results = $engine->getResults();
|
||||
|
||||
// It'd be nice to just return a single result from the run method above
|
||||
// which contains both the lint messages and the postponed linters.
|
||||
|
@ -309,6 +316,10 @@ EOTEXT
|
|||
}
|
||||
}
|
||||
|
||||
if ($failed) {
|
||||
throw $failed;
|
||||
}
|
||||
|
||||
$repository_api = $this->getRepositoryAPI();
|
||||
if ($wrote_to_disk &&
|
||||
($repository_api instanceof ArcanistGitAPI) &&
|
||||
|
|
Loading…
Reference in a new issue