Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistFlake8Linter.php
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | final class ArcanistFlake8Linter extends ArcanistExternalLinter { | ||||
public function getInstallInstructions() { | public function getInstallInstructions() { | ||||
return pht('Install flake8 using `%s`.', 'pip install flake8'); | return pht('Install flake8 using `%s`.', 'pip install flake8'); | ||||
} | } | ||||
protected function parseLinterOutput($path, $err, $stdout, $stderr) { | protected function parseLinterOutput($path, $err, $stdout, $stderr) { | ||||
$lines = phutil_split_lines($stdout, false); | $lines = phutil_split_lines($stdout, false); | ||||
// stdin:2: W802 undefined name 'foo' # pyflakes | |||||
// stdin:3:1: E302 expected 2 blank lines, found 1 # pep8 | |||||
$regexp = | |||||
'/^(?:.*?):(?P<line>\d+):(?:(?P<char>\d+):)? (?P<code>\S+) (?P<msg>.*)$/'; | |||||
$messages = array(); | $messages = array(); | ||||
foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
$matches = null; | $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)) { | if (!preg_match($regexp, $line, $matches)) { | ||||
continue; | continue; | ||||
} | } | ||||
foreach ($matches as $key => $match) { | foreach ($matches as $key => $match) { | ||||
$matches[$key] = trim($match); | $matches[$key] = trim($match); | ||||
} | } | ||||
$message = new ArcanistLintMessage(); | $message = new ArcanistLintMessage(); | ||||
$message->setPath($path); | $message->setPath($path); | ||||
$message->setLine($matches[2]); | $message->setLine($matches['line']); | ||||
if (!empty($matches[3])) { | if (!empty($matches['char'])) { | ||||
$message->setChar($matches[3]); | $message->setChar($matches['char']); | ||||
} | } | ||||
$message->setCode($matches[4]); | $message->setCode($matches['code']); | ||||
$message->setName($this->getLinterName().' '.$matches[3]); | $message->setName($this->getLinterName().' '.$matches['code']); | ||||
$message->setDescription($matches[5]); | $message->setDescription($matches['msg']); | ||||
$message->setSeverity($this->getLintMessageSeverity($matches[4])); | $message->setSeverity($this->getLintMessageSeverity($matches['code'])); | ||||
$messages[] = $message; | $messages[] = $message; | ||||
} | } | ||||
return $messages; | return $messages; | ||||
} | } | ||||
protected function getDefaultMessageSeverity($code) { | protected function getDefaultMessageSeverity($code) { | ||||
Show All 31 Lines |