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) { $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->setName($this->getLinterName()); $message->setDescription($description); $message->setSeverity($severity); $messages[] = $message; } return $messages; }
protected function parseLinterOutput($output) { $json = json_decode($output, true); $files = $json['files']; $severityMap = array(); $severityMap['refactor'] = 'warning'; $severityMap['convention'] = 'warning'; $severityMap['warning'] = 'warning'; $severityMap['error'] = 'error'; $severityMap['fatal'] = 'error'; $messages = array(); foreach ($files as $file) { foreach ($file['offenses'] as $offense) { $message = new ArcanistLintMessage(); $message->setPath($file['path']); $message->setLine($offense['location']['line']); $message->setChar($offense['location']['column']); $message->setCode('RUBY'); $message->setName($offense['cop_name']); $message->setDescription($offense['message']); $message->setseverity('error'); $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) { $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); } }
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) { $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) { $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) { $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; }
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; }
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) { $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; }
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) { $xml_result = new SimpleXMLElement($stdout); $messages = array(); foreach ($xml_result->file->issue as $issue) { $message = new ArcanistLintMessage(); $message->setPath($path); $message->setLine($this->intValOrNull($issue['line'])); $message->setChar($this->intValOrNull($issue['char'])); $message->setName($issue['reason']); $message->setDescription("Evidence: " . $issue['evidence']); $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); $message->setCode(ArcanistLintSeverity::SEVERITY_ERROR); $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->setName($this->getLinterName()); $message->setDescription(ucfirst(trim($matches[2]))); $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); $messages[] = $message; } } return $messages; }
public function lintPath($path) { list($err, $_, $stderr) = exec_manual("gofmt -w -s %s", $this->getEngine()->getFilePathOnDisk($path)); if ($err) { $lines = explode("\n", $stderr); foreach ($lines as $line) { $matches = null; if (!preg_match('/[^:]+:(\\d+):(\\d+): (.*)$/', $line, $matches)) { continue; } $message = new ArcanistLintMessage(); $message->setPath($path); $message->setLine($matches[1]); $message->setChar($matches[2]); $message->setName($this->getLinterName() . " Parse error"); $message->setDescription($matches[3]); $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('/^(?:(?<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->setName($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); } }
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 .= ' **NOTE**: ' . trim($note, '"') . '.'; } $message->setDescription(pht('In module `%s`, declaration `%s`.%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']); } $message->setGranularity(idx($dict, 'granularity')); $message->setOtherLocations(idx($dict, 'locations', array())); if (isset($dict['bypassChangedLineFiltering'])) { $message->bypassChangedLineFiltering($dict['bypassChangedLineFiltering']); } return $message; }
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); } } }
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; }
public function lintPath($path) { $pep8_bin = $this->getPEP8Path(); $options = $this->getPEP8Options(); list($rc, $stdout) = exec_manual("%C %C %s", $pep8_bin, $options, $this->getEngine()->getFilePathOnDisk($path)); $lines = explode("\n", $stdout); $messages = array(); foreach ($lines as $line) { $matches = null; if (!preg_match('/^(.*?):(\\d+):(\\d+): (\\S+) (.*)$/', $line, $matches)) { continue; } foreach ($matches as $key => $match) { $matches[$key] = trim($match); } $message = new ArcanistLintMessage(); $message->setPath($path); $message->setLine($matches[2]); $message->setChar($matches[3]); $message->setCode($matches[4]); $message->setName('PEP8 ' . $matches[4]); $message->setDescription($matches[5]); if (!$this->isMessageEnabled($matches[4])) { continue; } if ($matches[4][0] == 'E') { $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); } else { $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); } $this->addLintMessage($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); } } }
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) { $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; }
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) { $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; }