Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistPyFlakesLinter.php
Show All 29 Lines | final class ArcanistPyFlakesLinter extends ArcanistExternalLinter { | ||||
public function getDefaultBinary() { | public function getDefaultBinary() { | ||||
return 'pyflakes'; | return 'pyflakes'; | ||||
} | } | ||||
public function getVersion() { | public function getVersion() { | ||||
list($stdout) = execx('%C --version', $this->getExecutableCommand()); | list($stdout) = execx('%C --version', $this->getExecutableCommand()); | ||||
$matches = array(); | $matches = array(); | ||||
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) { | $pattern = '/^(?P<version>\d+\.\d+\.\d+)( Python.*)?$/'; | ||||
if (preg_match($pattern, $stdout, $matches)) { | |||||
epriestley: Ideally, keep this under 80 characters (e.g., by putting `$pattern = ...` on a separate line). | |||||
return $matches['version']; | return $matches['version']; | ||||
} else { | } else { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
public function getInstallInstructions() { | public function getInstallInstructions() { | ||||
return pht('Install pyflakes with `%s`.', 'pip install pyflakes'); | return pht('Install pyflakes with `%s`.', 'pip install pyflakes'); | ||||
} | } | ||||
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); | ||||
$messages = array(); | $messages = array(); | ||||
foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
$matches = null; | $matches = null; | ||||
if (!preg_match('/^(.*?):(\d+): (.*)$/', $line, $matches)) { | $pattern = '/^(?<path>.*?):(?<line>\d+):(?<column>\d*) (?<message>.*)$/'; | ||||
if (!preg_match($pattern, $line, $matches)) { | |||||
continue; | continue; | ||||
} | } | ||||
foreach ($matches as $key => $match) { | foreach ($matches as $key => $match) { | ||||
$matches[$key] = trim($match); | $matches[$key] = trim($match); | ||||
} | } | ||||
$severity = ArcanistLintSeverity::SEVERITY_WARNING; | $severity = ArcanistLintSeverity::SEVERITY_WARNING; | ||||
$description = $matches[3]; | $description = $matches['message']; | ||||
$error_regexp = '/(^undefined|^duplicate|before assignment$)/'; | $error_regexp = '/(^undefined|^duplicate|before assignment$)/'; | ||||
if (preg_match($error_regexp, $description)) { | if (preg_match($error_regexp, $description)) { | ||||
$severity = ArcanistLintSeverity::SEVERITY_ERROR; | $severity = ArcanistLintSeverity::SEVERITY_ERROR; | ||||
} | } | ||||
$message = new ArcanistLintMessage(); | $message = new ArcanistLintMessage(); | ||||
$message->setPath($path); | $message->setPath($path); | ||||
$message->setLine($matches[2]); | $message->setLine($matches['line']); | ||||
if ($matches['column'] != '') { | |||||
$message->setChar($matches['column']); | |||||
} | |||||
$message->setCode($this->getLinterName()); | $message->setCode($this->getLinterName()); | ||||
$message->setName($this->getLinterName()); | $message->setName($this->getLinterName()); | ||||
$message->setDescription($description); | $message->setDescription($description); | ||||
$message->setSeverity($severity); | $message->setSeverity($severity); | ||||
$messages[] = $message; | $messages[] = $message; | ||||
} | } | ||||
return $messages; | return $messages; | ||||
} | } | ||||
protected function canCustomizeLintSeverities() { | protected function canCustomizeLintSeverities() { | ||||
return false; | return false; | ||||
} | } | ||||
} | } |
Ideally, keep this under 80 characters (e.g., by putting $pattern = ... on a separate line).