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+):(\\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]); $message->setSeverity($this->getLintMessageSeverity($matches[4])); $messages[] = $message; } if ($err && !$messages) { return false; } return $messages; }
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 addLintMessage(ArcanistLintMessage $msg) { $original = $msg->getOriginalText(); if (!preg_match("/{$this->holder}/", $original)) { foreach ($this->valid_holders as $holder) { if (preg_match("/{$holder}/", $original)) { // Suppress this one return; } } } parent::addLintMessage($msg); }
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($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; }
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($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; }
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); } }
public function willLintPaths(array $paths) { $program = false; $ret_value = 0; $last_line = system("which checkCpp", $ret_value); if ($ret_value == 0) { $program = $last_line; } else { if (file_exists(self::PROGRAM)) { $program = self::PROGRAM; } } if ($program) { $futures = array(); foreach ($paths as $p) { $futures[$p] = new ExecFuture("%s --lint %s 2>&1", $program, $this->getEngine()->getFilePathOnDisk($p)); } foreach (Futures($futures)->limit(8) as $p => $f) { list($stdout, $stderr) = $f->resolvex(); $raw = json_decode($stdout, true); if (!is_array($raw)) { throw new Exception("checkCpp returned invalid JSON!" . "Stdout: {$stdout} Stderr: {$stderr}"); } foreach ($raw as $err) { $this->addLintMessage(ArcanistLintMessage::newFromDictionary(array('path' => $err['file'], 'line' => $err['line'], 'char' => 0, 'name' => $err['name'], 'description' => $err['info'], 'code' => $this->getLinterName(), 'severity' => ArcanistLintSeverity::SEVERITY_WARNING))); } } } return; }
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; }
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); } }
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($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) { $lint_for_path = idx($this->lintByPath, $path); if (!$lint_for_path) { return; } foreach ($lint_for_path as $lint) { $this->addLintMessage(ArcanistLintMessage::newFromDictionary($lint)); } }
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 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) { $lines = phutil_split_lines($stdout, false); $messages = array(); foreach ($lines as $line) { $matches = explode(':', $line, 4); if (count($matches) === 4) { $message = new ArcanistLintMessage(); $message->setPath($path); $message->setLine($matches[1]); $message->setChar($matches[2]); $message->setCode($this->getLinterName()); $message->setName($this->getLinterName()); $message->setDescription(ucfirst(trim($matches[3]))); $message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE); $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; $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) { 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) { $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; }
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; 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; } 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); } } }
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) { 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 final function addLintMessage(ArcanistLintMessage $message) { $root = $this->getProjectRoot(); $path = Filesystem::resolvePath($message->getPath(), $root); $message->setPath(Filesystem::readablePath($path, $root)); $this->messages[] = $message; return $message; }