Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistPhpcsLinter.php
| Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | protected function parseLinterOutput($path, $err, $stdout, $stderr) { | ||||
| $files = $report_dom->getElementsByTagName('file'); | $files = $report_dom->getElementsByTagName('file'); | ||||
| $messages = array(); | $messages = array(); | ||||
| foreach ($files as $file) { | foreach ($files as $file) { | ||||
| foreach ($file->childNodes as $child) { | foreach ($file->childNodes as $child) { | ||||
| if (!($child instanceof DOMElement)) { | if (!($child instanceof DOMElement)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ($child->tagName == 'error') { | $message = id(new ArcanistLintMessage()) | ||||
| $prefix = 'E'; | ->setPath($path) | ||||
| } else { | ->setLine($child->getAttribute('line')) | ||||
| $prefix = 'W'; | ->setChar($child->getAttribute('column')) | ||||
| ->setCode($child->getAttribute('source')) | |||||
| ->setDescription($child->nodeValue); | |||||
| switch ($child->tagName) { | |||||
| case 'error': | |||||
| $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR); | |||||
| break; | |||||
| } | } | ||||
| $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; | $messages[] = $message; | ||||
| } | } | ||||
| } | } | ||||
| return $messages; | return $messages; | ||||
| } | } | ||||
| protected function getDefaultMessageSeverity($code) { | protected function getDefaultMessageSeverity($code) { | ||||
| if (preg_match('/^PHPCS\\.W\\./', $code)) { | |||||
| return ArcanistLintSeverity::SEVERITY_WARNING; | return ArcanistLintSeverity::SEVERITY_WARNING; | ||||
| } else { | |||||
| return ArcanistLintSeverity::SEVERITY_ERROR; | |||||
| } | |||||
| } | } | ||||
| protected function getLintCodeFromLinterConfigurationKey($code) { | protected function getLintCodeFromLinterConfigurationKey($code) { | ||||
| if (!preg_match('/^PHPCS\\.(E|W)\\./', $code)) { | if (!preg_match('/^PHPCS\\.(E|W)\\./', $code)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| "Invalid severity code '%s', should begin with '%s.'.", | "Invalid severity code '%s', should begin with '%s.'.", | ||||
| $code, | $code, | ||||
| 'PHPCS')); | 'PHPCS')); | ||||
| } | } | ||||
| return $code; | return $code; | ||||
| } | } | ||||
| } | } | ||||