Skip to content

Commit

Permalink
Update diff parsing for isort 5.5+ (#49)
Browse files Browse the repository at this point in the history
PyCQA/isort#1429 fixed --check's output so
that the error message and diff output are separated into STDERR and
STDOUT rather than combined in STDOUT. This means we need to update our
diff parsing function accordingly.

Also fix the version parsing routine to read from STDOUT. This was
busted for at least a few versions.
  • Loading branch information
jparise authored Sep 3, 2020
1 parent 1b9e2f8 commit 4963ba2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/PythonIsortLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getVersion() {
$this->getExecutableCommand());

$matches = array();
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stderr, $matches)) {
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
$this->version = $matches['version'];
return $this->version;
} else {
Expand Down Expand Up @@ -89,13 +89,17 @@ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
return array();
}

// Expected output includes a single header optionally followed by a
// multiline diff. We're only interested in the latter case (which implies
// a lint violation), but we could also parse the header for more detailed
// information if we need that later.
list($header, $diff) = explode("\n", $stdout, 2);
if (empty($diff)) {
if (version_compare($this->version, '5.5.0', '>=')) {
$diff = $stdout;
} else {
// Expected output includes a single header optionally followed by a
// multiline diff. We're only interested in the latter case (which implies
// a lint violation), but we could also parse the header for more detailed
// information if we need that later.
list($header, $diff) = explode("\n", $stdout, 2);
if (empty($diff)) {
return array();
}
}

$messages = array();
Expand Down

0 comments on commit 4963ba2

Please sign in to comment.