1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-23 05:50:54 +01:00

Updating the pylint linter to set the output fomat correctly depending on the version of pylint installed

See: <https://github.com/facebook/arcanist/pull/161>

Reviewed by: epriestley
This commit is contained in:
Andrew Jones 2014-04-10 09:07:42 -04:00 committed by epriestley
parent b4e91e1a37
commit 85000be96f

View 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();