protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $dom = new DOMDocument();
     $ok = @$dom->loadXML($stderr);
     if (!$ok) {
         return false;
     }
     $errors = $dom->getElementsByTagName('error');
     $messages = array();
     foreach ($errors as $error) {
         foreach ($error->getElementsByTagName('location') as $location) {
             $message = new ArcanistLintMessage();
             $message->setPath($location->getAttribute('file'));
             $message->setLine($location->getAttribute('line'));
             $message->setCode('Cppcheck');
             $message->setName($error->getAttribute('id'));
             $message->setDescription($error->getAttribute('msg'));
             switch ($error->getAttribute('severity')) {
                 case 'error':
                     $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
                     break;
                 default:
                     if ($error->getAttribute('inconclusive')) {
                         $message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
                     } else {
                         $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
                     }
                     break;
             }
             $messages[] = $message;
         }
     }
     return $messages;
 }
 public function lintPath($path)
 {
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     if (simplexml_load_string($this->getData($path))) {
         // XML appears to be valid.
         return;
     }
     foreach (libxml_get_errors() as $error) {
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($error->line);
         $message->setChar($error->column ? $error->column : null);
         $message->setCode($this->getLintMessageFullCode($error->code));
         $message->setName('LibXML Error');
         $message->setDescription(trim($error->message));
         switch ($error->level) {
             case LIBXML_ERR_NONE:
                 $message->setSeverity(ArcanistLintSeverity::SEVERITY_DISABLED);
                 break;
             case LIBXML_ERR_WARNING:
                 $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
                 break;
             case LIBXML_ERR_ERROR:
             case LIBXML_ERR_FATAL:
                 $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
                 break;
             default:
                 $message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
                 break;
         }
         $this->addLintMessage($message);
     }
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = phutil_split_lines($stdout, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         if (!preg_match('/^(.*?):(\\d+): (.*)$/', $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $severity = ArcanistLintSeverity::SEVERITY_WARNING;
         $description = $matches[3];
         $error_regexp = '/(^undefined|^duplicate|before assignment$)/';
         if (preg_match($error_regexp, $description)) {
             $severity = ArcanistLintSeverity::SEVERITY_ERROR;
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[2]);
         $message->setCode($this->getLinterName());
         $message->setDescription($description);
         $message->setSeverity($severity);
         $messages[] = $message;
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = phutil_split_lines($stderr, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         if (!preg_match('/(.*?):(\\d+): (.*?)$/', $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $code = head(explode(',', $matches[3]));
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[2]);
         $message->setCode($this->getLinterName());
         $message->setName(pht('Syntax Error'));
         $message->setDescription($matches[3]);
         $message->setSeverity($this->getLintMessageSeverity($code));
         $messages[] = $message;
     }
     if ($err && !$messages) {
         return false;
     }
     return $messages;
 }
Exemple #5
0
 private function collectResults()
 {
     while ($this->futures) {
         $f = array_shift($this->futures);
         list($err, $stdout, $stderr) = $f->resolve();
         $lines = explode("\n", $stderr);
         $messages = array();
         foreach ($lines as $line) {
             $line = trim($line);
             $matches = null;
             $regex = '/^([^:]+):(\\d+):\\s*(.*)\\s*\\[(.*)\\] \\[(\\d+)\\]$/';
             if (!preg_match($regex, $line, $matches)) {
                 continue;
             }
             foreach ($matches as $key => $match) {
                 $matches[$key] = trim($match);
             }
             $message = new ArcanistLintMessage();
             $message->setPath($matches[1]);
             $message->setLine($matches[2]);
             $message->setCode($matches[4]);
             $message->setName($matches[4]);
             $message->setDescription($matches[3]);
             $message->setSeverity($matches[5] >= 4 ? ArcanistLintSeverity::SEVERITY_ERROR : ArcanistLintSeverity::SEVERITY_WARNING);
             $this->addLintMessage($message);
         }
     }
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = phutil_split_lines($stderr, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = explode(':', $line, 6);
         if (count($matches) === 6) {
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($matches[3]);
             $message->setChar($matches[4]);
             $code = "E00";
             $message->setCode($code);
             $message->setName($this->getLinterName());
             $message->setDescription(ucfirst(trim($matches[5])));
             $severity = $this->getLintMessageSeverity($code);
             $message->setSeverity($severity);
             $messages[] = $message;
         }
         if (count($matches) === 3) {
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($matches[1]);
             $code = "E01";
             $message->setCode($code);
             $message->setName($this->getLinterName());
             $message->setDescription(ucfirst(trim($matches[2])));
             $severity = $this->getLintMessageSeverity($code);
             $message->setSeverity($severity);
             $messages[] = $message;
         }
     }
     return $messages;
 }
 public function lintPath($path)
 {
     $sbt = $this->getSBTPath();
     // Tell SBT to not use color codes so our regex life is easy.
     // TODO: Should this be "clean compile" instead of "compile"?
     $f = new ExecFuture("%s -Dsbt.log.noformat=true compile", $sbt);
     list($err, $stdout, $stderr) = $f->resolve();
     $lines = explode("\n", $stdout);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         if (!preg_match("/\\[(warn|error)\\] (.*?):(\\d+): (.*?)\$/", $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $message = new ArcanistLintMessage();
         $message->setPath($matches[2]);
         $message->setLine($matches[3]);
         $message->setCode($this->getLinterName());
         $message->setDescription($matches[4]);
         $message->setSeverity($this->getMessageCodeSeverity($matches[1]));
         $this->addLintMessage($message);
     }
 }
 public function lintPath($path)
 {
     $rubyp = $this->getRubyPath();
     $f = new ExecFuture("%s -wc", $rubyp);
     $f->write($this->getData($path));
     list($err, $stdout, $stderr) = $f->resolve();
     if ($err === 0) {
         return;
     }
     $lines = explode("\n", $stderr);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         if (!preg_match("/(.*?):(\\d+): (.*?)\$/", $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $code = head(explode(',', $matches[3]));
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[2]);
         $message->setName($this->getLinterName() . " " . $code);
         $message->setDescription($matches[3]);
         $message->setSeverity($this->getMessageCodeSeverity($code));
         $this->addLintMessage($message);
     }
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = phutil_split_lines($stdout, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         // stdin:2: W802 undefined name 'foo'  # pyflakes
         // stdin:3:1: E302 expected 2 blank lines, found 1  # pep8
         $regexp = '/^(.*?):(\\d+):(?:(\\d+):)? (\\S+) (.*)$/';
         if (!preg_match($regexp, $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[2]);
         if (!empty($matches[3])) {
             $message->setChar($matches[3]);
         }
         $message->setCode($matches[4]);
         $message->setName($this->getLinterName() . ' ' . $matches[3]);
         $message->setDescription($matches[5]);
         $message->setSeverity($this->getLintMessageSeverity($matches[4]));
         $messages[] = $message;
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = explode("\n", $stderr);
     $messages = array();
     foreach ($lines as $line) {
         $line = trim($line);
         $matches = null;
         $regex = '/^.+?:(\\d+):\\s*(.*)\\s*\\[(.*)\\] \\[(\\d+)\\]$/';
         if (!preg_match($regex, $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $severity = $this->getLintMessageSeverity($matches[3]);
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[1]);
         $message->setCode($matches[3]);
         $message->setName($matches[3]);
         $message->setDescription($matches[2]);
         $message->setSeverity($severity);
         $messages[] = $message;
     }
     return $messages;
 }
 public function lintPath($path)
 {
     $bin = $this->getLintPath();
     $path = $this->rocksdbDir() . '/' . $path;
     $f = new ExecFuture("%C {$path}", $bin);
     list($err, $stdout, $stderr) = $f->resolve();
     if ($err === 2) {
         throw new Exception("cpplint failed to run correctly:\n" . $stderr);
     }
     $lines = explode("\n", $stderr);
     $messages = array();
     foreach ($lines as $line) {
         $line = trim($line);
         $matches = null;
         $regex = '/^[^:]+:(\\d+):\\s*(.*)\\s*\\[(.*)\\] \\[(\\d+)\\]$/';
         if (!preg_match($regex, $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[1]);
         $message->setCode($matches[3]);
         $message->setName($matches[3]);
         $message->setDescription($matches[2]);
         $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
         $this->addLintMessage($message);
     }
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $report_dom = new DOMDocument();
     $ok = @$report_dom->loadXML($stdout);
     if (!$ok) {
         return false;
     }
     $files = $report_dom->getElementsByTagName('file');
     $messages = array();
     foreach ($files as $file) {
         foreach ($file->childNodes as $child) {
             if (!$child instanceof DOMElement) {
                 continue;
             }
             $data = $this->getData($path);
             $lines = explode("\n", $data);
             $name = $child->getAttribute('reason');
             $severity = $child->getAttribute('severity') == 'warning' ? ArcanistLintSeverity::SEVERITY_WARNING : ArcanistLintSeverity::SEVERITY_ERROR;
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($child->getAttribute('line'));
             $message->setChar($child->getAttribute('char'));
             $message->setCode('CSSLint');
             $message->setDescription($child->getAttribute('reason'));
             $message->setSeverity($severity);
             if ($child->hasAttribute('line') && $child->getAttribute('line') > 0) {
                 $line = $lines[$child->getAttribute('line') - 1];
                 $text = substr($line, $child->getAttribute('char') - 1);
                 $message->setOriginalText($text);
             }
             $messages[] = $message;
         }
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     // Each line looks like this:
     // Line 46, E:0110: Line too long (87 characters).
     $regex = '/^Line (\\d+), (E:\\d+): (.*)/';
     $severity_code = ArcanistLintSeverity::SEVERITY_ERROR;
     $lines = phutil_split_lines($stdout, false);
     $messages = array();
     foreach ($lines as $line) {
         $line = trim($line);
         $matches = null;
         if (!preg_match($regex, $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[1]);
         $message->setName($matches[2]);
         $message->setCode($this->getLinterName());
         $message->setDescription($matches[3]);
         $message->setSeverity($severity_code);
         $messages[] = $message;
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $ok = $err == 0;
     $lines = phutil_split_lines($stdout, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         if (!preg_match('/^(.*?):(\\d+):((\\d+):)? (\\S+): ((\\s|\\w)+): (.*)$/', $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[2]);
         if ($matches[4] != '') {
             $message->setChar($matches[4]);
         }
         $message->setCode($this->getLinterName());
         $message->setName($matches[6]);
         $message->setDescription($matches[8]);
         $message->setSeverity($this->getLintMessageSeverity($matches[5]));
         $messages[] = $message;
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $json = phutil_json_decode($stdout);
     $messages = array();
     foreach ($json as $fix) {
         if ($fix === null) {
             return;
         }
         $message = new ArcanistLintMessage();
         $message->setCode($this->getLinterName());
         $message->setPath($path);
         $message->setLine($fix['startLine']);
         $message->setChar($fix['startColumn']);
         $message->setName($fix['hint']);
         $message->setOriginalText($fix['from']);
         $message->setReplacementText($fix['to']);
         /* Some improvements may slightly change semantics, so attach
            all necessary notes too. */
         $notes = '';
         foreach ($fix['note'] as $note) {
             $notes .= phutil_console_format(' **%s**: %s.', pht('NOTE'), trim($note, '"'));
         }
         $message->setDescription(pht('In module `%s`, declaration `%s`.', $fix['module'], $fix['decl']) . $notes);
         switch ($fix['severity']) {
             case 'Error':
                 $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
                 break;
             case 'Warning':
                 $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
                 break;
             default:
                 $message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
                 break;
         }
         $messages[] = $message;
     }
     return $messages;
 }
 public static function newFromDictionary(array $dict)
 {
     $message = new ArcanistLintMessage();
     $message->setPath($dict['path']);
     $message->setLine($dict['line']);
     $message->setChar($dict['char']);
     $message->setCode($dict['code']);
     $message->setSeverity($dict['severity']);
     $message->setName($dict['name']);
     $message->setDescription($dict['description']);
     if (isset($dict['original'])) {
         $message->setOriginalText($dict['original']);
     }
     if (isset($dict['replacement'])) {
         $message->setReplacementText($dict['replacement']);
     }
     return $message;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = phutil_split_lines($stderr, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = explode(':', $line, 3);
         if (count($matches) === 3) {
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($matches[1]);
             $message->setCode($this->getLinterName());
             $message->setDescription(ucfirst(trim($matches[2])));
             $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
             $messages[] = $message;
         }
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     // Older versions of php had both on $stdout, newer ones split it
     // Combine $stdout and $stderr for consistency
     $stdout = $stderr . "\n" . $stdout;
     $matches = array();
     $regex = '/PHP (?<type>.+?) error:\\s+(?<error>.*?)\\s+in\\s+(?<file>.*?)' . '\\s+on line\\s+(?<line>\\d*)/';
     if (preg_match($regex, $stdout, $matches)) {
         $type = strtolower($matches['type']);
         $message = new ArcanistLintMessage();
         $message->setPath($matches['file']);
         $message->setLine($matches['line']);
         $message->setCode('php.' . $type);
         $message->setDescription('This file contains a ' . $type . ' error: ' . $matches['error'] . ' on line ' . $matches['line']);
         $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
         // php -l only returns the first error
         return array($message);
     }
     return array();
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = phutil_split_lines($stderr, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         $match = preg_match('/^(?:(?<path>.+): )?' . 'line (?<line>\\d+), col (?<column>\\d+), ' . '(?<description>.*)$/', $line, $matches);
         if ($match) {
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($matches['line']);
             $message->setChar($matches['column']);
             $message->setCode($this->getLinterName());
             $message->setDescription(ucfirst($matches['description']));
             $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
             $messages[] = $message;
         }
     }
     return $messages;
 }
 public function lintPath($path)
 {
     $flake8_bin = $this->getFlake8Path();
     $options = $this->getFlake8Options();
     $f = new ExecFuture("%C %C -", $flake8_bin, $options);
     $f->write($this->getData($path));
     list($err, $stdout, $stderr) = $f->resolve();
     if ($err === 2) {
         throw new Exception("flake8 failed to run correctly:\n" . $stderr);
     }
     $lines = explode("\n", $stdout);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         // stdin:2: W802 undefined name 'foo'  # pyflakes
         // stdin:3:1: E302 expected 2 blank lines, found 1  # pep8
         if (!preg_match('/^(.*?):(\\d+):(?:(\\d+):)? (\\S+) (.*)$/', $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         if (substr($matches[4], 0, 1) == 'E') {
             $severity = ArcanistLintSeverity::SEVERITY_ERROR;
         } else {
             $severity = ArcanistLintSeverity::SEVERITY_WARNING;
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[2]);
         if (!empty($matches[3])) {
             $message->setChar($matches[3]);
         }
         $message->setCode($matches[4]);
         $message->setName($this->getLinterName() . ' ' . $matches[3]);
         $message->setDescription($matches[5]);
         $message->setSeverity($severity);
         $this->addLintMessage($message);
     }
 }
 public static function newFromDictionary(array $dict)
 {
     $message = new ArcanistLintMessage();
     $message->setPath($dict['path']);
     $message->setLine($dict['line']);
     $message->setChar($dict['char']);
     $message->setCode($dict['code']);
     $message->setSeverity($dict['severity']);
     $message->setName($dict['name']);
     $message->setDescription($dict['description']);
     if (isset($dict['original'])) {
         $message->setOriginalText($dict['original']);
     }
     if (isset($dict['replacement'])) {
         $message->setReplacementText($dict['replacement']);
     }
     $message->setGranularity(idx($dict, 'granularity'));
     $message->setOtherLocations(idx($dict, 'locations', array()));
     if (isset($dict['bypassChangedLineFiltering'])) {
         $message->bypassChangedLineFiltering($dict['bypassChangedLineFiltering']);
     }
     return $message;
 }
 public function lintPath($path)
 {
     list($rc, $stdout) = $this->results[$path];
     $report = Filesystem::readFile($this->reports[$path]);
     if ($report) {
         $report_dom = new DOMDocument();
         libxml_clear_errors();
         $report_dom->loadXML($report);
     }
     if (!$report || libxml_get_errors()) {
         throw new ArcanistUsageException('PHPCS Linter failed to load ' . 'reporting file. Something happened when running phpcs. ' . "Output:\n{$stdout}" . "\nTry running lint with --trace flag to get more details.");
     }
     $files = $report_dom->getElementsByTagName('file');
     foreach ($files as $file) {
         foreach ($file->childNodes as $child) {
             if (!$child instanceof DOMElement) {
                 continue;
             }
             $data = $this->getData($path);
             $lines = explode("\n", $data);
             $line = $lines[$child->getAttribute('line') - 1];
             $text = substr($line, $child->getAttribute('column') - 1);
             $name = $this->getLinterName() . ' - ' . $child->getAttribute('source');
             $severity = $child->tagName == 'error' ? ArcanistLintSeverity::SEVERITY_ERROR : ArcanistLintSeverity::SEVERITY_WARNING;
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($child->getAttribute('line'));
             $message->setChar($child->getAttribute('column'));
             $message->setCode($child->getAttribute('severity'));
             $message->setName($name);
             $message->setDescription($child->nodeValue);
             $message->setSeverity($severity);
             $message->setOriginalText($text);
             $this->addLintMessage($message);
         }
     }
 }
 public function lintPath($path)
 {
     $bin = $this->getLintPath();
     $options = $this->getLintOptions();
     list($rc, $stdout, $stderr) = exec_manual("%C %C --inline-suppr --xml-version=2 -q %s", $bin, $options, $this->getEngine()->getFilePathOnDisk($path));
     if ($rc === 1) {
         throw new Exception("cppcheck failed to run correctly:\n" . $stderr);
     }
     $dom = new DOMDocument();
     libxml_clear_errors();
     if ($dom->loadXML($stderr) === false || libxml_get_errors()) {
         throw new ArcanistUsageException('cppcheck Linter failed to load ' . 'output. Something happened when running cppcheck. ' . "Output:\n{$stderr}" . "\nTry running lint with --trace flag to get more details.");
     }
     $errors = $dom->getElementsByTagName('error');
     foreach ($errors as $error) {
         $loc_node = $error->getElementsByTagName('location');
         if (!$loc_node) {
             continue;
         }
         $location = $loc_node->item(0);
         if (!$location) {
             continue;
         }
         $file = $location->getAttribute('file');
         $line = $location->getAttribute('line');
         $id = $error->getAttribute('id');
         $severity = $error->getAttribute('severity');
         $msg = $error->getAttribute('msg');
         $inconclusive = $error->getAttribute('inconclusive');
         $verbose_msg = $error->getAttribute('verbose');
         $severity_code = ArcanistLintSeverity::SEVERITY_WARNING;
         if ($inconclusive) {
             $severity_code = ArcanistLintSeverity::SEVERITY_ADVICE;
         } else {
             if (stripos($severity, 'error') !== false) {
                 $severity_code = ArcanistLintSeverity::SEVERITY_ERROR;
             }
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($line);
         $message->setCode($severity);
         $message->setName($id);
         $message->setDescription($msg);
         $message->setSeverity($severity_code);
         $this->addLintMessage($message);
     }
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $lines = phutil_split_lines($stderr, false);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         $match = preg_match('/^(?P<name>\\w+): (?P<description>.+) ' . 'in (?P<path>.+|-) ' . 'on line (?P<line>\\d+), column (?P<column>\\d+):$/', $line, $matches);
         if ($match) {
             switch ($matches['name']) {
                 case 'RuntimeError':
                     $code = self::LINT_RUNTIME_ERROR;
                     break;
                 case 'ArgumentError':
                     $code = self::LINT_ARGUMENT_ERROR;
                     break;
                 case 'FileError':
                     $code = self::LINT_FILE_ERROR;
                     break;
                 case 'NameError':
                     $code = self::LINT_NAME_ERROR;
                     break;
                 case 'OperationError':
                     $code = self::LINT_OPERATION_ERROR;
                     break;
                 case 'ParseError':
                     $code = self::LINT_PARSE_ERROR;
                     break;
                 case 'SyntaxError':
                     $code = self::LINT_SYNTAX_ERROR;
                     break;
                 default:
                     throw new RuntimeException(pht('Unrecognized lint message code "%s".', $code));
             }
             $code = $this->getLintCodeFromLinterConfigurationKey($matches['name']);
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($matches['line']);
             $message->setChar($matches['column']);
             $message->setCode($this->getLintMessageFullCode($code));
             $message->setSeverity($this->getLintMessageSeverity($code));
             $message->setName($this->getLintMessageName($code));
             $message->setDescription(ucfirst($matches['description']));
             $messages[] = $message;
         }
     }
     if ($err && !$messages) {
         return false;
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $errors = null;
     try {
         $errors = phutil_json_decode($stdout);
     } catch (PhutilJSONParserException $ex) {
         // Something went wrong and we can't decode the output. Exit abnormally.
         throw new PhutilProxyException(pht('JSHint returned unparseable output.'), $ex);
     }
     $messages = array();
     foreach ($errors as $err) {
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine(idx($err, 'line'));
         $message->setChar(idx($err, 'col'));
         $message->setCode(idx($err, 'code'));
         $message->setName('JSHint' . idx($err, 'code'));
         $message->setDescription(idx($err, 'reason'));
         $message->setSeverity($this->getLintMessageSeverity(idx($err, 'code')));
         $messages[] = $message;
     }
     return $messages;
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $report_dom = new DOMDocument();
     $ok = @$report_dom->loadXML($stdout);
     if (!$ok) {
         return false;
     }
     $messages = array();
     foreach ($report_dom->getElementsByTagName('file') as $file) {
         foreach ($file->getElementsByTagName('error') as $error) {
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($error->getAttribute('line'));
             $message->setChar($error->getAttribute('column'));
             $message->setCode('JSCS');
             $message->setName('JSCS');
             $message->setDescription($error->getAttribute('message'));
             switch ($error->getAttribute('severity')) {
                 case 'error':
                     $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
                     break;
                 case 'warning':
                     $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
                     break;
                 default:
                     $message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
                     break;
             }
             $messages[] = $message;
         }
     }
     return $messages;
 }
 public function lintPath($path)
 {
     $pylint_bin = $this->getPyLintPath();
     $python_path = $this->getPyLintPythonPath();
     $options = $this->getPyLintOptions();
     $path_on_disk = $this->getEngine()->getFilePathOnDisk($path);
     try {
         list($stdout, $_) = execx('/usr/bin/env PYTHONPATH=%s$PYTHONPATH %s %C %s', $python_path, $pylint_bin, $options, $path_on_disk);
     } catch (CommandException $e) {
         if ($e->getError() == 32) {
             // According to ##man pylint## the exit status of 32 means there was a
             // usage error. That's bad, so actually exit abnormally.
             throw $e;
         } else {
             // The other non-zero exit codes mean there were messages issued,
             // which is expected, so don't exit.
             $stdout = $e->getStdout();
         }
     }
     $lines = explode("\n", $stdout);
     $messages = array();
     foreach ($lines as $line) {
         $matches = null;
         if (!preg_match('/([A-Z]\\d+): *(\\d+)(?:|,\\d*): *(.*)$/', $line, $matches)) {
             continue;
         }
         foreach ($matches as $key => $match) {
             $matches[$key] = trim($match);
         }
         $message = new ArcanistLintMessage();
         $message->setPath($path);
         $message->setLine($matches[2]);
         $message->setCode($matches[1]);
         $message->setName($this->getLinterName() . " " . $matches[1]);
         $message->setDescription($matches[3]);
         $message->setSeverity($this->getMessageCodeSeverity($matches[1]));
         $this->addLintMessage($message);
     }
 }
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     // NOTE: Some version of PHPCS after 1.4.6 stopped printing a valid, empty
     // XML document to stdout in the case of no errors. If PHPCS exits with
     // error 0, just ignore output.
     if (!$err) {
         return array();
     }
     $report_dom = new DOMDocument();
     $ok = @$report_dom->loadXML($stdout);
     if (!$ok) {
         return false;
     }
     $files = $report_dom->getElementsByTagName('file');
     $messages = array();
     foreach ($files as $file) {
         foreach ($file->childNodes as $child) {
             if (!$child instanceof DOMElement) {
                 continue;
             }
             if ($child->tagName == 'error') {
                 $prefix = 'E';
             } else {
                 $prefix = 'W';
             }
             $code = 'PHPCS.' . $prefix . '.' . $child->getAttribute('source');
             $message = new ArcanistLintMessage();
             $message->setPath($path);
             $message->setLine($child->getAttribute('line'));
             $message->setChar($child->getAttribute('column'));
             $message->setCode($code);
             $message->setDescription($child->nodeValue);
             $message->setSeverity($this->getLintMessageSeverity($code));
             $messages[] = $message;
         }
     }
     return $messages;
 }
 protected function resolveFuture(Future $future)
 {
     list($stdout) = $future->resolvex();
     $all_results = json_decode($stdout);
     foreach ($all_results as $results) {
         if ($results === null || $results->Issues === null) {
             return;
         }
         foreach ($results->Issues as $issue) {
             $message = new ArcanistLintMessage();
             $message->setPath($results->FileName);
             $message->setLine($issue->LineNumber);
             $message->setCode($issue->Index->Code);
             $message->setName($issue->Index->Name);
             $message->setChar($issue->Column);
             $message->setOriginalText($issue->OriginalText);
             $message->setReplacementText($issue->ReplacementText);
             $desc = @vsprintf($issue->Index->Message, $issue->Parameters);
             if ($desc === false) {
                 $desc = $issue->Index->Message;
             }
             $message->setDescription($desc);
             $severity = ArcanistLintSeverity::SEVERITY_ADVICE;
             switch ($issue->Index->Severity) {
                 case 0:
                     $severity = ArcanistLintSeverity::SEVERITY_ADVICE;
                     break;
                 case 1:
                     $severity = ArcanistLintSeverity::SEVERITY_AUTOFIX;
                     break;
                 case 2:
                     $severity = ArcanistLintSeverity::SEVERITY_WARNING;
                     break;
                 case 3:
                     $severity = ArcanistLintSeverity::SEVERITY_ERROR;
                     break;
                 case 4:
                     $severity = ArcanistLintSeverity::SEVERITY_DISABLED;
                     break;
             }
             $severity_override = $this->getLintMessageSeverity($issue->Index->Code);
             if ($severity_override !== null) {
                 $severity = $severity_override;
             }
             $message->setSeverity($severity);
             $this->addLintMessage($message);
         }
     }
 }
Exemple #30
0
 protected function parseLinterOutput($path, $err, $stdout, $stderr)
 {
     $json = json_decode($stdout, true);
     $files = idx($json, 'files');
     if (!is_array($files)) {
         // Something went wrong and we can't decode the output. Exit abnormally.
         throw new ArcanistUsageException("lint-trap returned unparseable output.\n" . "stdout:\n\n{$stdout}" . "stderr:\n\n{$stderr}");
     }
     $messages = array();
     foreach ($files as $f) {
         $errors = idx($f, 'errors');
         foreach ($errors as $err) {
             $message = new ArcanistLintMessage();
             $message->setPath(idx($f, 'file'));
             $message->setLine(idx($err, 'line'));
             $message->setChar(idx($err, 'column'));
             $message->setCode(idx($err, 'rule'));
             $message->setName(idx($err, 'linter') . '.' . idx($err, 'rule'));
             $message->setDescription(idx($err, 'message'));
             $message->setSeverity($this->getLintMessageSeverity(idx($err, 'type')));
             $messages[] = $message;
         }
     }
     return $messages;
 }