1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 00:42:40 +01:00

Fix pyflakes tests for recent pyflakes versions

Summary:
Since 2.1.0 (commit 75bc0c03c145), pyflakes has included the Python
version and platform in its version output, so ignore it if present.

Since 2.2.0 (commit 6ba3f8e0b59b), pyflakes has included the column
number in its messages, so update the parser to include it and drop the
column number from the (only) test in order to work with both old and
new versions. Whilst here, assign names to the capture groups to make
the code clearer.

Test Plan: Ran arc unit

Reviewers: epriestley, joshuaspence, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D21504
This commit is contained in:
Jessica Clarke 2021-01-11 04:52:29 +00:00 committed by jrtc27
parent 09cff8611b
commit 172381260e
2 changed files with 12 additions and 7 deletions

View file

@ -35,7 +35,8 @@ final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
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)) {
return $matches['version']; return $matches['version'];
} else { } else {
return false; return false;
@ -52,7 +53,8 @@ final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
$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) {
@ -60,7 +62,7 @@ final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
} }
$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)) {
@ -69,7 +71,10 @@ final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
$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);

View file

@ -2,6 +2,6 @@ import sys, os
x += 1 x += 1
~~~~~~~~~~ ~~~~~~~~~~
warning:1:0 warning:1:
warning:1:0 warning:1:
error:3:0 error:3: