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

Add a getVersion function to ArcanistExternalLinter.

Summary:
This method will, theoretically, allow `arc lint` to be configured to require some minimum version of an external linter (although this would probably require significantly more work).

Additionally, the existence of this method simplifies the `getCacheVersion` function which, previously, was implemented by the external linters individually. Instead, a general approach to determining the version for cacheing purposes can be used.

Fixes T4954.

Test Plan: I'm not sure how to test this.

Reviewers: chad, epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T4954

Differential Revision: https://secure.phabricator.com/D8971
This commit is contained in:
Joshua Spence 2014-05-05 15:10:20 -07:00 committed by epriestley
parent a7327ca0e9
commit f2b341ae03
7 changed files with 77 additions and 12 deletions

View file

@ -34,6 +34,17 @@ final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
return $config->getConfigFromAnySource('lint.csslint.bin', 'csslint');
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
if (preg_match('/^v(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install CSSLint using `npm install -g csslint`.');
}

View file

@ -369,6 +369,21 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
return array_merge($mandatory_flags, $flags);
}
public function getCacheVersion() {
$version = $this->getVersion();
if ($version) {
return $version.'-'.json_encode($this->getCommandFlags());
} else {
// Either we failed to parse the version number or the `getVersion`
// function hasn't been implemented.
return json_encode($this->getCommandFlags());
}
}
public function getVersion() {
return null;
}
protected function buildFutures(array $paths) {
$executable = $this->getExecutableCommand();

View file

@ -34,6 +34,17 @@ final class ArcanistFlake8Linter extends ArcanistExternalLinter {
return 'flake8';
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)\b/', $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install flake8 using `easy_install flake8`.');
}

View file

@ -35,18 +35,16 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
}
}
public function getCacheVersion() {
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
// Extract version number from standard output.
$matches = array();
if (preg_match('/^jshint v(\d+\.\d+\.\d+)$/', $stdout, $matches)) {
$version = $matches[1];
$regex = '/^jshint v(?P<version>\d+\.\d+\.\d+)$/';
if (preg_match($regex, $stdout, $matches)) {
return $matches['version'];
} else {
$version = md5($stdout);
return false;
}
return $version . '-' . md5(json_encode($this->getCommandFlags()));
}
public function getInstallInstructions() {

View file

@ -15,11 +15,6 @@ final class ArcanistPEP8Linter extends ArcanistExternalLinter {
return 'pep8';
}
public function getCacheVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
return $stdout.implode(' ', $this->getCommandFlags());
}
public function getDefaultFlags() {
// TODO: Warn that all of this is deprecated.
$config = $this->getEngine()->getConfigurationManager();
@ -55,6 +50,17 @@ final class ArcanistPEP8Linter extends ArcanistExternalLinter {
return $arc_root.'/externals/pep8/pep8.py';
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install PEP8 using `easy_install pep8`.');
}

View file

@ -58,6 +58,18 @@ final class ArcanistPhpcsLinter extends ArcanistExternalLinter {
return $config->getConfigFromAnySource('lint.phpcs.bin', 'phpcs');
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
$regex = '/^PHP_CodeSniffer version (?P<version>\d+\.\d+\.\d+)\b/';
if (preg_match($regex, $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function shouldExpectCommandErrors() {
return true;
}

View file

@ -26,6 +26,18 @@ final class ArcanistRubyLinter extends ArcanistExternalLinter {
return 'ruby';
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
$regex = '/^ruby (?P<version>\d+\.\d+\.\d+)p\d+/';
if (preg_match($regex, $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install `ruby` from <http://www.ruby-lang.org/>.');
}