]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Updating the pylint linter to set the output fomat correctly depending on the version...
authorAndrew Jones <andrew@hioscar.com>
Thu, 10 Apr 2014 13:07:42 +0000 (09:07 -0400)
committerepriestley <git@epriestley.com>
Tue, 6 May 2014 02:05:16 +0000 (19:05 -0700)
See: <https://github.com/facebook/arcanist/pull/161>

Reviewed by: epriestley

src/lint/linter/ArcanistPyLintLinter.php

index c0fc82e329d893f647fdde1a6868b498bf7511af..aeb3f7fc1b6c66037ecedae768d860714250d99d 100644 (file)
@@ -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();