diff --git a/src/lint/linter/ArcanistFlake8Linter.php b/src/lint/linter/ArcanistFlake8Linter.php index 19d57432..37fb45e1 100644 --- a/src/lint/linter/ArcanistFlake8Linter.php +++ b/src/lint/linter/ArcanistFlake8Linter.php @@ -1,115 +1,117 @@ getExecutableCommand()); $matches = array(); if (preg_match('/^(?P\d+\.\d+(?:\.\d+)?)\b/', $stdout, $matches)) { return $matches['version']; } else { return false; } } public function getInstallInstructions() { return pht('Install flake8 using `%s`.', 'pip install flake8'); } protected function parseLinterOutput($path, $err, $stdout, $stderr) { $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\d+):(?:(?P\d+):)? (?P\S+) (?P.*)$/'; + $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->setLine($matches['line']); + if (!empty($matches['char'])) { + $message->setChar($matches['char']); } - $message->setCode($matches[4]); - $message->setName($this->getLinterName().' '.$matches[3]); - $message->setDescription($matches[5]); - $message->setSeverity($this->getLintMessageSeverity($matches[4])); + $message->setCode($matches['code']); + $message->setName($this->getLinterName().' '.$matches['code']); + $message->setDescription($matches['msg']); + $message->setSeverity($this->getLintMessageSeverity($matches['code'])); $messages[] = $message; } return $messages; } protected function getDefaultMessageSeverity($code) { if (preg_match('/^C/', $code)) { // "C": Cyclomatic complexity return ArcanistLintSeverity::SEVERITY_ADVICE; } else if (preg_match('/^W/', $code)) { // "W": PEP8 Warning return ArcanistLintSeverity::SEVERITY_WARNING; } else { // "E": PEP8 Error // "F": PyFlakes Error // or: Flake8 Extension Message return ArcanistLintSeverity::SEVERITY_ERROR; } } protected function getLintCodeFromLinterConfigurationKey($code) { if (!preg_match('/^[A-Z]\d+$/', $code)) { throw new Exception( pht( 'Unrecognized lint message code "%s". Expected a valid flake8 '. 'lint code like "%s", or "%s", or "%s", or "%s".', $code, 'E225', 'W291', 'F811', 'C901')); } return $code; } }