$stopped = array();
$linters = $this->buildLinters();
- if (!$linters) {
- throw new ArcanistNoEffectException("No linters to run.");
- }
-
- $have_paths = false;
- foreach ($linters as $linter) {
- if ($linter->getPaths()) {
- $have_paths = true;
- break;
- }
- }
-
- if (!$have_paths) {
- throw new ArcanistNoEffectException("No paths are lintable.");
- }
-
$exceptions = array();
foreach ($linters as $linter_name => $linter) {
try {
}
}
+ if (!$linters) {
+ throw new ArcanistNoEffectException("No linters to run.");
+ }
+
+ $have_paths = false;
+ foreach ($linters as $linter) {
+ if ($linter->getPaths()) {
+ $have_paths = true;
+ break;
+ }
+ }
+
+ if (!$have_paths) {
+ throw new ArcanistNoEffectException("No paths are lintable.");
+ }
+
if ($exceptions) {
throw new PhutilAggregateException('Some linters failed:', $exceptions);
}
return false;
}
- private function getResultForPath($path) {
+ public function getResultForPath($path) {
if (empty($this->results[$path])) {
$result = new ArcanistLintResult();
$result->setPath($path);
return $this;
}
+ public function getCacheVersion() {
+ return 0;
+ }
+
protected function getPEP8WithTextOptions() {
// E101 is subset of TXT2 (Tab Literal).
// E501 is same as TXT3 (Line Too Long).
array_keys(ArcanistLintSeverity::getLintSeverities())).
"'. Defaults to '".self::DEFAULT_SEVERITY."'.",
),
+ 'cache' => array(
+ 'param' => 'bool',
+ 'help' => "0 to disable cache (default), 1 to enable.",
+ ),
'*' => 'paths',
);
}
return true;
}
+ private function getCacheKey() {
+ return implode("\n", array(
+ get_class($this->engine),
+ $this->getArgument('severity', self::DEFAULT_SEVERITY),
+ $this->getArgument('lintall'),
+ $this->engine->getCacheVersion(),
+ ));
+ }
+
public function run() {
$working_copy = $this->getWorkingCopy();
$engine->setMinimumSeverity(
$this->getArgument('severity', self::DEFAULT_SEVERITY));
+ $cached = false;
+ if ($this->getArgument('cache')) {
+ $paths = array_combine($paths, $paths);
+ $cache = $this->readScratchJSONFile('lint-cache.json');
+ $cache = idx($cache, $this->getCacheKey(), array());
+ foreach ($cache as $path => $messages) {
+ $messages = idx($messages, md5_file($engine->getFilePathOnDisk($path)));
+ // TODO: Some linters work with the whole directory.
+ if ($messages !== null) {
+ foreach ($messages as $message) {
+ $engine->getResultForPath($path)->addMessage(
+ ArcanistLintMessage::newFromDictionary($message));
+ }
+ $cached = true;
+ unset($paths[$path]);
+ }
+ }
+ }
+
// Propagate information about which lines changed to the lint engine.
// This is used so that the lint engine can drop warning messages
// concerning lines that weren't in the change.
try {
$engine->run();
} catch (Exception $ex) {
- $failed = $ex;
+ if ($ex instanceof ArcanistNoEffectException && $cached) {
+ // Swallow.
+ } else {
+ $failed = $ex;
+ }
}
$results = $engine->getResults();
}
$this->unresolvedMessages = $unresolved;
+ if ($this->getArgument('cache')) {
+ $cached = array();
+ foreach ($results as $result) {
+ $path = $result->getPath();
+ $hash = md5_file($engine->getFilePathOnDisk($path));
+ $cached[$path] = array($hash => array());
+ foreach ($result->getMessages() as $message) {
+ if (!$message->isPatchApplied()) {
+ $cached[$path][$hash][] = $message->toDictionary();
+ }
+ }
+ }
+ $cache = $this->readScratchJSONFile('lint-cache.json');
+ $cache[$this->getCacheKey()] = $cached;
+ // TODO: Garbage collection.
+ $this->writeScratchJSONFile('lint-cache.json', $cache);
+ }
+
// Take the most severe lint message severity and use that
// as the result code.
if ($has_errors) {