Exemplo n.º 1
0
 public final function isSeverityEnabled($severity)
 {
     $minimum = $this->minimumSeverity;
     return ArcanistLintSeverity::isAtLeastAsSevere($severity, $minimum);
 }
Exemplo n.º 2
0
 public function run()
 {
     $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.");
     }
     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]);
             }
         }
         $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;
             }
             // When a user runs "arc lint", we default to raising only warnings on
             // lines they have changed (errors are still raised anywhere in the
             // file). The list of $changed lines may be null, to indicate that the
             // path is a directory or a binary file so we should not exclude
             // warnings.
             $changed = $this->getPathChangedLines($message->getPath());
             if ($changed !== null && !$message->isError() && $message->getLine()) {
                 if (empty($changed[$message->getLine()])) {
                     continue;
                 }
             }
             $result = $this->getResultForPath($message->getPath());
             $result->addMessage($message);
         }
     }
     foreach ($this->results as $path => $result) {
         $disk_path = $this->getFilePathOnDisk($path);
         $result->setFilePathOnDisk($disk_path);
         if (isset($this->fileData[$path])) {
             $result->setData($this->fileData[$path]);
         } else {
             if ($disk_path && Filesystem::pathExists($disk_path)) {
                 // TODO: this may cause us to, e.g., load a large binary when we only
                 // raised an error about its filename. We could refine this by looking
                 // through the lint messages and doing this load only if any of them
                 // have original/replacement text or something like that.
                 try {
                     $this->fileData[$path] = Filesystem::readFile($disk_path);
                     $result->setData($this->fileData[$path]);
                 } catch (FilesystemException $ex) {
                     // Ignore this, it's noncritical that we access this data and it
                     // might be unreadable or a directory or whatever else for plenty
                     // of legitimate reasons.
                 }
             }
         }
     }
     return $this->results;
 }