From 85000be96f7f5c530cb9d376a6823137f0d0a787 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 10 Apr 2014 09:07:42 -0400 Subject: [PATCH] Updating the pylint linter to set the output fomat correctly depending on the version of pylint installed See: Reviewed by: epriestley --- src/lint/linter/ArcanistPyLintLinter.php | 35 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/lint/linter/ArcanistPyLintLinter.php b/src/lint/linter/ArcanistPyLintLinter.php index c0fc82e3..aeb3f7fc 100644 --- a/src/lint/linter/ArcanistPyLintLinter.php +++ b/src/lint/linter/ArcanistPyLintLinter.php @@ -161,8 +161,16 @@ final class ArcanistPyLintLinter extends ArcanistLinter { private function getPyLintOptions() { // '-rn': don't print lint report/summary at end - // '-iy': show message codes for lint warnings/errors - $options = array('-rn', '-iy'); + $options = array('-rn'); + + // Version 0.x.x include the pylint message ids in the output + if (version_compare($this->getLinterVersion(), "1", 'lt')) { + array_push($options, '-iy', "--output-format=text"); + } + // Version 1.x.x set the output specifically to the 0.x.x format + else { + array_push($options, "--msg-template='{msg_id}:{line:3d}: {obj}: {msg}'"); + } $working_copy = $this->getEngine()->getWorkingCopy(); $config = $this->getEngine()->getConfigurationManager(); @@ -191,6 +199,29 @@ final class ArcanistPyLintLinter extends ArcanistLinter { return 'PyLint'; } + private function getLinterVersion() { + + $pylint_bin = $this->getPyLintPath(); + $options = '--version'; + + list($stdout) = execx( + '%s %s', + $pylint_bin, + $options); + + $lines = explode("\n", $stdout); + $matches = null; + + // If the version command didn't return anything or the regex didn't match + // Assume a future version that at least is compatible with 1.x.x + if (count($lines) == 0 || + !preg_match('/pylint\s((?:\d+\.?)+)/', $lines[0], $matches)) { + return "999"; + } + + return $matches[1]; + } + public function lintPath($path) { $pylint_bin = $this->getPyLintPath(); $python_path = $this->getPyLintPythonPath();